{"name":"process-warning","version":"2.2.0","description":"A small utility for creating warnings and emitting them.","main":"index.js","types":"types/index.d.ts","scripts":{"lint":"standard","lint:fix":"standard --fix","test":"npm run test:unit && npm run test:jest && npm run test:typescript","test:jest":"jest jest.test.js","test:unit":"tap","test:typescript":"tsd"},"repository":{"type":"git","url":"git+https://github.com/fastify/process-warning.git"},"keywords":["fastify","error","warning","utility","plugin","emit","once"],"author":{"name":"Tomas Della Vedova"},"license":"MIT","bugs":{"url":"https://github.com/fastify/fastify-warning/issues"},"homepage":"https://github.com/fastify/fastify-warning#readme","devDependencies":{"benchmark":"^2.1.4","jest":"^29.0.1","standard":"^17.0.0","tap":"^16.3.0","tsd":"^0.28.0"},"gitHead":"ca9dd68fe90ad5aafc0a1ce0384d45b2fe927733","_id":"process-warning@2.2.0","_nodeVersion":"18.15.0","_npmVersion":"9.5.0","dist":{"integrity":"sha512-/1WZ8+VQjR6avWOgHeEPd7SDQmFQ1B5mC1eRXsCm5TarlNmx/wCsa5GEaxGm05BORRtyG/Ex/3xq3TuRvq57qg==","shasum":"008ec76b579820a8e5c35d81960525ca64feb626","tarball":"http://registry-npm.ywwl.com/process-warning/download/process-warning-2.2.0.tgz","fileCount":15,"unpackedSize":14702,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIALWBVm4FqNk00AE9Yv7lppWezzLnw5k2DvRaU7KWH24AiEA2efwpPvphcjEplpTcUShVFW/mBROlous8lRbwsl1k4E="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkLFplACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqLtA//X6p/Osefqmx7QrpLsC9vSXPgtPF+zEqvjg8sJz4ebRFFNp6M\r\nSIyRwFVc1oWNLurZdRyT+mS21IYzWHPk+f/r2lJZsbzwLxcE2U6itncJXLd+\r\n5+5xFIbI9SaFoaoSuYsT0w3IZLKtIL+y63bscSRM8wqf5vNn1rsrxf5dvN8B\r\nN2TDXn0YUkMqHFsAYu74rM2COOoZQEvg1Q1TTZgNwpNJykgs9cHscBpsfqKC\r\nb41jbh4C7FtaVhdnrRmy+/XXkMF+zxHHikSzqt1FEcFHC9g8d7w/2as0JVZQ\r\nrROcpudFQNJ+63tnj2tHyrhKk6ZofYzwoxZVL6ySVTDn1sNvc1PYzMub6b1b\r\nUD4KK/alMxJ90rmktwPy0ZZnUq/Dor/6bStmY/gK8T8dJft41e33hUessFVH\r\npU84Joi6RcWvjeOpSx7fkemPslS22Iwz0SvigVjBfYmcrGxORzwH2tlTUwTB\r\nwcw4s+sXhh+PZt9wyNkJULdGlhxZPtBf5KLDTjmCgS1p6SSDPfFNkouU7Syj\r\nfWT+xVQvH5AUqh005vPxq4PstEHupsN10YuqSPPKvYeqFDI0jbKLr5rZG/nc\r\n54buEZqmESgw28OxSD8eU3O2LIW4ULKl4ep9jnwIRhBVH3w9D3jRTbC1M2c7\r\nlvYq+tIak8ZM/IcIrmIE0xMsUekQqqlxXos=\r\n=x7lb\r\n-----END PGP SIGNATURE-----\r\n","size":4834,"noattachment":false,"key":"/process-warning/-/process-warning-2.2.0.tgz"},"_npmUser":{"name":"matteo.collina","email":"hello@matteocollina.com"},"directories":{},"maintainers":[{"name":"matteo.collina","email":"hello@matteocollina.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/process-warning_2.2.0_1680628325134_0.5408404237875684"},"_hasShrinkwrap":false,"readme":"# process-warning\n\n![CI](https://github.com/fastify/process-warning/workflows/CI/badge.svg)\n[![NPM version](https://img.shields.io/npm/v/process-warning.svg?style=flat)](https://www.npmjs.com/package/process-warning)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/)\n\nA small utility for generating consistent warning objects across your 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.io) 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})\nwarning('world')\n```\n\n#### Methods\n\n##### `createWarning({ name, code, message[, unlimited] })`\n\n- `name` (`string`, required) - The error name, you can access it later with\n`error.name`. For consistency, we recommend prefixing module error names\nwith `{YourModule}Warning`\n- `code` (`string`, required) - The warning code, you can access it later with\n`error.code`. For consistency, we recommend prefixing plugin error codes with\n`{ThreeLetterModuleName}_`, e.g. `FST_`. NOTE: codes should be all uppercase.\n- `message` (`string`, required) - The warning message. You can also use\ninterpolated strings for formatting 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\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 used for emitting 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\nHow to use an interpolated string:\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. Useful for testing.\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\nHow to use an unlimited warning:\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#### Suppressing warnings\n\nIt is possible to suppress warnings by utilizing one of node's built-in warning suppression mechanisms.\n\nWarnings can be suppressed:\n\n- by setting the `NODE_NO_WARNINGS` environment variable to `1`\n- by passing the `--no-warnings` flag to the node process\n- by setting 'no-warnings' in the `NODE_OPTIONS` environment variable\n\nFor more information see [node's documentation](https://nodejs.org/api/cli.html).\n\n## License\n\nLicensed under [MIT](./LICENSE).\n","publish_time":1680628325333,"_cnpm_publish_time":1680628325333,"dist-tags":{"latest":"5.1.1"}}