Socket
Socket
Sign inDemoInstall

semver-compare

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

semver-compare

compare two semver version strings, returning -1, 0, or 1


Version published
Maintainers
1
Weekly downloads
6,193,766
decreased by-7.16%

Weekly downloads

Package description

What is semver-compare?

The semver-compare npm package is a simple utility for comparing semantic version strings. It allows developers to determine the order of semantic versions, check if one version is greater than, less than, or equal to another, and sort arrays of version strings.

What are semver-compare's main functionalities?

Compare two semantic version strings

This feature allows you to compare two semantic version strings and returns -1, 0, or 1 depending on whether the first version is less than, equal to, or greater than the second version.

"const compare = require('semver-compare');
let result = compare('1.2.3', '1.2.4');
console.log(result); // -1"

Sort an array of semantic version strings

This feature allows you to sort an array of semantic version strings in ascending order using the compare function provided by the package.

"const compare = require('semver-compare');
let versions = ['1.2.3', '1.2.4', '1.2.2'];
versions.sort(compare);
console.log(versions); // ['1.2.2', '1.2.3', '1.2.4']"

Other packages similar to semver-compare

Readme

Source

semver-compare

compare two semver version strings, returning -1, 0, or 1

The return value can be fed straight into [].sort.

build status

example

var cmp = require('semver-compare');
var versions = [
    '1.2.3',
    '4.11.6',
    '4.2.0',
    '1.5.19',
    '1.5.5',
    '4.1.3',
    '2.3.1',
    '10.5.5',
    '11.3.0'
];
console.log(versions.sort(cmp).join('\n'));

prints:

1.2.3
1.5.5
1.5.19
2.3.1
4.1.3
4.2.0
4.11.6
10.5.5
11.3.0

whereas the default lexicographic sort (versions.sort()) would be:

1.2.3
1.5.19
1.5.5
10.5.5
11.3.0
2.3.1
4.1.3
4.11.6
4.2.0

methods

var cmp = require('semver-compare')

cmp(a, b)

If the semver string a is greater than b, return 1. If the semver string b is greater than a, return -1. If a equals b, return 0;

install

With npm do:

npm install semver-compare

license

MIT

Keywords

FAQs

Last updated on 08 Nov 2014

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc