4.13.78 • Published 1 year ago

@taktikorg/quae-dolorem-eum v4.13.78

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

@taktikorg/quae-dolorem-eum šŸ”¬šŸ’„

GitHub Actions Workflow Status types npm bundle size NPM Downloads

@taktikorg/quae-dolorem-eum is a tiny, widely-supported, zero-dependency alternative to invariant.

@taktikorg/quae-dolorem-eum - when every byte counts!

What is invariant?

An invariant function takes a value, and if the value is falsy then the invariant function will throw. If the value is truthy, then the function will not throw.

import invariant from '@taktikorg/quae-dolorem-eum';

invariant(truthyValue, 'This should not throw!');

invariant(falsyValue, 'This will throw!');
// Error('Invariant violation: This will throw!');

Why @taktikorg/quae-dolorem-eum?

The library: invariant supports passing in arguments to the invariant function in a sprintf style (condition, format, a, b, c, d, e, f). It has internal logic to execute the sprintf substitutions. The sprintf logic is not removed in production builds. @taktikorg/quae-dolorem-eum has dropped all of the code for sprintf logic and instead encourages consumers to leverage template literals for message formatting.

invariant(condition, `Hello, ${name} - how are you today?`);

Error Messages

@taktikorg/quae-dolorem-eum allows you to pass a string message, or a function that returns a string message. Using a function that returns a message is helpful when your message is expensive to create.

import invariant from '@taktikorg/quae-dolorem-eum';

invariant(condition, `Hello, ${name} - how are you today?`);

// Using a function is helpful when your message is expensive
invariant(value, () => getExpensiveMessage());

When process.env.NODE_ENV is set to production, the message will be replaced with the generic message Invariant failed.

Type narrowing

@taktikorg/quae-dolorem-eum is useful for correctly narrowing types for flow and typescript

const value: Person | null = { name: 'Alex' }; // type of value == 'Person | null'
invariant(value, 'Expected value to be a person');
// type of value has been narrowed to 'Person'

API: (condition: any, message?: string | (() => string)) => void

  • condition is required and can be anything
  • message optional string or a function that returns a string (() => string)

Installation

# yarn
yarn add @taktikorg/quae-dolorem-eum

# npm
npm install @taktikorg/quae-dolorem-eum --save

Dropping your message for kb savings!

Big idea: you will want your compiler to convert this code:

invariant(condition, 'My cool message that takes up a lot of kbs');

Into this:

if (!condition) {
  if ('production' !== process.env.NODE_ENV) {
    invariant(false, 'My cool message that takes up a lot of kbs');
  } else {
    invariant(false);
  }
}

Your bundler can then drop the code in the "production" !== process.env.NODE_ENV block for your production builds to end up with this:

if (!condition) {
  invariant(false);
}

Builds

  • We have a es (EcmaScript module) build
  • We have a cjs (CommonJS) build
  • We have a umd (Universal module definition) build in case you needed it

We expect process.env.NODE_ENV to be available at module compilation. We cache this value

That's it!

🤘

createinstallcss-in-jspostcss-plugines2018__proto__deterministicglobal this valueES2022hasOwnscheme-validationcsspatchebsvisualsafecodesindicatorcensorcallbackglobalssignalruntimegraphqlObject.getPrototypeOftrimEndtermfile systemUint32ArrayRxhasdirectoryES5immeroptioneslintpluginargves2015Symbol.toStringTagjsdomreact-testing-librarycertificatescollection.es6Array.prototype.flatBigInt64ArrayReflect.getPrototypeOfReactiveXtrimRightoperating-systemtypedarraybyteOffsetlazy3dreactpopmotionfpcryptoMaputilsmoduleshebanges2017stylequeryfull-widthsimpledbString.prototype.trimdatastructurefluxreact-componentECMAScript 2019channellogexecsyntaxerrorstreamjavascriptfilterES2016toSortedrangeerrorquerystringrandom[[Prototype]]lrupackage manager$.extendtsrapidRFC-6455json-schema-validatorcall-bindprotobufglaciersortedES2021ECMAScript 6react posepushsetcompareArray.prototype.filterstatelesspasswordimportexportoptimist.gitignoreframerECMAScript 2017sigtermes-shimscommand-linefixed-widtherror-handlinggroupByeslintmergeArray.prototype.flattenelmregular-expressionmkdirmatchvalidationbrowserlistlogginggradients cssstarterincludesdatapnpm9superagentautoprefixerpackagesfastclonecompilermrugetintrinsicfullwidthrobustprocesstacitperformantdeepagentspinnertoobjectassertlocalsuperstructjson-schemaObservablesObservableclassnametostringtagrequiredescriptioncore-jsreversedbootstrap cssYAMLbcryptES2019stringexitgdprES2015symbolserializer6to5bytegitignorejson-schema-validationenvironmentassertsclass-validatorfilebusytransportrfc4122shellgetPrototypeOfECMAScript 2015elbObject.definePropertyworkflowclientwhichcoremapfshandlersstringifysharedhotObject.fromEntriestypescriptrequestnumberpipebinarieshashgestureslastCSSStyleDeclarationjsonschemaemitasciiECMAScript 7globinstallerspawnpurenpmignoreextraRegExp.prototype.flagsPromiseextendObject.assignJSON-Schemaminimalfunctionswhatwgtakeesjsdiffes2016URLbinarypromiseserializationiteratexhrstringifierchromebrowsermovewaapiarrayi18nmkdirpiefromforEachsigintflagspinnersqsnamesWebSocketdomES2020ajaxchromiumexecfilextermnpmeast-asian-widthtoolkitonceexecuteformsformatAsyncIteratorglobalThisiamtestRxJSinvariantdropfantasy-landArray.prototype.flatMapPushpostcssstylesheetrecursiveairbnbisConcatSpreadablemobilehttpiteratorTypeScripttypesafeuuidcloudfrontjshinttraverseoffsetworkspace:*binreplaytelephonefunctionregexsidesyntaxsomedescriptorsconsumeobjectl10nreducerclassesttyECMAScriptvalidatepreprocessorerrora11ywaitnopefast-deep-cloneexpressionsqshasOwnPropertywindowglobal objectterminaluser-streamsfunctionalopensslworkerawesomesaucestoragegatewaytddtranspilerdeleteES2017commanderslicesharedarraybuffer.envlink0ES3utilitylibphonenumberencryptionSetspeedzxremoveemramazonuploadlinttrimLeftwalksignedweaksetECMAScript 3nodejsenvStyleSheetowntoolsECMAScript 2022vpcsetPrototypeOflettimefast-copys3negative zerochaicomputed-typesless compilercryptdom-testing-librarycolorsECMAScript 2016resolveinternal slotliveintrinsicexit-codetrimFloat64Arrayconcathigher-orderqueueMicrotaskboundshimstyleguideIteratorcallredactdeep-cloneutilitiesprogressdataViewspringpolyfilltypesECMAScript 2023viewpreserve-symlinkseventEmittercloudsearchpluginargumentfast-clonemakejQueryless256css variablehelpersutil.inspectreact-hooksacornUnderscoreprotosymlinkswarningdescriptorstructuredClonedires-abstractprototypephoneshrinkwrapselfregular expressionpathparsinglistenerskeysinspectstreamsbrowserslistbootstrap lessasteriskshelper-0koreanfindInt32ArrayArray.prototype.findLasteslintconfiggetoptURLSearchParamsqueuestylingbabel-coreArrayBuffer.prototype.sliceimportyupforkjapanesejoienumerableformequalityastcloudformationassignmatchespyyamlnodedefinePropertyyamlWebSocketscolumnsStreamselectronObjectinputarraysregexpvaluegenericsprefixtouchzeroperformancesubprocessreverseflattenweakmapObject.entriesprettysameValueZeroECMAScript 2018writablecolumncss nestingio-tsSymbolenvironmentssignalsmatchAllparsepropertycommandconsoledategetOwnPropertyDescriptorvalidserializemetadatafindLastIndexefficientendertranspilepersistentmulti-packagebddquotetypedfunction.lengthiterationlockfileprotocol-bufferscurriedmixinsvaluesstyled-componentswritenegativepredictablemodulesObject.valuesdeep-copydiffrulescliescapepropreducees-shim APIdefinesetImmediateHyBiarktypeinterruptsloadingtypeerrorgroupInt16ArrayArrayBufferanimationawsirqdeepcopyless.jsroutelinuxtestingkinesiscircularclonemake dirvariables in cssbeanstalkESnextlanguagemonoreporeact animationasynclesscssfindLastuninstalltesterRegExp#flagsbundlingECMAScript 2021coercibledependenciestypanionstatusStreammanagerapies7globalsequenceexpresshardlinksequalvarsswf_.extendJSONformattingtypeArray.prototype.containscurlfetchES2023Int8Arrayhas-ownschemastatecompile lessUint8ClampedArraytoStringTag
4.13.78

1 year ago

4.13.77

1 year ago

4.13.76

1 year ago

4.12.76

1 year ago

4.12.75

1 year ago

4.12.74

1 year ago

4.11.74

1 year ago

4.11.73

1 year ago

4.10.73

1 year ago

4.10.72

1 year ago

4.10.71

1 year ago

4.10.70

1 year ago

4.10.69

1 year ago

4.10.68

1 year ago

4.10.67

1 year ago

4.10.66

1 year ago

4.10.65

1 year ago

4.10.64

1 year ago

4.10.63

1 year ago

4.10.62

1 year ago

4.10.61

1 year ago

3.10.61

1 year ago

3.10.60

1 year ago

3.10.59

1 year ago

3.10.58

1 year ago

3.10.57

1 year ago

3.10.56

1 year ago

3.10.55

1 year ago

3.10.54

1 year ago

3.10.53

1 year ago

3.10.52

1 year ago

3.10.51

1 year ago

3.10.50

1 year ago

3.10.49

1 year ago

3.10.48

1 year ago

3.10.47

1 year ago

3.10.46

1 year ago

3.10.45

1 year ago

3.10.44

1 year ago

3.10.43

1 year ago

3.10.42

1 year ago

3.10.41

1 year ago

3.10.40

1 year ago

3.10.39

1 year ago

3.10.38

1 year ago

3.10.37

1 year ago

3.10.36

1 year ago

3.10.35

1 year ago

3.10.34

1 year ago

3.10.33

1 year ago

3.10.32

1 year ago

3.10.31

1 year ago

3.9.31

1 year ago

3.9.30

1 year ago

3.9.29

1 year ago

3.8.29

1 year ago

3.7.29

1 year ago

3.7.28

1 year ago

3.7.27

1 year ago

3.7.26

1 year ago

3.6.26

1 year ago

3.6.25

1 year ago

3.6.24

1 year ago

2.6.24

1 year ago

2.6.23

1 year ago

2.6.22

1 year ago

2.6.21

1 year ago

2.6.20

1 year ago

2.6.19

1 year ago

2.6.18

1 year ago

2.6.17

1 year ago

1.6.17

1 year ago

1.6.16

1 year ago

1.6.15

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

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

1 year ago

1.1.7

1 year ago

1.1.6

1 year ago

1.1.5

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