node-gyp/lib/util/node_version.js
Nathan Rajlich 2461ff762c Prepare for a potential "0.10" release.
We can no longer treat the version like a Number, since `0.10`
gets represented as `0.1`.
2012-02-11 17:08:50 -08:00

35 lines
919 B
JavaScript

/**
* Helper functions for parsing and testing node versions.
* Just plain `parseFloat` doesn't work in case there's ever a "x.10" release,
* which would be parsed as x.1 when represented as a Number.
*/
var regexp = /^(\d+)\.(\d+)/
/**
* Accepts a String like "v0.10.4" and returns a String
* containing the major and minor versions ("0.10").
*/
exports.parse = function parse (str) {
str = String(str)
if (str[0] === 'v') {
str = str.substring(1)
}
return str.match(regexp)[0]
}
/**
* Accepts a major-minor version string (from `parseVersion`) and a major
* and minor Number value to test that the given version is less that the
* specified version. Returns true or false.
*/
exports.lessThan = function lessThan (ver, major, minor) {
var exec = regexp.exec(ver)
, inMaj = parseInt(exec[1])
, inMin = parseInt(exec[2])
if (inMaj > major) return false
return inMin < minor
}