{"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":{"integrity":"sha512-s1EQguBw/9qtc1p/WTY4eq9WMRIACkj+HTcOIK1in4MV5aFaQC9ZCIt0dJ7pr5bIf4lPpHvAtP2ywpTNgs7hqw==","shasum":"e717776026a4493dc9a2befa44db6d17f618008f","tarball":"http://registry-npm.ywwl.com/fastify-warning/download/fastify-warning-0.2.0.tgz","fileCount":9,"unpackedSize":10980,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfID4zCRA9TVsSAnZWagAAjrcP/jPEdql8Jlm6Dzl89Swm\nN2/0YPgYcGleIZ26WwulIIcHhLv1WcDiHXo4gPEgSiYTZxAuUMs3ocbNc/8e\nXTCCOPfmdLQkvFY/iJYvUJE41hdmNHwCHeQcCd1MFP2A3jS9RzVZR+xNynne\n+zzwMFn3wcLWg0vEDphPuEZSvlKFOrByADsLc2A/5iUgDwA5r98GEoc7fK9B\nUnk3Eelrs/p7pNV/aqcqOyRF6O3a8SvtGjdRytvlOm+ISxgCgFjOmaoxHxMe\nXzcVn7WdkIpuNKtnt30o9Dxm4kLE6GU8SnbHQORaSOWIv+Xkk35YidoLUFUj\nBF0IjD58n2ntihN8JAZBOo3eqE+TY1JojMfx5Z4QLjtjVogAmQFu3SBiH3Nx\nlo+eEICVHrYNa09ZdcjCP4wn7OWOJLWSX3/AMdmgb2MeM/W0wybKwBdJBAV7\nAljeKtrLlx8CiVufsbjGqXOJAZj8YndUmIvneRe4g1oVDrzZOMRPp0afiBRx\n59K5PEERL/qba/actU2XDAURDIk/FzzASNESjgYsM0zvSnubcX8ONPp/TeBp\nrjGFoRlz8c2YbBuDW4eqRjFnEF2/loiTdAwSzDt26lVSlADydqlxHLEZPg/D\n3oZzZkXzBpeCyRHiZ7Yf5lou3EHIwbaPKQNQ5zrjJ+fhw4NbWi9b8dh90vFJ\nOFJn\r\n=nsGt\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDYVV92OKbOH1Z0SCndcgAPOJc6Eh2Hu3c9HmLIlUueQQIgCJmTaqAn/pL7qCegVSwX9U8bmHiMhXm+hEbR33RCGyo="}],"size":3908,"noattachment":false,"key":"/fastify-warning/-/fastify-warning-0.2.0.tgz"},"maintainers":[{"name":"delvedor","email":"tommydelved@gmail.com"}],"_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,"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","publish_time":1595948594497,"_cnpm_publish_time":1595948594497,"dist-tags":{"latest":"0.2.0"}}