Gathering detailed insights and metrics for compare-versions
Gathering detailed insights and metrics for compare-versions
Gathering detailed insights and metrics for compare-versions
Gathering detailed insights and metrics for compare-versions
versions-compare
[](https://travis-ci.org/searchfe/versions-compare) [](https://coveral
@types/compare-versions
Stub TypeScript definitions entry for compare-versions, which provides its own types definitions
version-compare
Comparator to determine if a version is less than, equivalent to, or greater than another version
compare-semver
Compare semver versions to many other semver versions
Compare semver version strings to find which is greater, equal or lesser.
npm install compare-versions
Typescript
Module System
Node Version
NPM Version
99.8
Supply Chain
100
Quality
77.1
Maintenance
100
Vulnerability
100
License
TypeScript (100%)
Total Downloads
1,195,459,678
Last Day
317,676
Last Week
6,125,457
Last Month
27,031,734
Last Year
258,948,078
MIT License
624 Stars
135 Commits
54 Forks
3 Watchers
2 Branches
12 Contributors
Updated on Jun 05, 2025
Minified
Minified + Gzipped
Latest Version
6.1.1
Package Id
compare-versions@6.1.1
Unpacked Size
54.21 kB
Size
11.26 kB
File Count
29
NPM Version
9.5.0
Node Version
20.10.0
Published on
Jul 13, 2024
Cumulative downloads
Total Downloads
Last Day
-9.8%
317,676
Compared to previous day
Last Week
-10.2%
6,125,457
Compared to previous week
Last Month
6%
27,031,734
Compared to previous month
Last Year
25.8%
258,948,078
Compared to previous year
6
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:
1.0.x
or 1.0.*
.25.0.1364.126
.v
is ignored, e.g. v1.0
is interpreted as 1.0
.1.01.1
is interpreted as 1.1.1
.1.2.7 || >=1.2.9 <2.0.0
1$ npm install compare-versions
Note: Starting from v5 the main export is now named like so: import { compareVersions } from 'compare-versions'
.
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
.
Will return 1
if first version is greater, 0
if versions are equal, and -1
if the second version is greater:
1import { compareVersions } from 'compare-versions'; 2 3compareVersions('11.1.1', '10.0.0'); // 1 4compareVersions('10.0.0', '10.0.0'); // 0 5compareVersions('10.0.0', '11.1.1'); // -1
Can also be used for sorting:
1const versions = [ 2 '1.5.19', 3 '1.2.3', 4 '1.5.5' 5] 6const sorted = versions.sort(compareVersions); 7/* 8[ 9 '1.2.3', 10 '1.5.5', 11 '1.5.19' 12] 13*/
The alternative compare
function accepts an operator which will be more familiar to humans:
1import { compare } from 'compare-versions'; 2 3compare('10.1.8', '10.0.4', '>'); // true 4compare('10.0.1', '10.0.1', '='); // true 5compare('10.1.1', '10.2.2', '<'); // true 6compare('10.1.1', '10.2.2', '<='); // true 7compare('10.1.1', '10.2.2', '>='); // false
The satisfies
function accepts a range to compare, compatible with npm package versioning:
1import { satisfies } from 'compare-versions'; 2 3satisfies('10.0.1', '~10.0.0'); // true 4satisfies('10.1.0', '~10.0.0'); // false 5satisfies('10.1.2', '^10.0.0'); // true 6satisfies('11.0.0', '^10.0.0'); // false 7satisfies('10.1.8', '>10.0.4'); // true 8satisfies('10.0.1', '=10.0.1'); // true 9satisfies('10.1.1', '<10.2.2'); // true 10satisfies('10.1.1', '<=10.2.2'); // true 11satisfies('10.1.1', '>=10.2.2'); // false 12satisfies('1.4.6', '1.2.7 || >=1.2.9 <2.0.0'); // true 13satisfies('1.2.8', '1.2.7 || >=1.2.9 <2.0.0'); // false 14satisfies('1.5.1', '1.2.3 - 2.3.4'); // true 15satisfies('2.3.5', '1.2.3 - 2.3.4'); // false
Applies the same rules used comparing version numbers and returns a boolean:
1import { validate } from 'compare-versions'; 2 3validate('1.0.0-rc.1'); // true 4validate('1.0-rc.1'); // false 5validate('foo'); // false
Validate version numbers strictly according to semver.org; 3 integers, no wildcards, no leading zero or "v" etc:
1import { validateStrict } from 'compare-versions'; 2 3validate('1.0.0'); // true 4validate('1.0.0-rc.1'); // true 5validate('1.0'); // false 6validate('1.x'); // false 7validate('v1.02'); // false
If included directly in the browser, the functions above are available on the global window under the compareVersions
object:
1<script src=https://unpkg.com/compare-versions/lib/umd/index.js></script> 2<script> 3 const { compareVersions, compare, satisfies, validate } = window.compareVersions 4 console.log(compareVersions('11.0.0', '10.0.0')) 5 console.log(compare('11.0.0', '10.0.0', '>')) 6 console.log(satisfies('1.2.0', '^1.0.0')) 7 console.log(validate('11.0.0')) 8 console.log(validateStrict('11.0.0')) 9</script>
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
2 existing vulnerabilities detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 4
Details
Reason
branch protection is not maximal on development and all release branches
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 1/30 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-06-02
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More