process-warning
Advanced tools
Comparing version 2.3.0 to 2.3.1
44
index.js
@@ -46,5 +46,29 @@ 'use strict' | ||
const emitted = new Map() | ||
const opts = Object.create(null) | ||
/** | ||
* @typedef {number} STATE_CONSTANT | ||
*/ | ||
/** | ||
* @private | ||
* @typdef {object} EMISSION_STATES | ||
* @property {STATE_CONSTANT} UNLIMITED_INITIAL Indicates that the warning | ||
* is to be issued an unlimited number of times but has not yet been | ||
* emitted. | ||
* @property {STATE_CONSTANT} UNLIMITED_ONGOING Indicates that the warning | ||
* is to be issued an unlimited number of times and has been emitted at least | ||
* once. | ||
* @property {STATE_CONSTANT} LIMITED_INITIAL Indicates that the warning | ||
* is to be issued only once but has not yet been emitted. | ||
* @property {STATE_CONSTANT} LIMITED_FINAL Indicates that the warning | ||
* is to be issued only once and has already been emitted. | ||
*/ | ||
const STATES = { | ||
UNLIMITED_INITIAL: 0, | ||
UNLIMITED_ONGOING: -1, | ||
LIMITED_INITIAL: 1, | ||
LIMITED_FINAL: 2 | ||
} | ||
/** | ||
* Builds a new {@link ProcessWarning} and adds it to the | ||
@@ -95,4 +119,3 @@ * {@link ProcessWarningManager} such that it can be emitted through the | ||
Object.assign(opts, { unlimited }) | ||
emitted.set(code, unlimited) | ||
emitted.set(code, unlimited ? STATES.UNLIMITED_INITIAL : STATES.LIMITED_INITIAL) | ||
codes[code] = buildWarnOpts | ||
@@ -142,5 +165,9 @@ | ||
function emit (code, a, b, c) { | ||
if (emitted.get(code) === true && opts.unlimited === false) return | ||
const state = emitted.get(code) | ||
if (state === STATES.LIMITED_FINAL) return | ||
if (codes[code] === undefined) throw new Error(`The code '${code}' does not exist`) | ||
emitted.set(code, true) | ||
emitted.set( | ||
code, | ||
state <= STATES.UNLIMITED_INITIAL ? STATES.UNLIMITED_ONGOING : STATES.LIMITED_FINAL | ||
) | ||
@@ -155,3 +182,8 @@ const warning = codes[code](a, b, c) | ||
emit, | ||
emitted | ||
emitted: { | ||
get (code) { | ||
const state = emitted.get(code) | ||
return state === STATES.UNLIMITED_ONGOING || state === STATES.LIMITED_FINAL | ||
} | ||
} | ||
} | ||
@@ -158,0 +190,0 @@ } |
{ | ||
"name": "process-warning", | ||
"version": "2.3.0", | ||
"version": "2.3.1", | ||
"description": "A small utility for creating warnings and emitting them.", | ||
@@ -11,2 +11,3 @@ "main": "index.js", | ||
"lint:fix": "standard --fix", | ||
"benchmark": "node benchmarks/warn.js", | ||
"test": "npm run test:unit && npm run test:jest && npm run test:typescript", | ||
@@ -13,0 +14,0 @@ "test:jest": "jest jest.test.js", |
'use strict' | ||
const test = require('tap').test | ||
const { test } = require('tap') | ||
const build = require('..') | ||
@@ -5,0 +5,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22599
19
473
2