Site | NPM Module | GitHub Repo
wonderful-version is the official npm module of Wonderful Version, a free app for gracefully checking semantic versions instead of throwing errors.
Yes, this module works in both Node and browser environments, including compatibility with Webpack and Browserify!
- Gracefully check semantic versions instead of throwing errors
Install with npm if you plan to use wonderful-version
in a Node project or in the browser.
npm install wonderful-version
If you plan to use wonderful-version
in a browser environment, you will probably need to use Webpack, Browserify, or a similar service to compile it.
const wonderfulVersion = require('wonderful-version');
Install with CDN if you plan to use Wonderful Version only in a browser environment.
<script src="https://cdn.jsdelivr.net/npm/wonderful-version@latest/dist/index.min.js"></script>
<script type="text/javascript">
var wonderfulVersion = WonderfulVersion;
</script>
Cleans a version string by removing non-numeric characters and trailing zeros.
console.log(wonderfulVersion.clean('v1.02.30')); // '1.2.3'
Checks if two version strings are equal after cleaning.
console.log(wonderfulVersion.equals('1.0.0', '1')); // true
Checks if version1
is less than version2
.
console.log(wonderfulVersion.lessThan('1.2.3', '1.2.4')); // true
Checks if version1
is greater than version2
.
console.log(wonderfulVersion.greaterThan('1.2.4', '1.2.3')); // true
Checks if version1
is less than or equal to version2
.
console.log(wonderfulVersion.lessThanOrEqual('1.2.3', '1.2.4')); // true
Checks if version1
is greater than or equal to version2
.
console.log(wonderfulVersion.greaterThanOrEqual('1.2.4', '1.2.3')); // true
Checks if version1
is ['===', '!=', '>', '>=', '<', '<=']
to version2
.
console.log(wonderfulVersion.is('1.2.4', '>=', '1.2.3')); // true
console.log(wonderfulVersion.is('1.2.4', '!=', '1.2.3')); // true
console.log(wonderfulVersion.is('1.2.4', '===', '1.2.4')); // true
Returns the major version
number.
console.log(wonderfulVersion.major('1.2.3')); // 1
Returns the minor version
number.
console.log(wonderfulVersion.minor('1.2.3')); // 2
Returns the patch version
number.
console.log(wonderfulVersion.patch('1.2.3')); // 3
Determines which version level (major
, minor
, or patch
) version1
is behind compared to version2
.
console.log(wonderfulVersion.behindLevel('1.2.3', '2.0.0')); // 'major'
Increments a version
number by a certain level
and amount
. Segments following the incremented level are reset to 0
.
console.log(wonderfulVersion.increment('1.2.3', 'major', 1)); // '2.0.0'
console.log(wonderfulVersion.increment('1.2.3', 'minor', 1)); // '1.3.0'
console.log(wonderfulVersion.increment('1.2.3', 'patch', 1)); // '1.2.4'
After you have followed the install step, you can start using wonderful-version
to enhance your project.
For a more in-depth documentation of this library and the Wonderful Version service, please visit the official Wonderful Version website.
A far-less-frustrating rendition of semver
If you are still having difficulty, we would love for you to post a question to the Wonderful Version issues page. It is much easier to answer questions that include your code and relevant files! So if you can provide them, we'd be extremely grateful (and more likely to help you find the answer!)
Ask us to have your project listed! :)