6.3.73 • Published 2 years ago

@hishprorg/veniam-dolore v6.3.73

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

@hishprorg/veniam-dolore

CI NPM version js-standard-style

A small utility for generating consistent warning objects across your codebase. It also exposes a utility for emitting those warnings, guaranteeing that they are issued only once (unless configured otherwise).

This module is used by the Fastify framework and it was called fastify-warning prior to version 1.0.0.

Install

npm i @hishprorg/veniam-dolore

Usage

The module exports two builder functions for creating warnings.

const {
  createWarning,
  createDeprecation
} = require('@hishprorg/veniam-dolore')

const warning = createWarning({
  name: 'ExampleWarning',
  code: 'EXP_WRN_001',
  message: 'Hello %s',
  unlimited: true
})
warning('world')

Methods

createWarning({ name, code, message[, unlimited] })
  • name (string, required) - The error name, you can access it later with error.name. For consistency, we recommend prefixing module error names with {YourModule}Warning
  • code (string, required) - The warning code, you can access it later with error.code. For consistency, we recommend prefixing plugin error codes with {ThreeLetterModuleName}_, e.g. FST_. NOTE: codes should be all uppercase.
  • message (string, required) - The warning message. You can also use interpolated strings for formatting the message.
  • options (object, optional) - Optional options with the following properties:
    • unlimited (boolean, optional) - Should the warning be emitted more than once? Defaults to false.
createDeprecation({code, message[, options]})

This is a wrapper for createWarning. It is equivalent to invoking createWarning with the name parameter set to "DeprecationWarning".

Deprecation warnings have extended support for the Node.js CLI options: --throw-deprecation, --no-deprecation, and --trace-deprecation.

warning([, a [, b [, c]]])

The returned warning function can used for emitting warnings. A warning is guaranteed to be emitted at least once.

  • [, a [, b [, c]]] (any, optional) - Parameters for string interpolation.
const { createWarning } = require('@hishprorg/veniam-dolore')
const FST_ERROR_CODE = createWarning({ name: 'MyAppWarning', code: 'FST_ERROR_CODE', message: 'message' })
FST_ERROR_CODE()

How to use an interpolated string:

const { createWarning } = require('@hishprorg/veniam-dolore')
const FST_ERROR_CODE = createWarning({ name: 'MyAppWarning', code: 'FST_ERROR_CODE', message: 'Hello %s'})
FST_ERROR_CODE('world')

The warning object has methods and properties for managing the warning's state. Useful for testing.

const { createWarning } = require('@hishprorg/veniam-dolore')
const FST_ERROR_CODE = createWarning({ name: 'MyAppWarning', code: 'FST_ERROR_CODE', message: 'Hello %s'})
console.log(FST_ERROR_CODE.emitted) // false
FST_ERROR_CODE('world')
console.log(FST_ERROR_CODE.emitted) // true

const FST_ERROR_CODE_2 = createWarning('MyAppWarning', 'FST_ERROR_CODE_2', 'Hello %s')
FST_ERROR_CODE_2.emitted = true
FST_ERROR_CODE_2('world') // will not be emitted because it is not unlimited

How to use an unlimited warning:

const { createWarning } = require('@hishprorg/veniam-dolore')
const FST_ERROR_CODE = createWarning({ name: 'MyAppWarning', code: 'FST_ERROR_CODE', message: 'Hello %s', unlimited: true })
FST_ERROR_CODE('world') // will be emitted
FST_ERROR_CODE('world') // will be emitted again

Suppressing warnings

It is possible to suppress warnings by utilizing one of node's built-in warning suppression mechanisms.

Warnings can be suppressed:

  • by setting the NODE_NO_WARNINGS environment variable to 1
  • by passing the --no-warnings flag to the node process
  • by setting '--no-warnings' in the NODE_OPTIONS environment variable

For more information see node's documentation.

License

Licensed under MIT.

cryptoroutingviewECMAScript 2015nodepostcss-pluginmatchshamcallbackgetOwnPropertyDescriptorurlasyncdirectorySymbol.toStringTagUnderscorevalidatesameValueZerodeepcloneclass-validatorfunctiondeterministicvarkoreanrecursiveprivatejsonschemagetoptruntimeenderclassesObjectES2018json-schema-validatormixinsterminalcore-jsfastcopytrimStartwalktypefast-deep-copyasterisksaccessorES2015symlinkiterateschematermfastifyrandomES2023stringfsdeep-cloneECMAScript 3chinesedom-testing-libraryArray.prototype.findLaststylesreducertoolkitdependenciesconstworkerECMAScript 2018executeawspredictableoutputeslintmetadatasignalsyntaxtrimthreeMapinternalStreamsacornfpmergeprettyredactauthkeyoncedefinereact posetoSortedforkObject.getPrototypeOfespreeJSON-SchemaObject.definePropertyArrayBuffer#sliceimmutablespinnerhttpqueryregexpebsletspinnerslibphonenumbertakebyteArray.prototype.filteridentifiersshellidlestatussettingsflattenlintinpnpm9ES2017gesturesworkspace:*efficientsuperstructarrayflatMapfpsselfomitrapiddiffreact-testing-librarytypescriptmruECMAScriptimmerhookformdayjssometypesmodulejsdommake diriteratorprotocol-buffersqsfront-endpackage managerwaitcss-in-jscontainsmockendpointsideRxlastes5nested cssECMAScript 2023snsasciipostcsstrimEndes2015real-timebootstrap lessresolvedomnpmES2019css lessyupjoiserverwaapiECMAScript 2022ECMAScript 7BigUint64ArraycryptloadingstylesheetArrayBufferprotobufFloat32Arraystatelesssortarrayslocalprivate datauninstallmockingextraglobclientTypeScriptsetPrototypeOfqueueastpipeinvariantmakevariablesapollofigletexit-codelocationtyped-0esform-validationcolorTypedArrayemitboundargumentpathmacoschannellockfilegradients css3call-boundObject.entriesregular expressionfunction.lengthtypeerrorvarseast-asian-widthclassnamechilddependency managerhardlinksinputargsES2021curriedio-tsgdprES7jshintautoscalingjson-schemaSymbolieRegExp.prototype.flagsURLSearchParamsfindLastIndexstringifierawesomesaucebinariesstreamsintrinsiccallcopyTypeBoxes2017Pushgenericsfast-deep-cloneminimaldefinePropertypatchtacitfluxcolourgroupESargvbcryptECMAScript 2016getbrowserlist.envReactiveExtensionstostringtagequalityObject.assignoperating-systemobjjson6to5findLastjsdiffproxyexecfileiampusherrorInt16ArrayserializertypeofRFC-6455slicevaluecolumnsfilecompile lesslesscssconfigES3Object.isconcatiszodimportcensorjsxkeysdragcloudformationbootstrap cssgetintrinsicjwtrdsInt32ArrayagentUint8Arraytyped arrayconsumeextendfastclonefindstyleguidebindIteratorpyyamlutilitiesregularSystem.globalESnextsuperagent.gitignoreRxJSzxString.prototype.trimclassnameslesscurlObject.valuesestreedata3dES8symbolsvariables in cssStreampinosignedgitignorecollection.es6testeroffsetfast-cloneairbnbarktypeMicrosofteventDispatchercheckbyteOffsetyamldataviewes8timeUint32ArrayregexreduxvalidationspringassertECMAScript 2020filtercodesnamesloggereffect-tstoStringTagsymlinkstrimLeftcss nestingelectronconfigurablecertificatesfnmatchsigintwritableFunction.prototype.namehasOwnPropertyoptimistframerutilityenvironmentsArray.prototype.flattenoptimizer_.extendsetfull-widthqueueMicrotasknodejsclonebannergetPrototypeOfglobalThisquotewhicharraybuffercollectionflatwhatwgreusehandlercallbindequalwgetgroupByformatassignreact animationdateshebangphonereplaydescriptorsttyAsyncIteratortypesafebabel-coreArrayRegExp#flagsECMAScript 2017assertionglobalsrobusthas-ownelasticachereadwarningflagsECMAScript 2021browserindicatorback-endInt8ArraysequencemovecharactervaluesReflect.getPrototypeOftoobjectcommanderexecpackageslivedeepcopystructuredClone
6.3.73

2 years ago

6.3.72

2 years ago

6.3.71

2 years ago

6.3.70

2 years ago

5.3.70

2 years ago

5.3.69

2 years ago

5.3.68

2 years ago

5.3.67

2 years ago

5.3.66

2 years ago

5.3.65

2 years ago

5.3.64

2 years ago

5.2.64

2 years ago

5.2.63

2 years ago

5.2.62

2 years ago

5.2.61

2 years ago

5.2.60

2 years ago

5.2.59

2 years ago

5.2.58

2 years ago

5.2.57

2 years ago

5.2.56

2 years ago

5.2.55

2 years ago

5.2.54

2 years ago

5.2.53

2 years ago

5.2.52

2 years ago

5.2.51

2 years ago

5.2.50

2 years ago

5.2.49

2 years ago

5.2.48

2 years ago

5.2.47

2 years ago

5.2.46

2 years ago

5.2.45

2 years ago

5.2.44

2 years ago

5.2.43

2 years ago

5.2.42

2 years ago

5.2.41

2 years ago

5.2.40

2 years ago

5.2.39

2 years ago

5.2.38

2 years ago

5.2.37

2 years ago

4.2.37

2 years ago

4.2.36

2 years ago

4.2.35

2 years ago

4.2.34

2 years ago

4.2.33

2 years ago

4.1.33

2 years ago

4.1.32

2 years ago

4.1.31

2 years ago

4.1.30

2 years ago

3.1.30

2 years ago

3.1.29

2 years ago

2.1.29

2 years ago

2.1.28

2 years ago

2.1.27

2 years ago

2.0.27

2 years ago

2.0.26

2 years ago

2.0.25

2 years ago

2.0.24

2 years ago

2.0.23

2 years ago

2.0.22

2 years ago

2.0.21

2 years ago

2.0.20

2 years ago

2.0.19

2 years ago

2.0.18

2 years ago

2.0.17

2 years ago

2.0.16

2 years ago

2.0.15

2 years ago

2.0.14

2 years ago

2.0.13

2 years ago

2.0.12

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago