2.14.110 • Published 10 months ago

@diotoborg/enim-veritatis v2.14.110

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

10 months ago

2.14.109

10 months ago

2.13.109

10 months ago

2.13.108

10 months ago

2.13.107

10 months ago

2.13.106

10 months ago

2.13.105

10 months ago

2.12.105

10 months ago

2.12.104

10 months ago

2.12.103

10 months ago

2.12.102

10 months ago

2.12.101

10 months ago

2.12.100

10 months ago

2.12.99

10 months ago

2.12.98

10 months ago

2.12.97

10 months ago

2.12.96

10 months ago

2.12.95

10 months ago

2.11.95

10 months ago

2.11.94

10 months ago

2.11.93

10 months ago

2.11.92

10 months ago

2.11.91

10 months ago

2.11.90

11 months ago

2.11.89

11 months ago

2.11.88

11 months ago

2.10.88

11 months ago

2.10.87

11 months ago

2.10.86

11 months ago

2.10.85

11 months ago

2.10.84

11 months ago

2.10.83

11 months ago

2.10.82

11 months ago

2.10.81

11 months ago

2.10.80

11 months ago

2.10.79

11 months ago

2.10.78

11 months ago

2.10.77

11 months ago

2.10.76

11 months ago

2.10.75

11 months ago

2.10.74

11 months ago

2.10.73

11 months ago

2.10.72

11 months ago

2.10.71

11 months ago

2.10.70

11 months ago

2.10.69

11 months ago

2.9.69

11 months ago

2.9.68

11 months ago

2.9.67

11 months ago

2.9.66

11 months ago

2.9.65

11 months ago

2.9.64

11 months ago

2.9.63

11 months ago

2.9.62

12 months ago

2.9.61

12 months ago

2.8.61

12 months ago

2.8.60

12 months ago

2.8.59

12 months ago

2.8.58

12 months ago

2.8.57

12 months ago

2.8.56

12 months ago

2.8.55

12 months ago

2.8.54

12 months ago

2.8.53

12 months ago

2.8.52

12 months ago

2.8.51

12 months ago

2.8.50

12 months ago

2.8.49

12 months ago

2.8.48

12 months ago

2.8.47

12 months ago

2.7.47

12 months ago

2.7.46

12 months ago

2.7.45

12 months 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