3.11.87 • Published 1 year ago

@dramaorg/illo-nisi-corrupti v3.11.87

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

@dramaorg/illo-nisi-corrupti

Build Status Coverage Status npm bundle size (minified + gzip)

Compare semver version strings to find greater, equal or lesser. Runs in the browser as well as Node.js/React Native etc. Has no dependencies and is tiny.

Supports the full semver specification including versions with different number of digits like 1.0.0, 1.0, 1 and pre-releases like 1.0.0-alpha. Additionally supports the following variations:

  • Wildcards for minor and patch version like 1.0.x or 1.0.*.
  • Chromium version numbers with 4 parts, e.g. version 25.0.1364.126.
  • Any leading v is ignored, e.g. v1.0 is interpreted as 1.0.
  • Leading zero is ignored, e.g. 1.01.1 is interpreted as 1.1.1.
  • npm version ranges, e.g. 1.2.7 || >=1.2.9 <2.0.0

Install

$ npm install @dramaorg/illo-nisi-corrupti

Note: Starting from v5 the main export is now named like so: import { compareVersions } from '@dramaorg/illo-nisi-corrupti'.

Note: Starting from v4 this library includes a ESM version which will automatically be selected by your bundler (webpack, parcel etc). The CJS/UMD version is lib/umd/index.js and the new ESM version is lib/esm/index.js.

Usage

Will return 1 if first version is greater, 0 if versions are equal, and -1 if the second version is greater:

import { compareVersions } from '@dramaorg/illo-nisi-corrupti';

compareVersions('11.1.1', '10.0.0'); //  1
compareVersions('10.0.0', '10.0.0'); //  0
compareVersions('10.0.0', '11.1.1'); // -1

Can also be used for sorting:

const versions = [
  '1.5.19',
  '1.2.3',
  '1.5.5'
]
const sorted = versions.sort(compareVersions);
/*
[
  '1.2.3',
  '1.5.5',
  '1.5.19'
]
*/

"Human Readable" Compare

The alternative compare function accepts an operator which will be more familiar to humans:

import { compare } from '@dramaorg/illo-nisi-corrupti';

compare('10.1.8', '10.0.4', '>');  // true
compare('10.0.1', '10.0.1', '=');  // true
compare('10.1.1', '10.2.2', '<');  // true
compare('10.1.1', '10.2.2', '<='); // true
compare('10.1.1', '10.2.2', '>='); // false

Version ranges

The satisfies function accepts a range to compare, compatible with npm package versioning:

import { satisfies } from '@dramaorg/illo-nisi-corrupti';

satisfies('10.0.1', '~10.0.0');  // true
satisfies('10.1.0', '~10.0.0');  // false
satisfies('10.1.2', '^10.0.0');  // true
satisfies('11.0.0', '^10.0.0');  // false
satisfies('10.1.8', '>10.0.4');  // true
satisfies('10.0.1', '=10.0.1');  // true
satisfies('10.1.1', '<10.2.2');  // true
satisfies('10.1.1', '<=10.2.2'); // true
satisfies('10.1.1', '>=10.2.2'); // false
satisfies('1.4.6', '1.2.7 || >=1.2.9 <2.0.0'); // true
satisfies('1.2.8', '1.2.7 || >=1.2.9 <2.0.0'); // false
satisfies('1.5.1', '1.2.3 - 2.3.4'); // true
satisfies('2.3.5', '1.2.3 - 2.3.4'); // false

Validate version numbers

Applies the same rules used comparing version numbers and returns a boolean:

import { validate } from '@dramaorg/illo-nisi-corrupti';

validate('1.0.0-rc.1'); // true
validate('1.0-rc.1');   // false
validate('foo');        // false

Validate version numbers (strict)

Validate version numbers strictly according to semver.org; 3 integers, no wildcards, no leading zero or "v" etc:

import { validateStrict } from '@dramaorg/illo-nisi-corrupti';

validate('1.0.0');      // true
validate('1.0.0-rc.1'); // true
validate('1.0');        // false
validate('1.x');        // false
validate('v1.02');      // false

Browser

If included directly in the browser, the functions above are available on the global window under the compareVersions object:

<script src=https://unpkg.com/@dramaorg/illo-nisi-corrupti/lib/umd/index.js></script>
<script>
  const { compareVersions, compare, satisfies, validate } = window.compareVersions
  console.log(compareVersions('11.0.0', '10.0.0'))
  console.log(compare('11.0.0', '10.0.0', '>'))
  console.log(satisfies('1.2.0', '^1.0.0'))
  console.log(validate('11.0.0'))
  console.log(validateStrict('11.0.0'))
</script>
typanionbyteOffsetreactSeteventEmitterttyslotFloat32ArrayFunction.prototype.nameInt8ArrayECMAScript 2015io-tsregexECMAScript 2022streams2route53mkdirpclassnamesdescriptorscommandReflect.getPrototypeOfAsyncIteratorcall-boundpreprocessorprettywidththroatproxypreserve-symlinksairbnbchromestringifier.envfast-copycloudtrailargsdescriptorloadbalancingmobileECMAScript 7getterES2016css lesscompile lessnativepositivedataViewsidehasOwnPropertyentriesregular expressioniamaccessorwgetkeycolumnsmetadataformsimmutabletimepropertyObject.valuesagentdeterministicreact-hookstypeerrorjestminimalreadablestreamBigInt64Arrayhttpsyntaxerrorpasswordglacierwritei18nconfigurablepathcssartframeworkArrayBuffer.prototype.slicewalkansijsdiffmixinsvieweventssimpledbtype$.extendlintcallbounds3nested cssfast-cloneswfvalidatedeepsharedsetImmediateArray.prototype.includescensorredactloadingreducereast-asian-widthmulti-packagees5code pointscolorprototypeMicrosofttestingnegative zerosqsponyfillarktyperoutekarmagdprzodcompilerdefinePropertyURLescapesymlinkstslibmapexecObject.getPrototypeOfphonelimitimmergroupobjectfolderfunctionsregexptakepipewatchfixed-widthECMAScript 2020Uint16ArrayregularnodetrimStartpackage managercjkmoveESastperformantvalidationwarninggetOwnPropertyDescriptortrimRightconsumeform-validationelbES8eventDispatchereslintRegExp.prototype.flagsduplexterminalcolorsshellparsingoffsetformes7package.jsondebuggerassigngraphqlargvtoSortedstreamsemojitraversedatafast-deep-copybddstructuredClonewritableschemeArray.prototype.filterqslivetypescriptownstablewebpromisesisConcatSpreadablechaimapreducefluxbrowseriteratermdircloudformationfullwidthgenericsmimetypesfile systemratecollectionless mixinsArray.prototype.containsredirectawesomesauceguidtestESnexttyped arraytostringtagvisualsearches6runtimedeep-cloneobjincludesObject.entriesstylingWebSocketES2020columncodesiteratorfseventsidstatelessdependenciesmruhashfunctionalstyled-componentsdeepcopytestertrimshimcommanderreact-hook-formnumberlook-upcall-bindinstallerawsstylesheetrequiresyntaxES5bindbrowserlistjsxfastcopyjsonpathclikoreanenvnegativehooksworkspace:*es2018installconnectrm -frSymbol.toStringTagquerytypeofvariablesprogressMapeslintconfigresolve-0prunergbpnpm9location_.extendautoprefixerECMAScript 2018queueMicrotaskhelpersinferencestreaminspectRFC-6455walkingcallbacksymlinkworkflowbreakbannermochaUnderscorepredictableloggingdescription0higher-orderless.jsfromECMAScript 2021apidayjsInt16ArrayxhraccessibilityECMAScript 2023datesliceES6ES2019ES2023dependency manager[[Prototype]]256eslintpluginelectronmoduletypedarraycharacterssortedcloudfrontunicodesuperstructECMAScript 2016symbolintrinsicless compilercopyObservableBigUint64ArrayebsfastpushrequestmatchAllutil.inspect@@toStringTagnopeextrareduxtddargumentYAMLtypesafereact-testing-librarydiffprefixmake dirarraybufferhookformajvassertiondirectorywafvaluesmiddlewareObjectstdlibtermemrlesscssutilObject.istsJSONtrimLeftjsspeclockfileequalRxJSgradients css3IteratorfigletclassnamefilterfastifybluebirdschemacoercibleArray.prototype.flattenES2018styleswordwraperrorcss variableformattingratelimitdotenvspeedstyleguidewhatwgsomeString.prototype.trimreusecommand-lineECMAScript 5cloudsearchoutputuuidxtermoptionkinesiscryptnamessetPrototypeOfpropertiesconsoleworkeridleprotocol-buffersutilityspinnersjsonrangeerrorCSSstatetypedmodulesparentsa11ypackagescloudwatchauthchinesebytetypedarrayshotTypedArrayglobpluginWeakMapconcatreal-timeES2022matchesclientdropchannelwatcherArray.prototype.findLastassertsjQueryl10nes-abstractasyncfullregular expressionsredux-toolkitdeletedirECMAScript 6linkArrayBuffer#sliceparseronceWebSocketstapfindupespreepropwaitbcryptsetterspinnerserializationcircularstoragegatewayencryptiontoArrayomitmakestarterdefinehas-owntc39importStreamECMAScript 2017Array.prototype.flatMapextendrobusturlassertrm -rfes2015polyfillfastcloneutilitiesshebangES7sharedarraybuffereveryforEachinputcore
2.7.62

1 year ago

2.5.44

1 year ago

1.4.28

1 year ago

1.4.29

1 year ago

1.4.31

1 year ago

1.4.30

1 year ago

1.4.33

1 year ago

1.4.32

1 year ago

1.4.35

1 year ago

1.4.34

1 year ago

1.4.37

1 year ago

1.4.36

1 year ago

1.4.39

1 year ago

1.4.38

1 year ago

3.8.69

1 year ago

3.8.67

1 year ago

3.8.68

1 year ago

3.8.65

1 year ago

3.8.66

1 year ago

3.10.75

1 year ago

3.10.76

1 year ago

3.10.73

1 year ago

3.10.74

1 year ago

3.10.79

1 year ago

3.10.77

1 year ago

3.10.78

1 year ago

3.10.71

1 year ago

3.10.72

1 year ago

3.8.63

1 year ago

3.8.64

1 year ago

1.1.19

1 year ago

1.1.18

1 year ago

1.1.17

1 year ago

2.8.63

1 year ago

2.8.62

1 year ago

3.10.82

1 year ago

2.6.48

1 year ago

3.10.83

1 year ago

2.6.49

1 year ago

3.10.80

1 year ago

3.10.81

1 year ago

2.6.44

1 year ago

1.1.23

1 year ago

2.6.45

1 year ago

1.1.22

1 year ago

2.6.46

1 year ago

1.1.21

1 year ago

2.6.47

1 year ago

1.1.20

1 year ago

3.8.70

1 year ago

1.1.24

1 year ago

2.6.50

1 year ago

2.6.59

1 year ago

2.6.55

1 year ago

2.6.56

1 year ago

2.6.57

1 year ago

2.6.58

1 year ago

2.6.51

1 year ago

2.6.52

1 year ago

1.5.39

1 year ago

2.6.53

1 year ago

2.6.54

1 year ago

2.6.60

1 year ago

2.6.61

1 year ago

1.5.41

1 year ago

1.5.40

1 year ago

1.5.43

1 year ago

1.5.42

1 year ago

1.5.44

1 year ago

1.3.25

1 year ago

2.6.62

1 year ago

1.3.28

1 year ago

1.3.26

1 year ago

1.3.27

1 year ago

3.11.86

1 year ago

3.11.85

1 year ago

3.11.87

1 year ago

3.11.84

1 year ago

3.11.83

1 year ago

1.2.24

1 year ago

3.9.71

1 year ago

1.2.25

1 year ago

3.9.70

1 year ago

1.1.16

1 year ago

1.1.12

1 year ago

1.1.15

1 year ago

1.1.14

1 year ago

1.1.13

1 year ago

1.1.11

1 year ago

1.1.10

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

1 year ago

1.0.3

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago