Urara-Blog/node_modules/.pnpm-store/v3/files/00/79e3101cc30c35cb36a312490205d34309c8e5f83d5f70abec7f3d5fd7bf30375ad24953813fb0b55dffe4b53cec54e8f10334dfd1685b48570859dcac0144
2022-08-14 01:14:53 +08:00

33 lines
662 B
Text

const { MAX_LENGTH } = require('../internal/constants')
const { re, t } = require('../internal/re')
const SemVer = require('../classes/semver')
const parseOptions = require('../internal/parse-options')
const parse = (version, options) => {
options = parseOptions(options)
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