7.8.112 • Published 11 months ago

@devtea2026/nostrum-quae-debitis-eum v7.8.112

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

@devtea2026/nostrum-quae-debitis-eum šŸ”¬šŸ’„

GitHub Actions Workflow Status types npm bundle size NPM Downloads

@devtea2026/nostrum-quae-debitis-eum is a tiny, widely-supported, zero-dependency alternative to invariant.

@devtea2026/nostrum-quae-debitis-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 '@devtea2026/nostrum-quae-debitis-eum';

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

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

Why @devtea2026/nostrum-quae-debitis-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. @devtea2026/nostrum-quae-debitis-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

@devtea2026/nostrum-quae-debitis-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 '@devtea2026/nostrum-quae-debitis-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

@devtea2026/nostrum-quae-debitis-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 @devtea2026/nostrum-quae-debitis-eum

# npm
npm install @devtea2026/nostrum-quae-debitis-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!

🤘

Int16ArraywindowsESnextequalES7codesqueueMicrotaskgradients cssmime-dbcolumnsReflect.getPrototypeOfprivate dataprunestatelessprivatecall-boundconcatMapUint8ClampedArraycopykarmaloggertypesdatahookformirqlogdeepstyled-componentsArray.prototype.filteremojiArray.prototype.includesnamedebuggerfast-deep-clonetermglobalsshebangvariablesmacosspawnsqsmakehttpiteratoreslint-pluginECMAScript 2017speedECMAScript 3finda11ysetImmediateArray.prototype.findLastautoprefixerECMAScript 2022dayjsTypeBoxconcurrencyless.jssetfpsfullwidthSymbol.toStringTagexpressiontypedrobustpredictablestylesheetpnpm9hasprettyprotobufshamrestfullintyupform-validationfastwhichastfast-deep-copyvarsformcollection.es6rapidbannercommanddefinePropertyelburlunicodePushamazondependenciesprocesstoobjectpositiveexit-codeinterruptscode pointsmimetypesWebSocketenvelmes-shim APIparsingfull-widthUint16ArrayhotWebSocketscallbindhigher-orderautoscalingdatastructureRFC-6455workertraversestructuredClonemodulestypescriptfseventsperformancedebugES2023exitstableslotnodejsprogressECMAScript 2015consoleIteratorinspectES2018fluxhandlersstoragegatewayfunctionaldropecmascriptsharedec2warningcontainsMicrosoftES2021ES6idECMAScript 2018serializershrinkwrapcryptfullgroupCSSinternalrm -frlooksigtermartdom-testing-libraryajvdataViewSymbollockfileexeloadbalancingreadablestreameveryargscomparewhatwgcircularoutput256shellpolyfilllinkpatchInt32Arraymulti-packagees-abstractmkdirregexObject.getPrototypeOfStreamses5classesclassnamesprefixpropertiesnegative zeroPromisetesttoStringTageslintwatchingBigInt64ArrayhashbluebirdutilitiesenvironmentssuperstructrandomsigintbuffersobjECMAScript 2016serializationincludesfiltercorsvalueschromiumresolvecloudformationdataviewmergehas-ownfastcopyeventEmittertrimEndvestmobileappvalidationargvlinewrapsettingsispackageestreecachees7Object.entriesless compilerratelimitYAMLsortArrayBuffer#slicehelpersthrottleloggingArrayio-tsECMAScript 2021getteriterateindicator$.extendfigletexpresssetteropenerreduceobjectcss nestingsimpledbequalityregular expressionsnopelistenersclirm -rfexecObjectlimittestingxtermapipackagesschemevalidES2022util.inspectWeakMapquerystringwatchpromiselibphonenumberterminalpicomatchreadconfigkoreanArray.prototype.containsansiiamisConcatSpreadablematchAllArrayBuffer.prototype.slicesameValueZerorfc4122command-lineprotocol-buffersvisualoperating-systemauthreact-hooksObject.fromEntriescallspinnerlengthhooksmatchAsyncIteratorsymbolsURLSearchParamsnativeflats3.envdefinethroatinstallerfindupTypedArrayarktypedeterministicmkdirpfetchfunctionscall-bindweakmaptypedarrayshasOwnPropertybatchsafetrimavafindLastquoteparsestreams2phonebeanstalkcjksequenceglobaltestereditorrequirecssjsdomagentECMAScript 7httpsbcryptauthenticationinputinternal slotuuidmonorepocss-in-jszodwidthimportexportassertsUint8ArrayoncestyleguideproxywraphasOwnwgetjshintwatcherawsmodulecharacterjapanesedescriptorsbytewatchFileflagopenspostcss-plugines2017lruhardlinksfind-upcoretypeerrores-shimsinstallstringifycloudfrontReactiveExtensionsObject.isenvironmentjavascriptcheckxhrObject.assignspinnersvariables in cssttyWeakSetcolumnregexpesframeworkbootstrap cssimportstatusaccessorbddtypeoftelephoneless cssendpointduplexemitES2019css variable_.extenddeepclonelivecallboundes8byteLengthBigUint64Arrayreduxtostringtagoptionpathscheme-validationtslibES2017genericserrorponyfillasyncruntimeassertionObservableskeyserializeemrjQuerytrimLeftES2020sinatrapreprocessorparentglaciernodejsdiffelectron@@toStringTaggetPrototypeOfmovepackage managerwalkingl10nfile systemstringifierargumentsseswritableRxJSarraysECMAScript 2020chineseefficientsymlinkformattingcollectiondirectoryHyBiconsumeESfastifyeslintpluginbusyclass-validatorUint32Arraybundlermrugradients css3rdsinmochaschemaES3entriesarraylanguageflatMappackage.jsondiffdeep-copysliceexecutabledescriptorvalidateString.prototype.matchAllnameslastbufferpushchromeeventDispatcherless mixinsinferencekinesisStreamimmertrimRightfixed-widthbyteOffsetfromObject.definePropertyutiljoicss lessasciirouterArray.prototype.flatMapRegExp.prototype.flagslinuxintrinsicECMAScript 2023trimStartmatchesenderdomdeepcopydotenvtypedarraystylesaccessibilitymkdirsprotoarraybufferidentifiersMaplazytypanionsomecoercibleownreuserequestconnectECMAScript 5queuestylejsxfast-clonetypesafetoSortedmapfsvaluewritekeysArrayBufferbindpersistentescapeprototypedependency managerCSSStyleDeclarationclassnamefileqstextshimsetPrototypeOfArray.prototype.flatgetOwnPropertyDescriptorcompilerwebRxeast-asian-widthroute53regular expression__proto__rgbclonemetadataassertpluginRegExp#flagsstreamjsoptimizerreal-timeassigncolourchairmimmutablezerourlsxdgquerycryptolesscssweaksetsidejeststarterrmdirlaunchrangeerrortakedeletepropjsonpathremovewordbreakswfes2015Object.valuesflattencolorsymbol[[Prototype]]ajaxinvariantnegativetimei18nStyleSheetstatepyyamlforEachyamlpostcssviewcurltddes2016argumentObservable
7.8.112

11 months ago

7.8.111

11 months ago

6.8.111

11 months ago

6.8.110

11 months ago

6.7.110

11 months ago

6.7.109

11 months ago

6.7.108

11 months ago

6.7.107

11 months ago

5.4.73

12 months ago

4.3.53

1 year ago

4.3.52

1 year ago

4.3.51

1 year ago

4.3.50

1 year ago

2.3.29

1 year ago

4.3.57

1 year ago

4.3.56

1 year ago

4.3.55

1 year ago

4.3.54

1 year ago

4.3.59

1 year ago

4.3.58

1 year ago

5.4.74

12 months ago

5.4.75

12 months ago

4.3.42

1 year ago

4.3.41

1 year ago

4.3.40

1 year ago

6.5.84

12 months ago

4.3.46

1 year ago

4.3.45

1 year ago

6.5.86

12 months ago

4.3.44

1 year ago

6.5.85

12 months ago

4.3.43

1 year ago

2.3.31

1 year ago

4.3.49

1 year ago

2.3.30

1 year ago

4.3.48

1 year ago

4.3.47

1 year ago

2.3.32

1 year ago

6.6.88

11 months ago

6.6.89

11 months ago

4.3.71

1 year ago

4.3.70

1 year ago

4.3.73

12 months ago

4.3.72

1 year ago

6.6.86

12 months ago

6.6.87

12 months ago

4.3.60

1 year ago

4.3.64

1 year ago

4.3.63

1 year ago

4.3.62

1 year ago

4.3.61

1 year ago

4.3.68

1 year ago

4.3.67

1 year ago

4.3.66

1 year ago

4.3.65

1 year ago

1.1.23

1 year ago

1.1.22

1 year ago

1.1.21

1 year ago

4.3.69

1 year ago

5.3.73

12 months ago

5.5.84

12 months ago

5.5.82

12 months ago

5.5.83

12 months ago

5.5.80

12 months ago

5.5.81

12 months ago

3.3.32

1 year ago

2.2.28

1 year ago

2.2.29

1 year ago

2.2.26

1 year ago

2.2.27

1 year ago

2.2.25

1 year ago

5.5.79

12 months ago

5.5.77

12 months ago

5.5.78

12 months ago

5.5.75

12 months ago

6.6.90

11 months ago

5.5.76

12 months ago

6.7.101

11 months ago

6.7.92

11 months ago

6.7.100

11 months ago

6.7.93

11 months ago

6.7.94

11 months ago

6.7.95

11 months ago

6.7.105

11 months ago

6.7.96

11 months ago

4.3.35

1 year ago

6.7.104

11 months ago

6.7.97

11 months ago

4.3.34

1 year ago

6.7.103

11 months ago

6.7.98

11 months ago

4.3.33

1 year ago

6.7.102

11 months ago

6.7.99

11 months ago

4.3.32

1 year ago

4.3.39

1 year ago

1.2.23

1 year ago

4.3.38

1 year ago

1.2.24

1 year ago

4.3.37

1 year ago

6.7.106

11 months ago

4.3.36

1 year ago

6.7.90

11 months ago

1.2.25

1 year ago

6.7.91

11 months ago

1.0.21

1 year ago

1.0.20

1 year ago

1.0.19

1 year ago

1.0.18

1 year ago

1.0.17

1 year ago

1.0.16

1 year ago

1.0.15

1 year ago

1.0.14

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