Process Warning Utility

5.0.0 · active · verified Sun Apr 19

process-warning is a lightweight utility designed to standardize the creation and emission of warnings within JavaScript and TypeScript applications, particularly for the Fastify ecosystem. It ensures that warnings, including deprecation warnings, are consistently formatted and, by default, emitted only once to prevent log spam. The current stable version is 5.0.0. The package maintains a regular release cadence, often aligning with Node.js version updates and Fastify development, with minor releases for bug fixes and dependency bumps and occasional major releases for refactoring or dropping older Node.js support. Its key differentiators include built-in one-time emission, support for Node.js's native deprecation warning CLI options, and a clear API for defining warning codes and messages.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates creating and emitting both standard and deprecation warnings, including the 'unlimited' option.

import { createWarning, createDeprecation } from 'process-warning';

const MyModuleWarning = createWarning({
  name: 'MyModuleWarning',
  code: 'MYMOD_001',
  message: 'This is a warning for value: %s'
});

const MyModuleDeprecation = createDeprecation({
  code: 'MYMOD_DEP_002',
  message: 'The %s method is deprecated, use %s instead.'
});

console.log('Emitting first warning...');
MyModuleWarning('someValue'); // Emits the warning

console.log('Attempting to emit same warning again...');
MyModuleWarning('anotherValue'); // Will not emit by default (unlimited: false)

console.log('Emitting deprecation warning...');
MyModuleDeprecation('oldMethod', 'newMethod'); // Emits a deprecation warning

const UnlimitedWarning = createWarning({
  name: 'UnlimitedWarning',
  code: 'UNL_003',
  message: 'This warning will always emit for %s',
  unlimited: true
});

console.log('Emitting unlimited warning...');
UnlimitedWarning('first call'); // Emits
UnlimitedWarning('second call'); // Emits again

view raw JSON →