-
Notifications
You must be signed in to change notification settings - Fork 0
parse
Subhajit Sahu edited this page May 31, 2020
·
9 revisions
Converts string to version. 🏃 📼 📦 🌔 📒
version.parse(s, [i], [lvl]);
// s: a string
// i: start index (0)
// lvl: permissive level, 0-4/-1 (0 => none)
// --> [end index, version], or [-1, null]
const version = require('extra-version');
version.parse('1.2');
// [-1, null] (not a semver)
version.parse('1.2.0');
// [
// 5, ^ end index
// Version {
// major: 1,
// minor: 2,
// patch: 0,
// prerelease: [],
// buildmetadata: []
// }
// ]
version.parse('lagaan@1.2.3.4', 7);
// [ ^ start here
// 12, ^ end index
// Version {
// major: 1,
// minor: 2,
// patch: 3,
// prerelease: [],
// buildmetadata: []
// }
// ]
version.parse('lagaan@1.2.3.4', 7, -1);
// [ ^ start here ^ permit any error
// 14, ^ end index
// Version {
// major: 1,
// minor: 2,
// patch: 3,
// prerelease: [],
// buildmetadata: [ '4' ]
// }
// ]