{"_id":"fastify-warning","_rev":"202372","name":"fastify-warning","description":"A small utility for creating warnings and emitting them.","dist-tags":{"latest":"0.2.0"},"maintainers":[{"name":"delvedor","email":""},{"name":"eomm","email":""},{"name":"jsumners","email":""},{"name":"matteo.collina","email":""}],"time":{"modified":"2023-03-21T06:28:06.000Z","created":"2020-07-26T13:24:41.371Z","0.2.0":"2020-07-28T15:03:14.497Z","0.1.0":"2020-07-26T13:24:41.371Z"},"users":{},"author":{"name":"Tomas Della Vedova"},"repository":{"type":"git","url":"git+https://github.com/fastify/fastify-warning.git"},"versions":{"0.2.0":{"name":"fastify-warning","version":"0.2.0","description":"A small utility for creating warnings and emitting them.","main":"index.js","types":"index.d.ts","scripts":{"test":"standard && ava -v test.js && jest jest.test.js && tsd"},"repository":{"type":"git","url":"git+https://github.com/fastify/fastify-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":{"ava":"^3.10.1","jest":"^26.1.0","standard":"^14.3.4","tsd":"^0.13.1"},"gitHead":"bbbae97ce990657a7089bb71b425937e96b9b2e7","_id":"fastify-warning@0.2.0","_nodeVersion":"12.18.1","_npmVersion":"6.14.5","dist":{"shasum":"e717776026a4493dc9a2befa44db6d17f618008f","size":3908,"noattachment":false,"key":"/fastify-warning/-/fastify-warning-0.2.0.tgz","tarball":"http://name.csiicloud.com:7001/fastify-warning/download/fastify-warning-0.2.0.tgz"},"maintainers":[{"name":"delvedor","email":""},{"name":"eomm","email":""},{"name":"jsumners","email":""},{"name":"matteo.collina","email":""}],"_npmUser":{"name":"delvedor","email":"tommydelved@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/fastify-warning_0.2.0_1595948594364_0.8030099287583465"},"_hasShrinkwrap":false,"publish_time":1595948594497,"_cnpm_publish_time":1595948594497,"_cnpmcore_publish_time":"2021-12-16T11:28:18.894Z","deprecated":"This module renamed to process-warning"},"0.1.0":{"name":"fastify-warning","version":"0.1.0","description":"A small utility for creating warnings and emitting them.","main":"index.js","types":"index.d.ts","scripts":{"test":"standard && ava -v && tsd"},"repository":{"type":"git","url":"git+https://github.com/fastify/fastify-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":{"ava":"^3.10.1","standard":"^14.3.4","tsd":"^0.13.1"},"gitHead":"d3647c1cb8bdf302e143756a065376ad7fea42ef","_id":"fastify-warning@0.1.0","_nodeVersion":"12.18.1","_npmVersion":"6.14.5","dist":{"shasum":"319846d6d481cc90ed5d9caf828df82515e3ad30","size":3783,"noattachment":false,"key":"/fastify-warning/-/fastify-warning-0.1.0.tgz","tarball":"http://name.csiicloud.com:7001/fastify-warning/download/fastify-warning-0.1.0.tgz"},"maintainers":[{"name":"delvedor","email":""},{"name":"eomm","email":""},{"name":"jsumners","email":""},{"name":"matteo.collina","email":""}],"_npmUser":{"name":"delvedor","email":"tommydelved@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/fastify-warning_0.1.0_1595769881250_0.4278316151227577"},"_hasShrinkwrap":false,"publish_time":1595769881371,"_cnpm_publish_time":1595769881371,"_cnpmcore_publish_time":"2021-12-16T11:28:19.150Z","deprecated":"This module renamed to process-warning"}},"readme":"# fastify-warning\n\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](http://standardjs.com/)  ![build](https://github.com/fastify/fastify-warning/workflows/build/badge.svg)\n\nA small utility, used by Fastify itself, for generating consistent warning objects across your codebase and plugins.\nIt also exposes a utility for emitting those warnings, guaranteeing that they are issued only once.\n\n### Install\n```\nnpm i fastify-warning\n```\n\n### Usage\n\nThe module exports a builder function that returns an utility for creating warnings and emitting them.\n\n```js\nconst warning = require('fastify-warning')()\n```\n\n#### Methods\n\n```\nwarning.create(name, code, message)\n```\n\n- `name` (`string`, required) - The error name, you can access it later with `error.name`. For consistency, we recommend to prefix plugin error names with `FastifWarning{YourPluginName}`\n- `code` (`string`, required) - The warning code, you can access it later with `error.code`. For consistency, we recommend to prefix plugin error codes with `FST_{YourPluginName}_`\n- `message` (`string`, required) - The warning message. You can also use interpolated strings for formatting the message.\n\nThe utility also contains an `emit` function that you can use for emitting the warnings you have previously created by passing their respective code. A warning is guaranteed to be emitted only once.\n\n```\nwarning.emit(code [, a [, b [, c]]])\n```\n\n- `code` (`string`, required) - The warning code you intend to emit.\n- `[, a [, b [, c]]]` (`any`, optional) - Parameters for string interpolation.\n\n```js\nconst warning = require('fastify-warning')()\nwarning.create('FastifyWarning', 'FST_ERROR_CODE', 'message')\nwarning.emit('FST_ERROR_CODE')\n```\n\nHow to use a interpolated string:\n```js\nconst warning = require('fastify-warning')()\nwarning.create('FastifyWarning', 'FST_ERROR_CODE', 'Hello %s')\nwarning.emit('FST_ERROR_CODE', 'world')\n```\n\nThe module also exports an `warning.emitted` [Map](https://developer.mozilla.org/it/docs/Web/JavaScript/Reference/Global_Objects/Map), which contains all the warnings already emitted. Useful for testing.\n```js\nconst warning = require('fastify-warning')()\nwarning.create('FastifyWarning', 'FST_ERROR_CODE', 'Hello %s')\nconsole.log(warning.emitted.get('FST_ERROR_CODE')) // false\nwarning.emit('FST_ERROR_CODE', 'world')\nconsole.log(warning.emitted.get('FST_ERROR_CODE')) // true\n```\n\n## License\n\nLicensed under [MIT](./LICENSE).\n","_attachments":{},"homepage":"https://github.com/fastify/fastify-warning#readme","bugs":{"url":"https://github.com/fastify/fastify-warning/issues"},"license":"MIT"}