3.9.85 • Published 12 months ago

@erboladaiorg/ullam-laboriosam v3.9.85

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

@erboladaiorg/ullam-laboriosam

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 @erboladaiorg/ullam-laboriosam

Usage

The module exports two builder functions for creating warnings.

const {
  createWarning,
  createDeprecation
} = require('@erboladaiorg/ullam-laboriosam')

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('@erboladaiorg/ullam-laboriosam')
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('@erboladaiorg/ullam-laboriosam')
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('@erboladaiorg/ullam-laboriosam')
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('@erboladaiorg/ullam-laboriosam')
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.

Object.fromEntriesnested cssECMAScript 2017fastcopyhashvargetoptcloneservicetextdirectoryiteratortc39genericsbytestableauthenticationglobredirectSystem.globalwalkcopytraversetransportWeakSetterminalpostcss-pluginredux-toolkitback-endcodesserverless cssawesomesaucetoobjectloggerES2018npmqsparseECMAScript 7popmotiondeepcopystyled-componentsvalidatoruser-streamsPushcloudsearchtimefastclonesesinspectrapidbootstrap lessECMAScript 2020awssnscloudwatchinstalldynamodbacorntrimbufferreal-timecensoreventDispatcherargumentautoscalingRegExp.prototype.flagspackage managerformscssbrowserlistsharedarraybufferscheme-validationstringifiercallgroupbannerObservablesprettyconcatMapconfigFunction.prototype.namemergeglobal objectURLnativebrowserjson-schema-validatorArray.prototype.findLastIndexjavascriptArrayopensslSetinterruptsregexpmixinsfindLastdependency managersetterpluginlazyec2ECMAScript 2016resolvedeterministicES5arraylivevesteffect-tsregextestECMAScript 2018classnamespyyamlio-tsless mixinsassigncore-jsES7sqscollectionwhatwgshebangmanagermatchesboundflattenargsflatsettingsemitfullwidthwgetes2017asserts3httpsUint16ArraytrimEndimmer@@toStringTagprefixreact-componentStreamstringspecArray.prototype.includescurl[[Prototype]]httpECMAScript 5workflowtoolkitgitignoresequencebootstrap cssYAMLoutputreducerdirstringifykeynodejsES2017handlerencryptionESnexttesterestreettyfileconfigurablemomentObjectagenttoArrayajaxminimalspinnersES2019includessomenegative zerorules6to5hotinstallerutilsjoiloadbalancingtrimLeftramdareact poseES3jsoncallbackimportexportmulti-packageiterationfantasy-landtoStringTagbyteLengthefficient_.extendjson-schemaebscoresymbolslockfile.enva11ydragartfiltercoercibleintrinsicpathphonees-abstractcompile lessBigUint64ArrayObject.entrieslettypedarraystypeerrorroutefastifyArrayBufferargvquerybcryptserializeString.prototype.matchAllchaistatushas-ownstarterinternalsigintlink
3.9.85

12 months ago

3.9.84

12 months ago

3.8.84

12 months ago

3.8.83

12 months ago

3.8.82

12 months ago

3.8.81

1 year ago

3.8.80

1 year ago

3.7.80

1 year ago

3.7.79

1 year ago

3.7.78

1 year ago

3.7.77

1 year ago

3.6.77

1 year ago

3.6.76

1 year ago

3.6.75

1 year ago

3.6.74

1 year ago

3.6.73

1 year ago

3.6.72

1 year ago

3.6.71

1 year ago

3.6.70

1 year ago

3.6.69

1 year ago

3.6.68

1 year ago

3.6.67

1 year ago

3.6.66

1 year ago

3.6.65

1 year ago

3.6.64

1 year ago

3.6.63

1 year ago

3.6.62

1 year ago

3.6.61

1 year ago

3.6.60

1 year ago

3.5.60

1 year ago

3.5.59

1 year ago

3.5.58

1 year ago

3.5.57

1 year ago

3.5.56

1 year ago

3.5.55

1 year ago

3.5.54

1 year ago

3.5.53

1 year ago

3.5.52

1 year ago

3.5.51

1 year ago

3.5.50

1 year ago

3.5.49

1 year ago

3.5.48

1 year ago

3.5.47

1 year ago

3.5.46

1 year ago

3.5.45

1 year ago

3.5.44

1 year ago

3.5.43

1 year ago

3.5.42

1 year ago

3.5.41

1 year ago

3.5.40

1 year ago

3.5.39

1 year ago

3.5.38

1 year ago

3.5.37

1 year ago

3.5.36

1 year ago

3.5.35

1 year ago

3.5.34

1 year ago

3.5.33

1 year ago

3.5.32

1 year ago

3.4.32

1 year ago

3.4.31

1 year ago

3.4.30

1 year ago

3.4.29

1 year ago

3.4.28

1 year ago

3.4.27

1 year ago

3.4.26

1 year ago

3.4.25

1 year ago

3.4.24

1 year ago

3.4.23

1 year ago

2.4.23

1 year ago

2.3.23

1 year ago

2.3.22

1 year ago

2.3.21

1 year ago

2.3.20

1 year ago

2.3.19

1 year ago

2.3.18

1 year ago

2.3.17

1 year ago

2.2.17

1 year ago

2.2.16

1 year ago

2.2.15

1 year ago

2.2.14

1 year ago

2.2.13

1 year ago

2.2.12

1 year ago

2.2.11

1 year ago

2.2.10

1 year ago

2.2.9

1 year ago

1.2.9

1 year ago

1.2.8

1 year ago

1.2.7

1 year ago

1.1.7

1 year ago

1.1.6

1 year ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.3

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