Security News
The Unpaid Backbone of Open Source: Solo Maintainers Face Increasing Security Demands
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
fastify-warning
Advanced tools
A small utility, used by Fastify itself, for generating consistent warning objects across your codebase and plugins. It also exposes a utility for emitting those warnings, guaranteeing that they are issued only once.
npm i fastify-warning
The module exports a builder function that returns an utility for creating warnings and emitting them.
const warning = require('fastify-warning')()
warning.create(name, code, message)
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}
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}_
message
(string
, required) - The warning message. You can also use interpolated strings for formatting the message.The 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.
warning.emit(code [, a [, b [, c]]])
code
(string
, required) - The warning code you intend to emit.[, a [, b [, c]]]
(any
, optional) - Parameters for string interpolation.const warning = require('fastify-warning')()
warning.create('FastifyWarning', 'FST_ERROR_CODE', 'message')
warning.emit('FST_ERROR_CODE')
How to use a interpolated string:
const warning = require('fastify-warning')()
warning.create('FastifyWarning', 'FST_ERROR_CODE', 'Hello %s')
warning.emit('FST_ERROR_CODE', 'world')
The module also exports an warning.emitted
Map, which contains all the warnings already emitted. Useful for testing.
const warning = require('fastify-warning')()
warning.create('FastifyWarning', 'FST_ERROR_CODE', 'Hello %s')
console.log(warning.emitted.get('FST_ERROR_CODE')) // false
warning.emit('FST_ERROR_CODE', 'world')
console.log(warning.emitted.get('FST_ERROR_CODE')) // true
Licensed under MIT.
FAQs
A small utility for creating warnings and emitting them.
The npm package fastify-warning receives a total of 112,474 weekly downloads. As such, fastify-warning popularity was classified as popular.
We found that fastify-warning demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.
Security News
A developer is accusing Tencent of violating the GPL by modifying a Python utility and changing its license to BSD, highlighting the importance of copyleft compliance.