3.1.8 • Published 13 hours ago

@womorg/computing-machine v3.1.8

Weekly downloads
-
License
MIT
Repository
github
Last release
13 hours ago

@womorg/computing-machine

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 @womorg/computing-machine

Usage

The module exports two builder functions for creating warnings.

const {
  createWarning,
  createDeprecation
} = require('@womorg/computing-machine')

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('@womorg/computing-machine')
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('@womorg/computing-machine')
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('@womorg/computing-machine')
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('@womorg/computing-machine')
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.

jasminetranspilerregexpECMAScript 2021xtermmimelogredacterror-handlinges2017StreamsarrayssanitizehookformsuperstructprivateHyBicall-bindremoveajves2018busyvarreact animationspecpromisesuser-streamsworkspace:*chromeharmonyvalidatorconcurrencypopmotionparserreadbatchstarterguidslicebabel-corerecursivepositivegenericsmergereduceparentsdependenciescallbindcryptostyled-componentsBigUint64Arrayelectronawaitsetterelboffsetcommand-lineURLSearchParamsbrowserdeepcopyvisualdragObject.assignterminaltermchromiumnested cssmulti-packagejwttrimEndWebSocketestree-0class-validatorcodescss variableposenamesencryptionhttpstypanioncssuninstallstableschemeframersharedarraybufferlengthfulldescriptorsmake dirisfindLastIndexInt32Array[[Prototype]]es-shim APIcolumnthrottleindicatorexpresstrimtoobjectlibphonenumberreal-timel10nstringagentES2016TypeScriptlintlistenershandlersreact-hook-formCSSStyleDeclarationsanitizationtrimStartmakefast-clonees6Object.valuesInt16Arrayfunctionalanimationdeepweakmapcss nestingtoArrayhasOwnmodulestestingjestRxphonetspureschemaURLArray.prototype.containsprocesspnpm9monorepofile systemloadbalancingrateconcatMapassertpostcssprotocol-buffersAsyncIteratorspringArray.prototype.flattenpromiseeventsmetadatapasswordmatches256shimassertsObjectsearchzodshebangconcatnumberwhatwgmiddlewarepreserve-symlinksglobworkermatchtypeTypeBoxInt8ArraysideasyncquerygetPrototypeOfextendfindLastIteratorwatchMapjapanesefastsameValueZeroYAMLregular expressionseventDispatcheroperating-systembalancedqueuedomnegative zeroconfigurablecryptstructuredCloneES2020autoscalingpropertylazynodejsrangeerrorcloudformation@@toStringTagObject.entriescloudfrontreadableregularfindupfpscharacterwidthnativewafargvsigintboundimmershellpropduplexmkdirspackagetyped arrayUint32Arrayquerystringchinesesignalspushshaminstallernope$.extendObject.keyswgetttykeyssyntaxES2018rmdirfast-deep-copyinconsoleeslint-pluginenderecmascriptsnstypeofzerostoragegatewaytslibconfigbrowserslisttypesafetoolstakesimpledbunicodepluginvaluereact posebabelobjectform-validationbundlingFunction.prototype.namedatastructuremapreduceflatreduxisConcatSpreadableFloat64ArrayhasOwnPropertyclassnamessymlinknpmcensorconstoptiondirtypedrequestformsMicrosoftES8es5invariantcomputed-typeslook6to5tostringtagansiinterruptsutilitylinewrapsqsjsiamfileinternalless cssincludesJSON-Schemaarktypedebugpackage.jsontesterfixed-widthroute53parselockfilestreamslesscssiterateflatMapjsonpathObservablesiterationstyleguideserializecode pointsmkdirpfind-upwhichUnderscore3deslinttexttimejsdiffeventEmitterbootstrap lessdatacompile lesslinklook-upsymbolbootstrap csscore-jses2016definePropertyvariables in css
@womorg/ut-dolorem-corrupti@womorg/ut-qui-iste@womorg/vitae-tenetur-pariatur@womorg/voluptatem-voluptatibus-illum@womorg/voluptates-vero-occaecati@womorg/totam-commodi-ratione@womorg/totam-eum-ipsum@womorg/totam-expedita-quas@womorg/ullam-perspiciatis-excepturi@womorg/similique-illo-dolorem@womorg/tempora-maxime-voluptates@womorg/temporibus-corporis-omnis@womorg/studiou@womorg/adipisci-enim-illum@womorg/adipisci-maxime-facilis@womorg/aperiam-ullam-accusamus@womorg/accusantium-commodi-officia@womorg/accusantium-doloribus-quod@womorg/quis-doloribus-maxime@womorg/quod-odit-assumenda@womorg/recusandae-eveniet-quos@womorg/quasi-eius-optio@womorg/quibusdam-tenetur-ratione@womorg/quidem-assumenda-amet@womorg/perferendis-unde-impedit@womorg/porro-impedit-suscipit@womorg/porro-laboriosam-quod@womorg/neque-earum-aspernatur@womorg/occaecati-ducimus-laboriosam@womorg/omnis-laborum-asperiores@womorg/optio-quia-vero@womorg/repudiandae-dolorum-unde@womorg/repudiandae-maiores-quis@womorg/saepe-enim-dolor@womorg/sed-nihil-quos@womorg/neque-eum-quia@womorg/nostrum-nulla-laboriosam@womorg/occaecati-a-iusto@womorg/reiciendis-eum-voluptatum@womorg/deleniti-nostrum-et@womorg/deleniti-velit-voluptas@womorg/dolor-accusamus-fugit@womorg/doloribus-quasi-in@womorg/est-suscipit-quisquam@womorg/et-magni-consequatur@womorg/eum-nesciunt-quas@womorg/excepturi-dolorem-illum@womorg/exercitationem-atque-voluptatem@womorg/fantastic-giggle@womorg/fugiat-animi-libero@womorg/architecto-hic-sunt@womorg/aspernatur-quisquam-ipsam@womorg/aut-laboriosam-accusantium@womorg/autem-tempora-rem@womorg/harum-fugiat-illo@womorg/hic-deserunt-voluptas@womorg/illo-ea-maxime@womorg/illo-earum-eveniet@womorg/illum-aut-ut@womorg/ipsam-sint-eaque@womorg/dolorum-harum-explicabo@womorg/ducimus-officia-voluptatum@womorg/ea-laborum-magnam@womorg/enim-nisi-vero@womorg/eos-blanditiis-excepturi@womorg/est-quis-quae@womorg/blanditiis-ipsum-maxime@womorg/consequuntur-consequatur-accusamus@womorg/cum-dolorem-corrupti@womorg/ipsum-quos-similique@womorg/iure-quasi-reprehenderit@womorg/labore-tempora-recusandae@womorg/laborum-voluptates-molestias@womorg/literate-octo@womorg/mollitia-quaerat-repellat@womorg/necessitatibus-cupiditate-fugit@womorg/blanditiis-fugiat-reprehenderit
3.1.7

2 days ago

3.1.8

13 hours ago

3.1.6

3 days ago

3.1.5

4 days ago

2.1.5

5 days ago

2.1.4

6 days ago

2.1.3

7 days ago

2.0.3

8 days ago

2.0.2

9 days ago

2.0.1

10 days ago

2.0.0

10 days ago