Gathering detailed insights and metrics for process-warning
Gathering detailed insights and metrics for process-warning
Gathering detailed insights and metrics for process-warning
Gathering detailed insights and metrics for process-warning
A small utility for creating warnings and emitting them.
npm install process-warning
Typescript
Module System
Node Version
NPM Version
99.8
Supply Chain
100
Quality
83.7
Maintenance
100
Vulnerability
100
License
JavaScript (93.46%)
TypeScript (6.54%)
Total Downloads
681,872,681
Last Day
1,184,094
Last Week
9,107,422
Last Month
40,280,601
Last Year
370,724,862
37 Stars
132 Commits
9 Forks
14 Watching
4 Branches
25 Contributors
Minified
Minified + Gzipped
Latest Version
4.0.0
Package Id
process-warning@4.0.0
Unpacked Size
21.56 kB
Size
6.16 kB
File Count
21
NPM Version
10.7.0
Node Version
20.15.0
Publised On
09 Jul 2024
Cumulative downloads
Total Downloads
Last day
-33.3%
1,184,094
Compared to previous day
Last week
-7.8%
9,107,422
Compared to previous week
Last month
6.1%
40,280,601
Compared to previous month
Last year
79.4%
370,724,862
Compared to previous year
A small utility for generating consistent warning objects across your codebase. It also exposes a utility for emitting those warnings, guaranteeing that they are issued only once (unless configured otherwise).
This module is used by the Fastify framework and it was called fastify-warning
prior to version 1.0.0.
npm i process-warning
The module exports two builder functions for creating warnings.
1const { 2 createWarning, 3 createDeprecation 4} = require('process-warning') 5 6const warning = createWarning({ 7 name: 'ExampleWarning', 8 code: 'EXP_WRN_001', 9 message: 'Hello %s', 10 unlimited: true 11}) 12warning('world')
createWarning({ name, code, message[, unlimited] })
name
(string
, required) - The error name, you can access it later with
error.name
. For consistency, we recommend prefixing module error names
with {YourModule}Warning
code
(string
, required) - The warning code, you can access it later with
error.code
. For consistency, we recommend prefixing plugin error codes with
{ThreeLetterModuleName}_
, e.g. FST_
. NOTE: codes should be all uppercase.message
(string
, required) - The warning message. You can also use
interpolated strings for formatting the message.options
(object
, optional) - Optional options with the following
properties:
unlimited
(boolean
, optional) - Should the warning be emitted more than
once? Defaults to false
.createDeprecation({code, message[, options]})
This is a wrapper for createWarning
. It is equivalent to invoking
createWarning
with the name
parameter set to "DeprecationWarning".
Deprecation warnings have extended support for the Node.js CLI options:
--throw-deprecation
, --no-deprecation
, and --trace-deprecation
.
warning([, a [, b [, c]]])
The returned warning
function can used for emitting warnings.
A warning is guaranteed to be emitted at least once.
[, a [, b [, c]]]
(any
, optional) - Parameters for string interpolation.1const { createWarning } = require('process-warning') 2const FST_ERROR_CODE = createWarning({ name: 'MyAppWarning', code: 'FST_ERROR_CODE', message: 'message' }) 3FST_ERROR_CODE()
How to use an interpolated string:
1const { createWarning } = require('process-warning') 2const FST_ERROR_CODE = createWarning({ name: 'MyAppWarning', code: 'FST_ERROR_CODE', message: 'Hello %s'}) 3FST_ERROR_CODE('world')
The warning
object has methods and properties for managing the warning's state. Useful for testing.
1const { createWarning } = require('process-warning') 2const FST_ERROR_CODE = createWarning({ name: 'MyAppWarning', code: 'FST_ERROR_CODE', message: 'Hello %s'}) 3console.log(FST_ERROR_CODE.emitted) // false 4FST_ERROR_CODE('world') 5console.log(FST_ERROR_CODE.emitted) // true 6 7const FST_ERROR_CODE_2 = createWarning('MyAppWarning', 'FST_ERROR_CODE_2', 'Hello %s') 8FST_ERROR_CODE_2.emitted = true 9FST_ERROR_CODE_2('world') // will not be emitted because it is not unlimited
How to use an unlimited warning:
1const { createWarning } = require('process-warning') 2const FST_ERROR_CODE = createWarning({ name: 'MyAppWarning', code: 'FST_ERROR_CODE', message: 'Hello %s', unlimited: true }) 3FST_ERROR_CODE('world') // will be emitted 4FST_ERROR_CODE('world') // will be emitted again
It is possible to suppress warnings by utilizing one of node's built-in warning suppression mechanisms.
Warnings can be suppressed:
NODE_NO_WARNINGS
environment variable to 1
--no-warnings
flag to the node processNODE_OPTIONS
environment variableFor more information see node's documentation.
Licensed under MIT.
No vulnerabilities found.
No security vulnerabilities found.