source: trip-planner-front/node_modules/semver/internal/re.js@ 59329aa

Last change on this file since 59329aa was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 6.5 KB
RevLine 
[6a3a178]1const { MAX_SAFE_COMPONENT_LENGTH } = require('./constants')
2const debug = require('./debug')
3exports = module.exports = {}
4
5// The actual regexps go on exports.re
6const re = exports.re = []
7const src = exports.src = []
8const t = exports.t = {}
9let R = 0
10
11const createToken = (name, value, isGlobal) => {
12 const index = R++
13 debug(index, value)
14 t[name] = index
15 src[index] = value
16 re[index] = new RegExp(value, isGlobal ? 'g' : undefined)
17}
18
19// The following Regular Expressions can be used for tokenizing,
20// validating, and parsing SemVer version strings.
21
22// ## Numeric Identifier
23// A single `0`, or a non-zero digit followed by zero or more digits.
24
25createToken('NUMERICIDENTIFIER', '0|[1-9]\\d*')
26createToken('NUMERICIDENTIFIERLOOSE', '[0-9]+')
27
28// ## Non-numeric Identifier
29// Zero or more digits, followed by a letter or hyphen, and then zero or
30// more letters, digits, or hyphens.
31
32createToken('NONNUMERICIDENTIFIER', '\\d*[a-zA-Z-][a-zA-Z0-9-]*')
33
34// ## Main Version
35// Three dot-separated numeric identifiers.
36
37createToken('MAINVERSION', `(${src[t.NUMERICIDENTIFIER]})\\.` +
38 `(${src[t.NUMERICIDENTIFIER]})\\.` +
39 `(${src[t.NUMERICIDENTIFIER]})`)
40
41createToken('MAINVERSIONLOOSE', `(${src[t.NUMERICIDENTIFIERLOOSE]})\\.` +
42 `(${src[t.NUMERICIDENTIFIERLOOSE]})\\.` +
43 `(${src[t.NUMERICIDENTIFIERLOOSE]})`)
44
45// ## Pre-release Version Identifier
46// A numeric identifier, or a non-numeric identifier.
47
48createToken('PRERELEASEIDENTIFIER', `(?:${src[t.NUMERICIDENTIFIER]
49}|${src[t.NONNUMERICIDENTIFIER]})`)
50
51createToken('PRERELEASEIDENTIFIERLOOSE', `(?:${src[t.NUMERICIDENTIFIERLOOSE]
52}|${src[t.NONNUMERICIDENTIFIER]})`)
53
54// ## Pre-release Version
55// Hyphen, followed by one or more dot-separated pre-release version
56// identifiers.
57
58createToken('PRERELEASE', `(?:-(${src[t.PRERELEASEIDENTIFIER]
59}(?:\\.${src[t.PRERELEASEIDENTIFIER]})*))`)
60
61createToken('PRERELEASELOOSE', `(?:-?(${src[t.PRERELEASEIDENTIFIERLOOSE]
62}(?:\\.${src[t.PRERELEASEIDENTIFIERLOOSE]})*))`)
63
64// ## Build Metadata Identifier
65// Any combination of digits, letters, or hyphens.
66
67createToken('BUILDIDENTIFIER', '[0-9A-Za-z-]+')
68
69// ## Build Metadata
70// Plus sign, followed by one or more period-separated build metadata
71// identifiers.
72
73createToken('BUILD', `(?:\\+(${src[t.BUILDIDENTIFIER]
74}(?:\\.${src[t.BUILDIDENTIFIER]})*))`)
75
76// ## Full Version String
77// A main version, followed optionally by a pre-release version and
78// build metadata.
79
80// Note that the only major, minor, patch, and pre-release sections of
81// the version string are capturing groups. The build metadata is not a
82// capturing group, because it should not ever be used in version
83// comparison.
84
85createToken('FULLPLAIN', `v?${src[t.MAINVERSION]
86}${src[t.PRERELEASE]}?${
87 src[t.BUILD]}?`)
88
89createToken('FULL', `^${src[t.FULLPLAIN]}$`)
90
91// like full, but allows v1.2.3 and =1.2.3, which people do sometimes.
92// also, 1.0.0alpha1 (prerelease without the hyphen) which is pretty
93// common in the npm registry.
94createToken('LOOSEPLAIN', `[v=\\s]*${src[t.MAINVERSIONLOOSE]
95}${src[t.PRERELEASELOOSE]}?${
96 src[t.BUILD]}?`)
97
98createToken('LOOSE', `^${src[t.LOOSEPLAIN]}$`)
99
100createToken('GTLT', '((?:<|>)?=?)')
101
102// Something like "2.*" or "1.2.x".
103// Note that "x.x" is a valid xRange identifer, meaning "any version"
104// Only the first item is strictly required.
105createToken('XRANGEIDENTIFIERLOOSE', `${src[t.NUMERICIDENTIFIERLOOSE]}|x|X|\\*`)
106createToken('XRANGEIDENTIFIER', `${src[t.NUMERICIDENTIFIER]}|x|X|\\*`)
107
108createToken('XRANGEPLAIN', `[v=\\s]*(${src[t.XRANGEIDENTIFIER]})` +
109 `(?:\\.(${src[t.XRANGEIDENTIFIER]})` +
110 `(?:\\.(${src[t.XRANGEIDENTIFIER]})` +
111 `(?:${src[t.PRERELEASE]})?${
112 src[t.BUILD]}?` +
113 `)?)?`)
114
115createToken('XRANGEPLAINLOOSE', `[v=\\s]*(${src[t.XRANGEIDENTIFIERLOOSE]})` +
116 `(?:\\.(${src[t.XRANGEIDENTIFIERLOOSE]})` +
117 `(?:\\.(${src[t.XRANGEIDENTIFIERLOOSE]})` +
118 `(?:${src[t.PRERELEASELOOSE]})?${
119 src[t.BUILD]}?` +
120 `)?)?`)
121
122createToken('XRANGE', `^${src[t.GTLT]}\\s*${src[t.XRANGEPLAIN]}$`)
123createToken('XRANGELOOSE', `^${src[t.GTLT]}\\s*${src[t.XRANGEPLAINLOOSE]}$`)
124
125// Coercion.
126// Extract anything that could conceivably be a part of a valid semver
127createToken('COERCE', `${'(^|[^\\d])' +
128 '(\\d{1,'}${MAX_SAFE_COMPONENT_LENGTH}})` +
129 `(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?` +
130 `(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?` +
131 `(?:$|[^\\d])`)
132createToken('COERCERTL', src[t.COERCE], true)
133
134// Tilde ranges.
135// Meaning is "reasonably at or greater than"
136createToken('LONETILDE', '(?:~>?)')
137
138createToken('TILDETRIM', `(\\s*)${src[t.LONETILDE]}\\s+`, true)
139exports.tildeTrimReplace = '$1~'
140
141createToken('TILDE', `^${src[t.LONETILDE]}${src[t.XRANGEPLAIN]}$`)
142createToken('TILDELOOSE', `^${src[t.LONETILDE]}${src[t.XRANGEPLAINLOOSE]}$`)
143
144// Caret ranges.
145// Meaning is "at least and backwards compatible with"
146createToken('LONECARET', '(?:\\^)')
147
148createToken('CARETTRIM', `(\\s*)${src[t.LONECARET]}\\s+`, true)
149exports.caretTrimReplace = '$1^'
150
151createToken('CARET', `^${src[t.LONECARET]}${src[t.XRANGEPLAIN]}$`)
152createToken('CARETLOOSE', `^${src[t.LONECARET]}${src[t.XRANGEPLAINLOOSE]}$`)
153
154// A simple gt/lt/eq thing, or just "" to indicate "any version"
155createToken('COMPARATORLOOSE', `^${src[t.GTLT]}\\s*(${src[t.LOOSEPLAIN]})$|^$`)
156createToken('COMPARATOR', `^${src[t.GTLT]}\\s*(${src[t.FULLPLAIN]})$|^$`)
157
158// An expression to strip any whitespace between the gtlt and the thing
159// it modifies, so that `> 1.2.3` ==> `>1.2.3`
160createToken('COMPARATORTRIM', `(\\s*)${src[t.GTLT]
161}\\s*(${src[t.LOOSEPLAIN]}|${src[t.XRANGEPLAIN]})`, true)
162exports.comparatorTrimReplace = '$1$2$3'
163
164// Something like `1.2.3 - 1.2.4`
165// Note that these all use the loose form, because they'll be
166// checked against either the strict or loose comparator form
167// later.
168createToken('HYPHENRANGE', `^\\s*(${src[t.XRANGEPLAIN]})` +
169 `\\s+-\\s+` +
170 `(${src[t.XRANGEPLAIN]})` +
171 `\\s*$`)
172
173createToken('HYPHENRANGELOOSE', `^\\s*(${src[t.XRANGEPLAINLOOSE]})` +
174 `\\s+-\\s+` +
175 `(${src[t.XRANGEPLAINLOOSE]})` +
176 `\\s*$`)
177
178// Star ranges basically just allow anything at all.
179createToken('STAR', '(<|>)?=?\\s*\\*')
180// >=0.0.0 is like a star
181createToken('GTE0', '^\\s*>=\\s*0\.0\.0\\s*$')
182createToken('GTE0PRE', '^\\s*>=\\s*0\.0\.0-0\\s*$')
Note: See TracBrowser for help on using the repository browser.