
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
A lightweight version class to handle semantic version manipulation in Javascript.
To install run:
npm install version-js
And import by adding:
import Version from 'version-js';
A Version object can be instantiated with either a Semantic Version string or an object with preformatted properties resembling a semantic version object.
let string = '3.2.1-beta.release+meta.data'
The formatted string must follow conventions outlined in the Semantic Version documentation. It may be preceeded by the character v which will be omitted when parsed.
let object = {
major: 3,
minor: 2,
patch: 1,
prerelease: ['beta', 'release'],
metadata: ['meta', 'data']
}
The basic version object must follow the above format. Pre-release and metadata items should be set in an array.
A Version object can be instantiated like the following:
let version = new Version('3.2.1-beta.release+meta.data');
or
let version = new Version({
major: 3,
minor: 2,
patch: 1,
prerelease: ['beta', 'release'],
metadata: ['meta', 'data']
});
As of now, a Version object's version levels can be modified like the following:
Add version level
version.addMajor();
// version.major = 3+1 = 4
Subtract version level
version.subMajor();
// version.major = 3-1 = 2
Set version level
version.setMajor(10);
// version.major = 10
The above mathematical operations accept an optional value parameter which allows for nonstandard version changing like the following:
version.addMajor(5);
// version.major = 2+5 = 7
The following methods are available for Version modification:
addMajor(value = 1); // Add to Major version
subMajor(value = 1); // Subtract from Major version
setMajor(); // Set Major version
addMinor(value = 1); // Add to Minor version
subMinor(value = 1); // Subtract from Minor version
setMinor(); // Set Minor version
addPatch(value = 1); // Add to Patch version
subPatch(value = 1); // Subtract from Patch version
setPatch(); // Set Patch version
All modifiers accept either a string or integer representation of a positive integer.
A Version object may be compared to another.
Assuming a second version2 object:
let version2 = new Version({
major: 5,
minor: 4,
patch: 3,
prerelease: ['beta', 'release'],
metadata: ['meta', 'data']
});
We can determine if version is greater than version2:
version.isGreaterThan(version2); // False (3.2.1 << 5.4.3)
Or less than:
version.isLessThan(version2); // True (3.2.1 << 5.4.3)
Or equal to:
version.isEqualTo(version2, precise = false); // False (3.2.1 != 5.4.3)
Or less than or equal to:
version.isEqualOrLessThan(version2, precise = false); // True (3.2.1 << 5.4.3)
Or greater than or equal to:
version.isEqualOrGreaterThan(version2, precise = false); // False (3.2.1 << 5.4.3)
Note: isEqualTo(), isEqualOrLessThan() and isEqualOrGreaterThan() accept an optional second parameter precise which tells it to do a precise match when compared for equality. If precise = false (default) then the version will only be compared by Major, Minor and Patch values. If precise = true, the pre-release and metadata will also be evaluated (This would be considered a perfect match).
The version-js package is open-source software under the MIT License.
FAQs
Manipulate and compare semantic versions in Javascript.
We found that version-js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.