4.11.114 • Published 10 months ago

@erboladaiorg/id-blanditiis-inventore v4.11.114

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

@erboladaiorg/id-blanditiis-inventore

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/id-blanditiis-inventore

Usage

The module exports two builder functions for creating warnings.

const {
  createWarning,
  createDeprecation
} = require('@erboladaiorg/id-blanditiis-inventore')

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/id-blanditiis-inventore')
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/id-blanditiis-inventore')
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/id-blanditiis-inventore')
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/id-blanditiis-inventore')
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.

@dramaorg/esse-praesentium-eligendi@dramaorg/quae-dolore-nostrum@erboladaiorg/ad-exercitationem-ducimus@erboladaiorg/adipisci-repellendus-corporis@erboladaiorg/asperiores-earum-quaerat@erboladaiorg/asperiores-fuga-sint@erboladaiorg/asperiores-nam-adipisci@erboladaiorg/autem-dolores-ipsam@erboladaiorg/cum-commodi-consequatur@erboladaiorg/cupiditate-consectetur-porro@erboladaiorg/cupiditate-pariatur-optio@erboladaiorg/distinctio-tempora-quis@erboladaiorg/error-atque-ea@erboladaiorg/esse-ipsa-numquam@erboladaiorg/ex-hic-molestias@erboladaiorg/explicabo-eius-adipisci@erboladaiorg/fugiat-nobis-repellendus@erboladaiorg/laboriosam-inventore-natus@erboladaiorg/molestiae-voluptatibus-perferendis@erboladaiorg/molestias-nulla-dolor@erboladaiorg/nisi-culpa-cum@erboladaiorg/officia-illum-aperiam@erboladaiorg/perspiciatis-magni-ut@erboladaiorg/quae-in-veniam@erboladaiorg/quaerat-mollitia-adipisci@erboladaiorg/quibusdam-itaque-tempora@erboladaiorg/quod-explicabo-neque@erboladaiorg/sint-deleniti-dolorem@erboladaiorg/sit-nesciunt-amet@erboladaiorg/tenetur-architecto-dolore@erboladaiorg/ut-dignissimos-laborum@erboladaiorg/velit-fugit-harum@juigorg/nisi-molestiae-ut@juigorg/sit-nam-neque@kollorg/dicta-itaque-nemo@kollorg/nihil-veniam-deserunt@swenkerorg/modi-dolorum-provident@swenkerorg/nulla-voluptates-voluptates@zitterorg/aspernatur-pariatur-occaecati@zitterorg/eum-veritatis-placeat@zitterorg/illum-perferendis-consecteturanalsorhost-simple-bscorcojs-qrcodecorcojs-qrcode-logodable-effectfiran-loggingsimple-assi-animationsimple-prompts-web3
4.9.102

11 months ago

4.9.103

11 months ago

4.9.104

11 months ago

4.9.105

11 months ago

4.9.106

11 months ago

2.2.55

1 year ago

2.2.53

1 year ago

2.2.54

1 year ago

2.8.100

11 months ago

4.10.108

11 months ago

3.9.101

11 months ago

3.9.102

11 months ago

4.10.106

11 months ago

4.10.107

11 months ago

2.7.77

12 months ago

4.11.114

10 months ago

2.7.79

12 months ago

2.7.78

12 months ago

4.11.112

11 months ago

2.7.80

12 months ago

4.11.113

11 months ago

4.11.110

11 months ago

4.11.111

11 months ago

2.5.60

1 year ago

2.7.84

12 months ago

2.7.83

12 months ago

2.7.82

12 months ago

2.7.81

12 months ago

2.9.100

11 months ago

2.1.27

1 year ago

2.9.101

11 months ago

2.1.28

1 year ago

2.1.25

1 year ago

2.1.26

1 year ago

2.1.23

1 year ago

2.1.24

1 year ago

2.1.21

1 year ago

2.1.22

1 year ago

4.11.109

11 months ago

2.7.88

12 months ago

2.5.65

1 year ago

2.7.87

12 months ago

2.5.66

1 year ago

2.7.86

12 months ago

4.11.108

11 months ago

2.7.85

12 months ago

2.5.61

1 year ago

2.5.62

1 year ago

2.5.63

1 year ago

2.7.89

12 months ago

2.5.64

1 year ago

2.7.91

11 months ago

2.7.90

11 months ago

2.7.95

11 months ago

2.7.94

11 months ago

2.7.93

11 months ago

2.7.92

11 months ago

2.1.29

1 year ago

2.1.38

1 year ago

2.1.39

1 year ago

2.1.36

1 year ago

2.1.37

1 year ago

2.1.34

1 year ago

2.3.56

1 year ago

2.1.35

1 year ago

2.1.32

1 year ago

2.1.33

1 year ago

2.7.99

11 months ago

2.1.30

1 year ago

2.7.98

11 months ago

2.1.31

1 year ago

2.7.97

11 months ago

2.3.55

1 year ago

2.7.96

11 months ago

2.1.49

1 year ago

2.7.100

11 months ago

2.1.47

1 year ago

2.1.48

1 year ago

2.1.45

1 year ago

2.1.46

1 year ago

2.1.43

1 year ago

2.1.44

1 year ago

2.1.41

1 year ago

2.1.42

1 year ago

2.1.40

1 year ago

2.6.66

1 year ago

2.1.52

1 year ago

2.6.67

1 year ago

2.1.53

1 year ago

2.6.68

1 year ago

2.1.50

1 year ago

2.6.69

1 year ago

2.1.51

1 year ago

2.6.70

1 year ago

2.6.71

12 months ago

2.6.72

12 months ago

2.0.15

1 year ago

2.0.16

1 year ago

2.4.58

1 year ago

2.4.57

1 year ago

2.4.59

1 year ago

2.6.77

12 months ago

2.4.56

1 year ago

2.6.73

12 months ago

2.6.74

12 months ago

2.6.75

12 months ago

2.6.76

12 months ago

2.0.19

1 year ago

2.0.17

1 year ago

2.0.18

1 year ago

2.0.20

1 year ago

2.0.21

1 year ago

2.4.60

1 year ago

2.0.14

1 year ago

2.0.13

1 year ago

2.0.12

1 year ago

1.0.11

1 year ago

1.0.12

1 year ago

1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

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