1
0
mirror of https://gitee.com/onvia/ccc-tnt-psd2ui synced 2025-05-04 04:48:41 +00:00

34 lines
662 B
JavaScript
Raw Normal View History

2023-07-27 15:04:13 +08:00
const { MAX_LENGTH } = require('../internal/constants')
const { re, t } = require('../internal/re')
2023-07-24 11:13:08 +08:00
const SemVer = require('../classes/semver')
2023-07-27 15:04:13 +08:00
const parseOptions = require('../internal/parse-options')
const parse = (version, options) => {
options = parseOptions(options)
2023-07-24 11:13:08 +08:00
if (version instanceof SemVer) {
return version
}
2023-07-27 15:04:13 +08:00
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
}
2023-07-24 11:13:08 +08:00
try {
return new SemVer(version, options)
} catch (er) {
2023-07-27 15:04:13 +08:00
return null
2023-07-24 11:13:08 +08:00
}
}
module.exports = parse