basant307/AI_Governance_Project
048
1# compare-versions2 3[](https://github.com/omichelsen/compare-versions/actions/workflows/ci.yml)4[](https://coveralls.io/github/omichelsen/compare-versions?branch=main)5[](https://bundlephobia.com/package/compare-versions)6 7Compare [semver](https://semver.org/) 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](https://bundlephobia.com/package/compare-versions).8 9Supports 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:10 11- Wildcards for minor and patch version like `1.0.x` or `1.0.*`.12- [Chromium version numbers](https://www.chromium.org/developers/version-numbers) with 4 parts, e.g. version `25.0.1364.126`.13- Any leading `v` is ignored, e.g. `v1.0` is interpreted as `1.0`.14- Leading zero is ignored, e.g. `1.01.1` is interpreted as `1.1.1`.15- [npm version ranges](https://docs.npmjs.com/cli/v6/using-npm/semver#ranges), e.g. `1.2.7 || >=1.2.9 <2.0.0`16 17## Install18 19```bash20$ npm install compare-versions21```22 23__Note__: Starting from v5 the main export is now _named_ like so: `import { compareVersions } from 'compare-versions'`.24 25__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`.26 27## Usage28 29Will return `1` if first version is greater, `0` if versions are equal, and `-1` if the second version is greater:30 31```js32import { compareVersions } from 'compare-versions';33 34compareVersions('11.1.1', '10.0.0'); // 135compareVersions('10.0.0', '10.0.0'); // 036compareVersions('10.0.0', '11.1.1'); // -137```38 39Can also be used for sorting:40 41```js42const versions = [43 '1.5.19',44 '1.2.3',45 '1.5.5'46]47const sorted = versions.sort(compareVersions);48/*49[50 '1.2.3',51 '1.5.5',52 '1.5.19'53]54*/55```56 57### "Human Readable" Compare58 59The alternative `compare` function accepts an operator which will be more familiar to humans:60 61```js62import { compare } from 'compare-versions';63 64compare('10.1.8', '10.0.4', '>'); // true65compare('10.0.1', '10.0.1', '='); // true66compare('10.1.1', '10.2.2', '<'); // true67compare('10.1.1', '10.2.2', '<='); // true68compare('10.1.1', '10.2.2', '>='); // false69```70 71### Version ranges72 73The `satisfies` function accepts a range to compare, compatible with [npm package versioning](https://docs.npmjs.com/cli/v6/using-npm/semver):74 75```js76import { satisfies } from 'compare-versions';77 78satisfies('10.0.1', '~10.0.0'); // true79satisfies('10.1.0', '~10.0.0'); // false80satisfies('10.1.2', '^10.0.0'); // true81satisfies('11.0.0', '^10.0.0'); // false82satisfies('10.1.8', '>10.0.4'); // true83satisfies('10.0.1', '=10.0.1'); // true84satisfies('10.1.1', '<10.2.2'); // true85satisfies('10.1.1', '<=10.2.2'); // true86satisfies('10.1.1', '>=10.2.2'); // false87satisfies('1.4.6', '1.2.7 || >=1.2.9 <2.0.0'); // true88satisfies('1.2.8', '1.2.7 || >=1.2.9 <2.0.0'); // false89satisfies('1.5.1', '1.2.3 - 2.3.4'); // true90satisfies('2.3.5', '1.2.3 - 2.3.4'); // false91```92 93### Validate version numbers94 95Applies the same rules used comparing version numbers and returns a boolean:96 97```js98import { validate } from 'compare-versions';99 100validate('1.0.0-rc.1'); // true101validate('1.0-rc.1'); // false102validate('foo'); // false103```104 105### Validate version numbers (strict)106 107Validate version numbers strictly according to semver.org; 3 integers, no wildcards, no leading zero or "v" etc:108 109```js110import { validateStrict } from 'compare-versions';111 112validate('1.0.0'); // true113validate('1.0.0-rc.1'); // true114validate('1.0'); // false115validate('1.x'); // false116validate('v1.02'); // false117```118 119### Browser120 121If included directly in the browser, the functions above are available on the global window under the `compareVersions` object:122 123```html124<script src=https://unpkg.com/compare-versions/lib/umd/index.js></script>125<script>126 const { compareVersions, compare, satisfies, validate } = window.compareVersions127 console.log(compareVersions('11.0.0', '10.0.0'))128 console.log(compare('11.0.0', '10.0.0', '>'))129 console.log(satisfies('1.2.0', '^1.0.0'))130 console.log(validate('11.0.0'))131 console.log(validateStrict('11.0.0'))132</script>133```134 