2.14.110 • Published 12 months ago

@diotoborg/enim-veritatis v2.14.110

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

@diotoborg/enim-veritatis šŸ”¬šŸ’„

GitHub Actions Workflow Status types npm bundle size NPM Downloads

@diotoborg/enim-veritatis is a tiny, widely-supported, zero-dependency alternative to invariant.

@diotoborg/enim-veritatis - 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 '@diotoborg/enim-veritatis';

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

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

Why @diotoborg/enim-veritatis?

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. @diotoborg/enim-veritatis 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

@diotoborg/enim-veritatis 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 '@diotoborg/enim-veritatis';

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

@diotoborg/enim-veritatis 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 @diotoborg/enim-veritatis

# npm
npm install @diotoborg/enim-veritatis --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!

🤘

es2016EShookformmatchesbannerECMAScript 2017package.jsonmochaflagsjsdomtoolkittrimPushECMAScript 2019hasmetadatainstrumentationeslintconfiglook-uppatchsyntaxfigletObjecttoReversedeslintpluginArray.prototype.includeseventsdependenciesutilitiesslottypeofponyfillbindSymbolindicatorappdategdprfullclassnameseast-asian-widthgroupsettingsexectimefromStyleSheet.gitignoresharedarraybuffercallxmlArrayBuffernativesymbolsrequestawesomesauceamazonelectronttybundlertransformjoiexecfilewaitprefixkoreanlookescapedropes-shim APItextwafidlespawnwgetextendloadbalancingfunctionaltrimRightmakeimportexportreact poseajaxdayjsgetPrototypeOffast-deep-clonestablespinnerszerohtmltypescloudformationwidthtypedarraysfindupconfigfeedcall-bindreduceriteratorglobalThisECMAScript 2018simpledbcjkcodescharacterowndotenvimmertacitfastifytypesafejavascriptramdaexpresscheckemroffsetfast-clonenegativecloudfrontxhrcallboundcommandmonorepoeventEmitterconcatECMAScript 2021computed-typeskinesisjasmineframeworkzxrsshttpcachecolumnstranspilepushUint32ArrayworkerformsecmascriptRFC-6455equalECMAScript 7pluginoptimizerFloat32Arraytypanionreact-testing-librarytypedstyled-componentsswfagentelasticachehelpertoArrayFunction.prototype.nameglobal objectsuperagentpositivesnscommandergetInt8Arrayboundapollo3drapidfs6to5writegraphqlpopmotionsideintrinsicbeanstalkqueryhigher-orderespreestoragegatewayES5deepcopyparentsqueueMicrotaskprogresscurriedclass-validatorcolorloggingchairouteECMAScript 2016util.inspectonceharmonytypedarrayIteratorpruneArray.prototype.findLastArray.prototype.flatunicodeinmergetoStringTagrm -frrandomfunction.lengthhooksentriesgesturesregular expressionES8rfc4122shrinkwrapAsyncIteratorcollection.es6enumerabletrimEndbabel-coreerrorforEachtakefetchtapeeslintresolveArrayBuffer#slicefantasy-landideventDispatcherpreprocessorregexpReactiveExtensionsfpsprototypejseveryfunctionisimmutableRegExp.prototype.flagsphonechinesetelephoneString.prototype.trimmanipulationelbjestcensorjapanesecolourjson-schema-validatorminimalutilbddMapkeyselfcompilerlinklistenersexpressionproxyjson-schema-validationgenericstestingdefinecharactersguidform-validationArray.prototype.findLastIndexprotomodulelibphonenumberpropertyasterisksconsoleframergetOwnPropertyDescriptorairbnbECMAScript 2022jsonchromiumdebuggertrimStartutilswindowviewfnmatchreadRxJSspeedBigInt64Arraylengthmake dirinternallruimportspinnerpolyfillstylingECMAScript 2020valuepipepostcssupgitignore__proto__ES2019qsflattrimLeftFloat64Arrayvalidatevalidatorvalidationtypeapistringifierprivate datalastthreeparseiterateprivatesafesearchECMAScript 3autoprefixerbusycurli18nvarsWebSocketES2023walkanimationfast-copyMicrosoftES2018delete_.extendregularidentifierssuperstructweakmapajvsesbinaryObject.getPrototypeOfterminallocaldom-testing-librarykeysregexserializeprocesssetterWeakMapassertJSON-SchematypescriptletreversedstylesES2016ES3tc39numberemitsliceassertsvaluespropertiesinstallerdirectoryESnexteslint-pluginsymbolbufferqueueredactio-tswritableredirectCSSloadingmkdirstostringtagglobalmkdirmapvalidaccessibilityStreamexecutetsjQuerya11yBigUint64Arrayarktypecallbackfastcloneperformanceuninstalll10nReactiveXes2017browsernpmignoreglacierregular expressionsasyncinputtesterfunctionsfastcopyrobustcontainsoptionbyteOffsethasOwnPropertyUint16ArraydirsortedRegExp#flagslockfilejsdiffec2redux-toolkitObject.fromEntriessource mapwhichES2021reactnopechromequerystringObservablesfile systemforkRxmomentcore-jsUint8ClampedArraycolorsfind-uprulesroute53WebSocketsnodePromiseobjectES7invariantpropargumentawsxtermInt32Arrayistanbulartjsxes5Array.prototype.flattenmapreduceconsumeconcatMapURLrequireformattinghardlinksmobiledataviewreact-hook-formsubprocessparentTypedArrayWeakSetObject.definePropertystringObject.valuespostcss-pluginkarmaArray.prototype.flatMaproutingshamrestArrayBuffer.prototype.slicereverseincludesjsonschemacloudwatchUnderscoreES2020compareprotocol-buffersTypeScriptECMAScript 5ignoredependency managerwarninglogflattenvariablescollectionposees7256matchAllefficientschemaes8-0Object.isyuplintparserspringbundlingdynamodbstreams[[Prototype]]user-streamswaapidomendpointperformantserializationzodbindescriptorswebes2018classesnpmECMAScriptvartypeerrorstyleguideavaJSONacornobjebsconfigurablereduxtranspilerdescriptorsetPrototypeOfhas-ownSystem.globalCSSStyleDeclarationenvsetomit
2.14.110

12 months ago

2.14.109

12 months ago

2.13.109

12 months ago

2.13.108

12 months ago

2.13.107

12 months ago

2.13.106

1 year ago

2.13.105

1 year ago

2.12.105

1 year ago

2.12.104

1 year ago

2.12.103

1 year ago

2.12.102

1 year ago

2.12.101

1 year ago

2.12.100

1 year ago

2.12.99

1 year ago

2.12.98

1 year ago

2.12.97

1 year ago

2.12.96

1 year ago

2.12.95

1 year ago

2.11.95

1 year ago

2.11.94

1 year ago

2.11.93

1 year ago

2.11.92

1 year ago

2.11.91

1 year ago

2.11.90

1 year ago

2.11.89

1 year ago

2.11.88

1 year ago

2.10.88

1 year ago

2.10.87

1 year ago

2.10.86

1 year ago

2.10.85

1 year ago

2.10.84

1 year ago

2.10.83

1 year ago

2.10.82

1 year ago

2.10.81

1 year ago

2.10.80

1 year ago

2.10.79

1 year ago

2.10.78

1 year ago

2.10.77

1 year ago

2.10.76

1 year ago

2.10.75

1 year ago

2.10.74

1 year ago

2.10.73

1 year ago

2.10.72

1 year ago

2.10.71

1 year ago

2.10.70

1 year ago

2.10.69

1 year ago

2.9.69

1 year ago

2.9.68

1 year ago

2.9.67

1 year ago

2.9.66

1 year ago

2.9.65

1 year ago

2.9.64

1 year ago

2.9.63

1 year ago

2.9.62

1 year ago

2.9.61

1 year ago

2.8.61

1 year ago

2.8.60

1 year ago

2.8.59

1 year ago

2.8.58

1 year ago

2.8.57

1 year ago

2.8.56

1 year ago

2.8.55

1 year ago

2.8.54

1 year ago

2.8.53

1 year ago

2.8.52

1 year ago

2.8.51

1 year ago

2.8.50

1 year ago

2.8.49

1 year ago

2.8.48

1 year ago

2.8.47

1 year ago

2.7.47

1 year ago

2.7.46

1 year ago

2.7.45

1 year ago

2.7.44

1 year ago

2.6.44

1 year ago

2.6.43

1 year ago

2.6.42

1 year ago

2.6.41

1 year ago

2.6.40

1 year ago

2.6.39

1 year ago

2.6.38

1 year ago

2.6.37

1 year ago

2.6.36

1 year ago

2.6.35

1 year ago

2.6.34

1 year ago

2.6.33

1 year ago

2.6.32

1 year ago

2.6.31

1 year ago

2.6.30

1 year ago

2.6.29

1 year ago

2.6.28

1 year ago

2.5.28

1 year ago

2.5.27

1 year ago

2.5.26

1 year ago

2.5.25

1 year ago

2.5.24

1 year ago

1.5.24

1 year ago

1.4.24

1 year ago

1.4.23

1 year ago

1.3.23

1 year ago

1.3.22

1 year ago

1.3.21

1 year ago

1.3.20

1 year ago

1.2.20

1 year ago

1.2.19

1 year ago

1.2.18

1 year ago

1.2.17

1 year ago

1.2.16

1 year ago

1.2.15

1 year ago

1.2.14

1 year ago

1.2.13

1 year ago

1.1.13

1 year ago

1.0.13

1 year ago

1.0.12

1 year ago

1.0.11

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