Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get maxSatisfying version including pre-release with node semver

How can i get the latest version (including the pre-releases) from an array of versions using node/semver.

For example:

var semver = require("semver");
var versions = ["1.0.0-rc.10","1.0.0-rc.11"];
console.log(semver.maxSatisfying(versions, "*"));

Returns null, but i want to get the 1.0.0-rc.11 back.

Kind Regards and have a nice day!

like image 805
Michael Avatar asked Jun 25 '26 05:06

Michael


1 Answers

You need to add the includePrerelease option to your maxSatisfying method as described here: https://github.com/npm/node-semver#functions

In your example:

var semver = require("semver");
var versions = ["1.0.0-rc.10","1.0.0-rc.11"];

console.log(semver.maxSatisfying(versions, "*", {
        includePrerelease: true
}));
like image 111
Doron Avatar answered Jul 01 '26 02:07

Doron



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!