Skip to content

Instantly share code, notes, and snippets.

@lopezjurip
Last active December 17, 2016 15:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lopezjurip/dd3452d1232129e039f2f753e63b5a4b to your computer and use it in GitHub Desktop.
Save lopezjurip/dd3452d1232129e039f2f753e63b5a4b to your computer and use it in GitHub Desktop.
Detect semver release
const assert = require('assert');
function version(semver) {
const indexes = [
'major',
'minor',
'patch',
];
return semver.split('.').reduce((classification, number, index) => {
return (number !== '0') ? indexes[index] : classification;
}, indexes[0]);
}
assert(version('1.2.0') === 'minor');
assert(version('2.0.0') === 'major');
assert(version('2.0.2') === 'patch');
assert(version('0.0.2') === 'patch');
// All pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment