2.14.110 • Published 2 years ago

@diotoborg/enim-veritatis v2.14.110

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years 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

2 years ago

2.14.109

2 years ago

2.13.109

2 years ago

2.13.108

2 years ago

2.13.107

2 years ago

2.13.106

2 years ago

2.13.105

2 years ago

2.12.105

2 years ago

2.12.104

2 years ago

2.12.103

2 years ago

2.12.102

2 years ago

2.12.101

2 years ago

2.12.100

2 years ago

2.12.99

2 years ago

2.12.98

2 years ago

2.12.97

2 years ago

2.12.96

2 years ago

2.12.95

2 years ago

2.11.95

2 years ago

2.11.94

2 years ago

2.11.93

2 years ago

2.11.92

2 years ago

2.11.91

2 years ago

2.11.90

2 years ago

2.11.89

2 years ago

2.11.88

2 years ago

2.10.88

2 years ago

2.10.87

2 years ago

2.10.86

2 years ago

2.10.85

2 years ago

2.10.84

2 years ago

2.10.83

2 years ago

2.10.82

2 years ago

2.10.81

2 years ago

2.10.80

2 years ago

2.10.79

2 years ago

2.10.78

2 years ago

2.10.77

2 years ago

2.10.76

2 years ago

2.10.75

2 years ago

2.10.74

2 years ago

2.10.73

2 years ago

2.10.72

2 years ago

2.10.71

2 years ago

2.10.70

2 years ago

2.10.69

2 years ago

2.9.69

2 years ago

2.9.68

2 years ago

2.9.67

2 years ago

2.9.66

2 years ago

2.9.65

2 years ago

2.9.64

2 years ago

2.9.63

2 years ago

2.9.62

2 years ago

2.9.61

2 years ago

2.8.61

2 years ago

2.8.60

2 years ago

2.8.59

2 years ago

2.8.58

2 years ago

2.8.57

2 years ago

2.8.56

2 years ago

2.8.55

2 years ago

2.8.54

2 years ago

2.8.53

2 years ago

2.8.52

2 years ago

2.8.51

2 years ago

2.8.50

2 years ago

2.8.49

2 years ago

2.8.48

2 years ago

2.8.47

2 years ago

2.7.47

2 years ago

2.7.46

2 years ago

2.7.45

2 years ago

2.7.44

2 years ago

2.6.44

2 years ago

2.6.43

2 years ago

2.6.42

2 years ago

2.6.41

2 years ago

2.6.40

2 years ago

2.6.39

2 years ago

2.6.38

2 years ago

2.6.37

2 years ago

2.6.36

2 years ago

2.6.35

2 years ago

2.6.34

2 years ago

2.6.33

2 years ago

2.6.32

2 years ago

2.6.31

2 years ago

2.6.30

2 years ago

2.6.29

2 years ago

2.6.28

2 years ago

2.5.28

2 years ago

2.5.27

2 years ago

2.5.26

2 years ago

2.5.25

2 years ago

2.5.24

2 years ago

1.5.24

2 years ago

1.4.24

2 years ago

1.4.23

2 years ago

1.3.23

2 years ago

1.3.22

2 years ago

1.3.21

2 years ago

1.3.20

2 years ago

1.2.20

2 years ago

1.2.19

2 years ago

1.2.18

2 years ago

1.2.17

2 years ago

1.2.16

2 years ago

1.2.15

2 years ago

1.2.14

2 years ago

1.2.13

2 years ago

1.1.13

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago