What is semver-utils?
The semver-utils npm package provides utilities for parsing, comparing, and manipulating semantic version strings. It is useful for developers who need to handle versioning in their applications, ensuring compatibility and proper version management.
What are semver-utils's main functionalities?
Parsing Semantic Versions
This feature allows you to parse a semantic version string into its component parts, such as major, minor, patch, and pre-release identifiers.
const semverUtils = require('semver-utils');
const parsed = semverUtils.parse('1.2.3-alpha.1');
console.log(parsed);
Comparing Versions
This feature enables you to compare two semantic version strings to determine their order. It returns -1, 0, or 1 depending on whether the first version is less than, equal to, or greater than the second version.
const semverUtils = require('semver-utils');
const result = semverUtils.compare('1.2.3', '1.2.4');
console.log(result);
Incrementing Versions
This feature allows you to increment a semantic version string by a specified part (major, minor, or patch).
const semverUtils = require('semver-utils');
const incremented = semverUtils.increment('1.2.3', 'patch');
console.log(incremented);
Other packages similar to semver-utils
semver
The semver package is a popular library for parsing, validating, comparing, and incrementing semantic version strings. It offers a comprehensive set of features for handling semantic versions and is widely used in the Node.js ecosystem. Compared to semver-utils, semver provides more extensive functionality and better integration with npm.
node-semver
node-semver is another library for working with semantic versioning in Node.js. It provides similar functionalities to semver-utils, such as parsing, comparing, and incrementing versions. However, it is less commonly used than the semver package and may have fewer features.
semver-utils.js
| Sponsored by ppl
Some utils that aren't provided by the mainstream semver
module.
Usage
npm install --save semver-utils
'use strict';
var semverUtils = require('semver-utils');
var version = require('./package.json').version;
var semver = semverUtils.parse(version);
console.log(semver);
API
semverUtils.parse(semverString)
semverUtils.stringify(semverObject)
semverUtils.parseRange(rangeString)
semverUtils.stringifyRange(rangeArray)
semverUtils.parse(semverString)
Turns a string such as 1.0.6-1+build-623
into the object
{ semver: '1.0.6-1+build-623'
, version: '1.0.6'
, major: '1'
, minor: '0'
, patch: '6'
, release: '1'
, build: 'build-623'
}
returns null
on error
semverUtils.stringify(semverObject)
Creates a string such as 1.0.6-1+build-623
from the object
{ major: '1'
, minor: '0'
, patch: '6'
, release: '1'
, build: 'build-623'
}
semverUtils.parseRange(rangeString)
A solution to https://github.com/isaacs/node-semver/issues/10
Parses a range string into an array of semver objects
>= 1.1.7 < 2.0.0 || 1.1.3
becomes
[
{
"semver": ">= v1.1.7"
, "operator": ">="
, "major": 1
, "minor": 1
, "patch": 7
}
, {
"semver": "< v2.0.0"
, "operator": "<"
, "major": 2
, "minor": 0
, "patch": 0
}
, {
"operator": "||"
}
, {
"semver": "v1.1.3"
, "operator": "="
, "major": 1
, "minor": 1
, "patch": 3
}
]
semverUtils.stringifyRange(rangeArray)
Creates a range string such as >= 1.1.7 < 2.0.0 || 1.1.3
from an array of semver objects (and operators) such as
[
{ "semver": ">= v1.1.7"
, "operator": ">="
, "major": 1
, "minor": 1
, "patch": 7
}
, { "semver": "< v2.0.0"
, "operator": "<"
, "major": 2
, "minor": 0
, "patch": 0
}
, { "operator": "||"
}
, { "semver": "v1.1.3"
, "operator": "="
, "major": 1
, "minor": 1
, "patch": 3
}
]
Obsolete Work