{"_id":"process-warning@5.1.1","bugs":{"url":"https://github.com/fastify/fastify-warning/issues"},"dist":{"shasum":"9c7f34dd637100966be7d32661831ea328ea776b","tarball":"http://registry-npm.ywwl.com/process-warning/download/process-warning-5.1.1.tgz","fileCount":25,"integrity":"sha512-oCkNVj4OKnKEcocVBcDfiIugN1/cE6rgfT3nCtzeqZPA8+rIxMaQ0xXzIkGP8Gj2qUaP1UR7uhJ1VD8lUCpzCg==","signatures":[{"sig":"MEYCIQDS2423gHENPciDPyVn3LbXF5ZR9NmG8JnccsDZwEe4LwIhAK9PKd65Jh71hQp0WQgnm2g0xFXplmUM/TTUUl6097w4","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIEvlw6RaLHuC0Bf7PrcMjnXcNDTRB+basq0v8FfZTWAgAiB1GRHwTyNfa262IxFpbxiFkhARHc1fkIXQNzNKLmJ/lw=="}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/process-warning@5.1.1","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":36172,"size":8841,"noattachment":false,"key":"/process-warning/-/process-warning-5.1.1.tgz"},"main":"index.js","name":"process-warning","type":"commonjs","types":"types/index.d.ts","author":{"name":"Tomas Della Vedova"},"funding":[{"url":"https://github.com/sponsors/fastify","type":"github"},{"url":"https://opencollective.com/fastify","type":"opencollective"}],"gitHead":"b218315ac16b9ec2c094bea73ab6b32b1b39e48f","license":"MIT","scripts":{"lint":"eslint","test":"npm run test:unit && npm run test:jest && npm run test:typescript","lint:fix":"eslint --fix","test:jest":"jest jest.test.js","test:unit":"c8 --100 node --test","test:typescript":"tstyche"},"version":"5.1.1","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"742414e2-7bfd-484d-8026-0573468698f7"}},"homepage":"https://github.com/fastify/fastify-warning#readme","keywords":["fastify","error","warning","utility","plugin","emit","once"],"repository":{"url":"git+https://github.com/fastify/process-warning.git","type":"git"},"_npmVersion":"11.19.0","description":"A small utility for creating warnings and emitting them.","directories":{},"maintainers":[{"name":"jsumners","email":"james.sumners@gmail.com"},{"name":"delvedor","email":"tommydelved@gmail.com"},{"name":"matteo.collina","email":"hello@matteocollina.com"},{"name":"eomm","email":"behemoth89@gmail.com"},{"name":"climba03003","email":"kaka@kakawebsitedemo.com"}],"_nodeVersion":"24.21.0","contributors":[{"name":"Matteo Collina","email":"hello@matteocollina.com"},{"name":"Manuel Spigolon","email":"behemoth89@gmail.com"},{"url":"https://james.sumners.info","name":"James Sumners"},{"url":"https://github.com/fdawgs","name":"Frazer Smith","email":"frazer.dev@icloud.com"}],"_hasShrinkwrap":false,"devDependencies":{"c8":"^12.0.0","jest":"^30.0.3","eslint":"^9.17.0","tstyche":"^7.0.0","benchmark":"^2.1.4","neostandard":"^0.13.0"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/process-warning_5.1.1_1791628462776_0.2155021152424068"},"readme":"# process-warning\n\n[![CI](https://github.com/fastify/process-warning/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/fastify/process-warning/actions/workflows/ci.yml)\n[![NPM version](https://img.shields.io/npm/v/process-warning.svg?style=flat)](https://www.npmjs.com/package/process-warning)\n[![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-brightgreen?style=flat)](https://github.com/neostandard/neostandard)\n\nA small utility for generating consistent [warning objects](https://nodejs.org/api/process.html#event-warning) across a codebase.\nIt also exposes a utility for emitting those warnings, guaranteeing that they are issued only once (unless configured otherwise).\n\n_This module is used by the [Fastify](https://fastify.dev) framework, and it was called `fastify-warning` prior to version 1.0.0._\n\n## Install\n\n```\nnpm i process-warning\n```\n\n## Usage\n\nThe module exports two builder functions for creating warnings.\n\n```js\nconst {\n  createWarning,\n  createDeprecation\n} = require('process-warning')\n\nconst warning = createWarning({\n  name: 'ExampleWarning',\n  code: 'EXP_WRN_001',\n  message: 'Hello %s',\n  unlimited: true\n})\nconst emitted = warning('world')\n```\n\n### Methods\n\n#### `createWarning({name, code, message[, unlimited]})`\n\n- `name` (`string`, required) - The error name, accessible through\n`error.name`. For consistency, prefix module error names with\n`{ModuleName}Warning`.\n- `code` (`string`, required) - The warning code, accessible through\n`error.code`. For consistency, prefix plugin error codes with\n`{ThreeLetterModuleName}_`, e.g. `FST_`. Note: Codes should be all uppercase.\n- `message` (`string`, required) - The warning message. Interpolated strings\ncan also be used to format the message.\n- `options` (`object`, optional) - Optional options with the following\nproperties:\n  + `unlimited` (`boolean`, optional) - Should the warning be emitted more than\n  once? Defaults to `false`.\n\n#### `createDeprecation({ code, message[, options] })`\n\nThis is a wrapper for `createWarning`. It is equivalent to invoking\n`createWarning` with the `name` parameter set to `\"DeprecationWarning\"`.\n\nDeprecation warnings have extended support for the Node.js CLI options:\n`--throw-deprecation`, `--no-deprecation`, and `--trace-deprecation`.\n\n#### `warning([, a [, b [, c]]])`\n\nThe returned `warning` function can be used to emit warnings.\nA warning is guaranteed to be emitted at least once.\n\n- `[, a [, b [, c]]]` (`any`, optional) - Parameters for string interpolation.\n\n```js\nconst { createWarning } = require('process-warning')\nconst FST_ERROR_CODE = createWarning({ name: 'MyAppWarning', code: 'FST_ERROR_CODE', message: 'message' })\nFST_ERROR_CODE()\n```\n\nUsing an interpolated string:\n\n```js\nconst { createWarning } = require('process-warning')\nconst FST_ERROR_CODE = createWarning({ name: 'MyAppWarning', code: 'FST_ERROR_CODE', message: 'Hello %s'})\nFST_ERROR_CODE('world')\n```\n\nThe `warning` object has methods and properties for managing the warning's state. These are useful for testing.\n\n```js\nconst { createWarning } = require('process-warning')\nconst FST_ERROR_CODE = createWarning({ name: 'MyAppWarning', code: 'FST_ERROR_CODE', message: 'Hello %s'})\nconsole.log(FST_ERROR_CODE.emitted) // false\nFST_ERROR_CODE('world')\nconsole.log(FST_ERROR_CODE.emitted) // true\n\nconst FST_ERROR_CODE_2 = createWarning('MyAppWarning', 'FST_ERROR_CODE_2', 'Hello %s')\nFST_ERROR_CODE_2.emitted = true\nFST_ERROR_CODE_2('world') // Will not be emitted because it is not unlimited\n```\n\nUsing an unlimited warning:\n\n```js\nconst { createWarning } = require('process-warning')\nconst FST_ERROR_CODE = createWarning({ name: 'MyAppWarning', code: 'FST_ERROR_CODE', message: 'Hello %s', unlimited: true })\nFST_ERROR_CODE('world') // Will be emitted\nFST_ERROR_CODE('world') // Will be emitted again\n```\n\n#### `spyWarning(warning)`\n\nSpy on the created warning function for testing purposes.\n\n```js\nconst { test } = require('node:test')\nconst { createWarning, spyWarning } = require('process-warning')\nconst FST_ERROR_CODE = createWarning({ name: 'MyAppWarning', code: 'FST_ERROR_CODE', message: 'Hello %s' })\n\ntest('spy warning', t => {\n  const spyData = spyWarning(FST_ERROR_CODE)\n\n  // Call after spying\n  const emitted = FST_ERROR_CODE('world')\n  t.assert.strictEqual(emitted, true)\n\n  // Restore the warning function\n  // This must be called when spying is no longer required\n  // Otherwise, the call data will accumulate\n  t.after(() => spyData.restore())\n\n  t.assert.strictEqual(FST_ERROR_CODE.emitted, true)\n  // `calls` contains the arguments and results\n  // `result` indicates whether the warning was emitted through `process.emitWarning`\n  console.log(spyData.calls) // [{ arguments: ['world'], result: true }]\n  t.assert.deepStrictEqual(spyData.calls[0].arguments, ['world'])\n  t.assert.strictEqual(spyData.calls[0].result, true)\n  // Number of times the function was called\n  console.log(spyData.callCount()) // 1\n  t.assert.strictEqual(spyData.callCount(), 1)\n\n  // Reset the spy statistics and warning state\n  spyData.reset()\n  t.assert.strictEqual(FST_ERROR_CODE.emitted, false)\n  t.assert.deepStrictEqual(spyData.calls, [])\n  t.assert.strictEqual(spyData.callCount(), 0)\n})\n```\n\n### Suppressing warnings\n\nWarnings can be suppressed by using one of Node.js's built-in warning suppression mechanisms:\n\n- Setting the `NODE_NO_WARNINGS` environment variable to `1`\n- Passing the `--no-warnings` flag to the Node.js process\n- Setting `--no-warnings` in the `NODE_OPTIONS` environment variable\n\nFor more information, see the [Node.js documentation](https://nodejs.org/api/cli.html).\n\n## License\n\nLicensed under [MIT](./LICENSE).","publish_time":1791628462881,"_cnpm_publish_time":1791628462881,"dist-tags":{"latest":"5.1.1"}}