Urara-Blog/node_modules/.pnpm-store/v3/files/94/1555bc1f43b58080446476cfc8fa122c27ec36245623f1abfbf55c16d08fd8a7b65821149cf6dff2ca239bdf26083fabb5d6914dd3884961715b7061d11b7a
2022-08-14 01:14:53 +08:00

37 lines
698 B
Text

const {MAX_LENGTH} = require('../internal/constants')
const { re, t } = require('../internal/re')
const SemVer = require('../classes/semver')
const parse = (version, options) => {
if (!options || typeof options !== 'object') {
options = {
loose: !!options,
includePrerelease: false
}
}
if (version instanceof SemVer) {
return version
}
if (typeof version !== 'string') {
return null
}
if (version.length > MAX_LENGTH) {
return null
}
const r = options.loose ? re[t.LOOSE] : re[t.FULL]
if (!r.test(version)) {
return null
}
try {
return new SemVer(version, options)
} catch (er) {
return null
}
}
module.exports = parse