Archived
1
0
Fork 0
This repository has been archived on 2025-01-22. You can view files and clone it, but cannot push or open issues or pull requests.
limepot-xyz/mybulma/node_modules/semver/functions/parse.js
2023-01-27 19:21:00 -07:00

33 lines
662 B
JavaScript

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