2.1.14 • Published 1 year ago

@dramaorg/debitis-quis v2.1.14

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

@dramaorg/debitis-quis

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 @dramaorg/debitis-quis

Usage

The module exports two builder functions for creating warnings.

const {
  createWarning,
  createDeprecation
} = require('@dramaorg/debitis-quis')

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('@dramaorg/debitis-quis')
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('@dramaorg/debitis-quis')
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('@dramaorg/debitis-quis')
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('@dramaorg/debitis-quis')
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.

flagclassnamesrestfulcurlhelperstoArrayvalidatepropertyyuptestcss-in-jsarrayspipesliceemrcoerciblefilephoneFunction.prototype.nameformUnderscorecloudtrailexecfileglobscheme-validationtddhookformpathreadJSONarraybuffersubprocessdefinerequireqsindicatorcallboundconcattypeofpopmotionregular expressionkinesistypanionsyntaxcloudformationtsESnextasterisksredux-toolkittoolkitglobal objectflatfastcopyECMAScript 5writableinstallerentriesgetPrototypeOfregularES8swfgroupInt32ArraytypeanimationRegExp#flagssinatraReactiveExtensionsfolderObservablesJSON-Schemaenderiamfastclonetypeerrorrmdragfantasy-landnamecallbindgetintrinsicmatchAllES2021shebangpnpm9istanbulroutingpushawsYAMLfigletdirectorydotenvvarsBigUint64ArraymodulesoptimistschemaawesomesauceecmascriptArraydynamodbforEachfast-copy256selfdeepclone3dsymlinksdependency managerlibphonenumberglobal this valuereact poseguidmanagerstoragegatewayRegExp.prototype.flagsmakereduxtapECMAScript 2019webcolumnsurltoSortedes-shim APItrimStarttc39hasOwnsidecollection.es6consolecloneArray.prototype.filteres2018ttysomewhichspinnerremovecurriedmodulefromfunction.lengthparentsfshttpdeep-clonebundlerinternal slotrestES2018findLastReflect.getPrototypeOfmapstreamskeyrssprefixfunctionalnodeECMAScript 2016Object.assigncore-jsponyfillform-validationowngetopttoReversedtypedarrayCSSeventDispatcherassertssetImmediateoffsetString.prototype.matchAllenvironmentsassignwaapiframeworkoptionidthreeflattenArray.prototype.flattenrecursiveintrinsiceffect-tsimportarktypecryptofullstylevalidationutilitiesjestelbquoteargv6to5npmjsdifftranspileforkcloudfrontfunctionskeyshasTypeBox.gitignoreobjecttapeObject.entriesWebSocketidentifierssuperagentgraphqluser-streamsutil.inspectgetestestingcreateappwafargsshrinkwrapeslinttranspilerfiltercopyWeakSetArray.prototype.flatMaptypesafesameValueZerounicodecallbackes-abstractyamlroutergetterstarteromitsharedasyncinspectautoscalingtrimjsdomprivate datanegative zeroRxRxJSprocessloggerchromeeveryrm -rfFloat64Arrayextendrfc4122termzerorandomsqstyped arraya11yObservableprototypestyleguideserializerObject.valuespyyamlexecfull-widthtoolsStyleSheetinternalregular-expressionxmlsortcall-boundcall-bindsettingsES6typeds3warningUint8Arraycommand-linebufferslinkshimcloudsearch@@toStringTagECMAScript 2015cjkECMAScript 2021ES2023es2015make dirPushStreaminputefficientloadbalancingnegativeproplookdataviewwaitextraArray.prototype.flatwidthloading.envdayjses5artqueryredirectregexsymbolcoverageregular expressionsconstpostcssaccessorFloat32ArraygroupByfind-upconfigurablemoveshammatchesclass-validatorclientvariableses8koreantraversejoiArray.prototype.containstransformdomstringifyECMAScript 2022reactdeleteECMAScript 6weaksetterminalES2019mkdirmruequalcharacterrangeerrortrimEndvaluereact-hook-formbabelBigInt64ArrayArray.prototype.findLastrgbtrimLeftmkdirssuperstructebstostringtag__proto__Map-0expresstacitObject.getPrototypeOflanguagedefinePropertyvpcexpressionjson-schema-validationSymbol.toStringTagworkspace:*higher-orderreadableregexpimportexporthashMicrosoftfetchstreamatomqueuecloudwatchIteratorsortedlintjshintECMAScriptoncedataagentInt8ArraytransportutilsroutegdprignorehelperflagsbyteOffsetminimalelasticacheestreestyleshttpsenvES2020ajvflatMapenvironmentnativestructuredCloneassertionsetteransijson-schema-validatorReactiveXsimpledbispackagessafefasttypescriptObject.keysrulesemojilengthglacierrequestbytebinariesreducees-shimsArrayBufferbinspecjson-schemaUint8ClampedArrayECMAScript 2017prettyprotobufpostcss-pluginreversefast-cloneUint16ArrayObjectcodespatchinstrumentationtoStringTagES2022optimizerlocationlook-upreversedprotoassertdom-testing-library[[Prototype]]Symbolmanipulationuninstallsymbolsbrowserlistmulti-packagebeanstalkbrowserfeedArrayBuffer.prototype.slicehardlinksworkflowUint32ArrayjsonschemaproxyjsondropjsshellslotvaluespinocompilerserializeES2017formattingPromisecheckgenericsfindapivestramdareducerrapidairbnbdescriptiones7styled-componentscollectionzodspawnparseeslintconfigtoobjectargumentviewqueueMicrotaskmergesetPrototypeOfframerpackageTypeScriptfullwidthwalkingmomentWeakMapmochaincludespicomatchreact-hooksparentArrayBuffer#slicepreprocessorinferenceRFC-6455log0telephonecolorsECMAScript 7snsECMAScript 3arrayTypedArrayObject.definePropertytrimRightECMAScript 2023Object.isSystem.globalsource mapECMAScript 2018stringifieriefast-deep-copychaiajaxstringcorechildconfigcolourcensorvalidatormkdirpfast-deep-clonesetboundformatlastcommanderURLlistenersdeterministicrm -frdebuggerequalityrobustelectroncomparestylingbannerwalkhas-ownemitharmonyinlrucommanddiffprogressruntimeresolvermdirpackage.jsonnodejsjsxmobilehasOwnPropertycode pointsacornchannelreuseenumerableWebSocketsdeepcopyspringformsfile systemupperformantpackage managerweakmapURLSearchParamsjavascriptcharacterssearchsyntaxerrordateavaoutputbinaryreact-testing-libraryECMAScript 2020tslibidleespreegetOwnPropertyDescriptoreventsglobalsdeep$.extendi18nerroreventEmitterxhrroute53functionObject.fromEntriesiteratebusyES2016amazoneast-asian-widthES3htmlcolumnclassespoint-freereal-timemetadataio-tschromiumprivatecontainsspinnersastec2es6findupbindfindLastIndexfixed-widthpluginglobalfnmatchtakewriteHyBiposequerystringimmutableutilparserCSSStyleDeclarationES5byteLengthes2017dataVieweslint-pluginstablewindowglobalThisescapevarl10nexecuteutilityjQuerydires2016concatMaprdspurebufferschemeserializationreact animationcallaccessibilityasciiprotocol-buffersSetString.prototype.trimArray.prototype.findLastIndexredactpromisepolyfilltouchimmertypedarraysfpslocalnpmignorejapanese_.extendES7karmadeep-copytesterconsumeautoprefixerESwgetAsyncIteratorfpinvariantStreamscolorxtermapollonumbercirculariteratorbundlingisConcatSpreadablegesturesbddclassnameperformancepropertiesfastifyvalidzxArray.prototype.includesdependenciesendpointInt16Arrayhooksreadablestreamloggingchinesepositivereworkcliwhatwgbabel-corenamesgitignoreES2015
2.1.14

1 year ago

2.1.13

1 year ago

2.1.12

1 year ago

2.1.11

1 year ago

2.1.10

1 year ago

2.1.9

1 year ago

2.1.8

1 year ago

2.1.7

1 year ago

2.1.6

1 year ago

2.0.6

1 year ago

2.0.5

1 year ago

2.0.4

1 year ago

2.0.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