Socket
Socket
Sign inDemoInstall

compare-versions

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

compare-versions - npm Package Compare versions

Comparing version 4.1.4 to 6.1.0

lib/esm/compare.d.ts

27

package.json
{
"name": "compare-versions",
"version": "4.1.4",
"version": "6.1.0",
"description": "Compare semver version strings to find greater, equal or lesser.",

@@ -23,17 +23,24 @@ "repository": {

"scripts": {
"test": "c8 --reporter=lcov mocha"
"build": "npm run build:esm && npm run build:umd",
"build:esm": "tsc --module esnext --target es2017 --outDir lib/esm",
"build:umd": "rollup lib/esm/index.js --format umd --name compareVersions --sourcemap -o lib/umd/index.js",
"prepublishOnly": "npm run build",
"test": "c8 --reporter=lcov mocha -r ts-node/register test/**/*.ts"
},
"main": "index.js",
"module": "index.mjs",
"types": "index.d.ts",
"main": "./lib/umd/index.js",
"module": "./lib/esm/index.js",
"types": "./lib/esm/index.d.ts",
"sideEffects": false,
"files": [
"index.js",
"index.mjs",
"index.d.ts"
"lib",
"src"
],
"devDependencies": {
"c8": "^7.10.0",
"mocha": "^10.0.0"
"@types/mocha": "^10.0.1",
"c8": "^8.0.1",
"mocha": "^10.0.0",
"rollup": "^3.7.4",
"ts-node": "^10.7.0",
"typescript": "^5.1.6"
}
}

@@ -15,2 +15,3 @@ # compare-versions

- Leading zero is ignored, e.g. `1.01.1` is interpreted as `1.1.1`.
- [npm version ranges](https://docs.npmjs.com/cli/v6/using-npm/semver#ranges), e.g. `1.2.7 || >=1.2.9 <2.0.0`

@@ -23,4 +24,6 @@ ## Install

Note: Starting from v4 this library includes a ESM version which will automatically be selected by your bundler (webpack, parcel etc). The old CJS version is `index.js` and the new ESM version is `index.mjs`.
__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`.
## Usage

@@ -31,3 +34,3 @@

```js
import compareVersions from 'compare-versions';
import { compareVersions } from 'compare-versions';

@@ -87,2 +90,6 @@ compareVersions('11.1.1', '10.0.0'); // 1

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
```

@@ -92,3 +99,3 @@

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

@@ -103,14 +110,30 @@ ```js

### Validate version numbers (strict)
Validate version numbers strictly according to semver.org; 3 integers, no wildcards, no leading zero or "v" etc:
```js
import { validateStrict } from 'compare-versions';
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, `compareVersions()` is available on the global window:
If included directly in the browser, the functions above are available on the global window under the `compareVersions` object:
```html
<script src=https://unpkg.com/compare-versions></script>
<script src=https://unpkg.com/compare-versions/lib/umd/index.js></script>
<script>
window.compareVersions('11.0.0', '10.0.0');
window.compareVersions.compare('11.0.0', '10.0.0', '>');
window.compareVersions.validate('11.0.0');
window.compareVersions.satisfies('1.2.0', '^1.0.0');
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>
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc