Last change
on this file since 6a80231 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
660 bytes
|
Rev | Line | |
---|
[6a3a178] | 1 | const {MAX_LENGTH} = require('../internal/constants')
|
---|
| 2 | const { re, t } = require('../internal/re')
|
---|
| 3 | const SemVer = require('../classes/semver')
|
---|
| 4 |
|
---|
| 5 | const parseOptions = require('../internal/parse-options')
|
---|
| 6 | const parse = (version, options) => {
|
---|
| 7 | options = parseOptions(options)
|
---|
| 8 |
|
---|
| 9 | if (version instanceof SemVer) {
|
---|
| 10 | return version
|
---|
| 11 | }
|
---|
| 12 |
|
---|
| 13 | if (typeof version !== 'string') {
|
---|
| 14 | return null
|
---|
| 15 | }
|
---|
| 16 |
|
---|
| 17 | if (version.length > MAX_LENGTH) {
|
---|
| 18 | return null
|
---|
| 19 | }
|
---|
| 20 |
|
---|
| 21 | const r = options.loose ? re[t.LOOSE] : re[t.FULL]
|
---|
| 22 | if (!r.test(version)) {
|
---|
| 23 | return null
|
---|
| 24 | }
|
---|
| 25 |
|
---|
| 26 | try {
|
---|
| 27 | return new SemVer(version, options)
|
---|
| 28 | } catch (er) {
|
---|
| 29 | return null
|
---|
| 30 | }
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 | module.exports = parse
|
---|
Note:
See
TracBrowser
for help on using the repository browser.