Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

compare-versions

Package Overview
Dependencies
Maintainers
0
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

compare-versions

Compare semver version strings to find greater, equal or lesser.

  • 6.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5.3M
decreased by-11.13%
Maintainers
0
Weekly downloads
 
Created

What is compare-versions?

The compare-versions npm package is used to compare and sort semantic version numbers. It provides a simple API for comparing version strings in 'major.minor.patch' format, and it can be used in various environments such as Node.js, browsers, and as a command-line tool.

What are compare-versions's main functionalities?

Compare versions

Compares two semantic version numbers and returns -1, 0, or 1 if the first version is less than, equal to, or greater than the second version, respectively.

const compareVersions = require('compare-versions');
console.log(compareVersions('1.2.3', '4.11.6')); // -1

Check if a version satisfies a range

Determines if a version satisfies a given range. It returns true if the version meets the criteria of the range, false otherwise.

const compareVersions = require('compare-versions');
console.log(compareVersions.satisfies('1.2.3', '>=1.0.0')); // true

Sort an array of versions

Sorts an array of semantic version numbers in ascending order.

const compareVersions = require('compare-versions');
const versions = ['1.2.3', '4.11.6', '2.0.0'];
versions.sort(compareVersions);
console.log(versions); // ['1.2.3', '2.0.0', '4.11.6']

Other packages similar to compare-versions

Keywords

FAQs

Package last updated on 13 Jul 2024

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc