{"id":13524450,"url":"https://github.com/fastify/process-warning","last_synced_at":"2025-05-16T03:04:43.179Z","repository":{"id":37965504,"uuid":"275332570","full_name":"fastify/process-warning","owner":"fastify","description":"A small utility for creating warnings and emitting them","archived":false,"fork":false,"pushed_at":"2025-05-01T12:59:52.000Z","size":142,"stargazers_count":38,"open_issues_count":0,"forks_count":10,"subscribers_count":12,"default_branch":"main","last_synced_at":"2025-05-07T09:04:23.594Z","etag":null,"topics":["fastify-library"],"latest_commit_sha":null,"homepage":"https://npmjs.com/package/process-warning","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fastify.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"fastify","open_collective":"fastify"}},"created_at":"2020-06-27T08:41:17.000Z","updated_at":"2025-05-01T12:59:49.000Z","dependencies_parsed_at":"2024-04-26T19:27:04.988Z","dependency_job_id":"9ab7b699-715a-43c6-bcb5-833e83c1f27b","html_url":"https://github.com/fastify/process-warning","commit_stats":{"total_commits":119,"total_committers":16,"mean_commits":7.4375,"dds":0.5798319327731092,"last_synced_commit":"9aacedebb1e8bc00adaabf9f676add62521ed54e"},"previous_names":["fastify/fastify-warning"],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastify%2Fprocess-warning","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastify%2Fprocess-warning/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastify%2Fprocess-warning/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastify%2Fprocess-warning/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fastify","download_url":"https://codeload.github.com/fastify/process-warning/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254459088,"owners_count":22074605,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fastify-library"],"created_at":"2024-08-01T06:01:10.199Z","updated_at":"2025-05-16T03:04:38.168Z","avatar_url":"https://github.com/fastify.png","language":"JavaScript","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 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.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})\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","funding_links":["https://github.com/sponsors/fastify","https://opencollective.com/fastify"],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffastify%2Fprocess-warning","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffastify%2Fprocess-warning","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffastify%2Fprocess-warning/lists"}