Semantic Version Comparison Utility

1.0.3 · abandoned · verified Sun Apr 19

This package provides a lightweight utility function for comparing two semantic version strings, adhering to the semver specification. It evaluates major, minor, patch, and pre-release identifiers, returning -1 if the first version is less than the second, 0 if they are equal, and 1 if the first is greater. The current stable version is 1.0.3, which was last published over six years ago (as of 2026), indicating that the project is largely abandoned and no longer receives active maintenance or updates. Its key differentiator is its singular focus on version comparison without supporting more complex features like version ranges. Due to its age and lack of updates, it exclusively uses the CommonJS module format. Newer projects or those requiring ESM compatibility, TypeScript support, or active development should consider more modern alternatives.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates basic semantic version comparison, showing how it handles different version parts and pre-release tags.

const compare = require('node-version-compare');

console.log(compare('1.0.0', '1.0.1'));                     // Expected: -1
console.log(compare('10.2.0-alpha.1', '10.2.0-alpha.1'));   // Expected: 0
console.log(compare('10.2.0-beta', '10.2.0-alpha'));        // Expected: 1
console.log(compare('3.1.1-1', '3.1.1-2'));                 // Expected: -1
console.log(compare('1.2.3', '1.2.3-alpha'));               // Expected: 1 (stable is greater than pre-release)
console.log(compare('1.0.0-rc.1', '1.0.0-rc.1.1'));         // Expected: -1

view raw JSON →