package.functions.parse.js Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of semver Show documentation
Show all versions of semver Show documentation
The semantic version parser used by npm.
const { MAX_LENGTH } = require('../internal/constants')
const SemVer = require('../classes/semver')
const parse = (version, options) => {
if (version instanceof SemVer) {
return version
}
if (typeof version !== 'string') {
return null
}
if (version.length > MAX_LENGTH) {
return null
}
try {
return new SemVer(version, options)
} catch (er) {
return null
}
}
module.exports = parse