4.13.95 • Published 1 year ago

@taktikorg/perferendis-repellendus v4.13.95

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@taktikorg/perferendis-repellendus

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 @taktikorg/perferendis-repellendus

Usage

The module exports two builder functions for creating warnings.

const {
  createWarning,
  createDeprecation
} = require('@taktikorg/perferendis-repellendus')

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('@taktikorg/perferendis-repellendus')
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('@taktikorg/perferendis-repellendus')
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('@taktikorg/perferendis-repellendus')
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('@taktikorg/perferendis-repellendus')
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.

webawesomesauceStreamstreamguidxhreventscurlassignreduxpathES8accessibilityfsinvariantcall-bindqueueoptimizerglaciercode pointsWebSocketsloadbalancingidsnslogvalidatoratomnamecolorservereslint-pluginES2021valuescollectionES2019s3eventDispatcherECMAScript 3writablecolumnsortedwritemomentinternal slotsesagentgroupdebugurlpipedependenciesclass-validatorcharactersstringifyjasmineisConcatSpreadabletypespreprocessorTypeScriptObjectWeakSetglobalsyntaxerrormochatapemockcoveragebindargssetHyBipackage.jsonhooksarttransportfantasy-landfilerm -rfi18njapanesejson-schemacharacterArrayBufferawsstructuredClonearraylook-upmoveES2020ArrayBuffer#slicedirectoryinternalgetoptmanipulationes-abstractperformantinspectfindreact-hook-formmkdirppicomatcharraybufferbrowserlistnamesresolveJSONPromiselanguageasterisksvpccopy0getOwnPropertyDescriptorextendbrowserthreegenericsObject.definePropertydiffform-validationshim$.extendpushInt8ArrayJSON-Schemaes2018-0busymatchAllajaxhasOwnchildlockfilehttpvarsreact posefunction.lengthjQueryrouteIteratorrestfulfpyamlfindupjsdiffstreamsrulesansiArray.prototype.containsutiles8globalsponyfillspeedstyleguidereaddescriptorECMAScript 2019xmlbddES2015CSSmodulescacheiteratorreact-testing-librarycommandcodesisregular-expressionexpressSymbol.toStringTaggdprArray.prototype.flatlintsortflattentranspilerES5requirezeroyuproute53endpointlistenersenvironmentsoutputinstallRxJSSetshameslintconfiginstallerruntimepropdescriptorstacittoobjectassert3dbeanstalkcolumnswalkingzxfeedtypedarraysserializercomputed-typesfixed-widthtddprefixutilsinstrumentationa11ydataformatECMAScript 6getPrototypeOfUint16ArraymapsearchfpstoSortedredactroutershebangshellconfigurablematcheskinesisbannerignorespinners@@toStringTagpromiseapisetImmediatecorelengthObject.getPrototypeOfnpmignorerequestdeepcloneES2016Push
4.13.95

1 year ago

4.13.94

1 year ago

4.13.93

1 year ago

4.13.92

1 year ago

4.13.91

1 year ago

4.13.90

1 year ago

4.12.90

1 year ago

4.12.89

1 year ago

4.12.88

1 year ago

4.12.87

1 year ago

4.12.86

1 year ago

3.12.86

1 year ago

3.12.85

1 year ago

3.12.84

1 year ago

3.12.83

1 year ago

3.12.82

1 year ago

3.12.81

1 year ago

3.12.80

1 year ago

3.12.79

1 year ago

3.12.78

1 year ago

3.12.77

1 year ago

3.12.76

1 year ago

3.11.76

1 year ago

3.11.75

1 year ago

3.11.74

1 year ago

3.11.73

1 year ago

3.10.73

1 year ago

3.10.72

1 year ago

3.10.71

1 year ago

3.10.70

1 year ago

3.10.69

1 year ago

3.10.68

1 year ago

2.10.68

1 year ago

2.10.67

1 year ago

2.10.66

1 year ago

2.10.65

1 year ago

2.10.64

1 year ago

2.10.63

1 year ago

2.10.62

1 year ago

2.10.61

1 year ago

2.10.60

1 year ago

2.10.59

1 year ago

2.10.58

1 year ago

2.10.57

1 year ago

2.10.56

1 year ago

2.10.55

1 year ago

2.9.55

1 year ago

2.9.54

1 year ago

2.9.53

1 year ago

2.9.52

1 year ago

2.9.51

1 year ago

2.9.50

1 year ago

2.9.49

1 year ago

2.9.48

1 year ago

2.9.47

1 year ago

2.9.46

1 year ago

2.9.45

1 year ago

2.9.44

1 year ago

2.9.43

1 year ago

2.9.42

1 year ago

2.9.41

1 year ago

1.9.41

1 year ago

1.9.40

1 year ago

1.9.39

1 year ago

1.9.38

1 year ago

1.9.37

1 year ago

1.8.37

1 year ago

1.8.36

1 year ago

1.7.36

1 year ago

1.7.35

1 year ago

1.7.34

1 year ago

1.7.33

1 year ago

1.7.32

1 year ago

1.7.31

1 year ago

1.7.30

1 year ago

1.7.29

1 year ago

1.7.28

1 year ago

1.6.28

1 year ago

1.6.27

1 year ago

1.6.26

1 year ago

1.6.25

1 year ago

1.6.24

1 year ago

1.5.24

1 year ago

1.5.23

1 year ago

1.5.22

1 year ago

1.5.21

1 year ago

1.5.20

1 year ago

1.5.19

1 year ago

1.5.18

1 year ago

1.5.17

1 year ago

1.5.16

1 year ago

1.5.15

1 year ago

1.5.14

1 year ago

1.5.13

1 year ago

1.4.13

1 year ago

1.4.12

1 year ago

1.4.11

1 year ago

1.3.11

1 year ago

1.3.10

1 year ago

1.3.9

1 year ago

1.3.8

1 year ago

1.3.7

1 year ago

1.3.6

1 year ago

1.2.6

1 year ago

1.2.5

1 year ago

1.2.4

1 year ago

1.1.4

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago