New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More

compare-version

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

compare-version

Compare semver version numbers

0.1.2
latest
Version published
Maintainers
1
Created

What is compare-version?

The compare-version npm package is a simple utility for comparing semantic version numbers. It allows you to determine if one version is greater than, less than, or equal to another version, which is useful for version control and dependency management.

What are compare-version's main functionalities?

Compare Versions

This feature allows you to compare two version strings. The function returns -1 if the first version is less than the second, 1 if the first version is greater than the second, and 0 if they are equal.

const compareVersions = require('compare-versions');

console.log(compareVersions('1.0.0', '1.0.1')); // -1
console.log(compareVersions('1.0.1', '1.0.0')); // 1
console.log(compareVersions('1.0.0', '1.0.0')); // 0

Check if Version is Greater Than

This feature allows you to check if one version is greater than another using a comparison operator. It returns true if the condition is met, otherwise false.

const compareVersions = require('compare-versions');

console.log(compareVersions.compare('1.0.1', '1.0.0', '>')); // true
console.log(compareVersions.compare('1.0.0', '1.0.1', '>')); // false

Check if Version is Less Than

This feature allows you to check if one version is less than another using a comparison operator. It returns true if the condition is met, otherwise false.

const compareVersions = require('compare-versions');

console.log(compareVersions.compare('1.0.0', '1.0.1', '<')); // true
console.log(compareVersions.compare('1.0.1', '1.0.0', '<')); // false

Check if Version is Equal

This feature allows you to check if two versions are equal using a comparison operator. It returns true if the condition is met, otherwise false.

const compareVersions = require('compare-versions');

console.log(compareVersions.compare('1.0.0', '1.0.0', '=')); // true
console.log(compareVersions.compare('1.0.0', '1.0.1', '=')); // false

Other packages similar to compare-version

FAQs

Package last updated on 23 Apr 2014

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