semver 6.2.0 → 7.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/README.md +58 -2
  3. package/bin/semver.js +78 -79
  4. package/classes/comparator.js +139 -0
  5. package/classes/index.js +5 -0
  6. package/classes/range.js +448 -0
  7. package/classes/semver.js +290 -0
  8. package/functions/clean.js +6 -0
  9. package/functions/cmp.js +48 -0
  10. package/functions/coerce.js +51 -0
  11. package/functions/compare-build.js +7 -0
  12. package/functions/compare-loose.js +3 -0
  13. package/functions/compare.js +5 -0
  14. package/functions/diff.js +25 -0
  15. package/functions/eq.js +3 -0
  16. package/functions/gt.js +3 -0
  17. package/functions/gte.js +3 -0
  18. package/functions/inc.js +15 -0
  19. package/functions/lt.js +3 -0
  20. package/functions/lte.js +3 -0
  21. package/functions/major.js +3 -0
  22. package/functions/minor.js +3 -0
  23. package/functions/neq.js +3 -0
  24. package/functions/parse.js +37 -0
  25. package/functions/patch.js +3 -0
  26. package/functions/prerelease.js +6 -0
  27. package/functions/rcompare.js +3 -0
  28. package/functions/rsort.js +3 -0
  29. package/functions/satisfies.js +10 -0
  30. package/functions/sort.js +3 -0
  31. package/functions/valid.js +6 -0
  32. package/index.js +64 -0
  33. package/internal/constants.js +17 -0
  34. package/internal/debug.js +9 -0
  35. package/internal/identifiers.js +23 -0
  36. package/internal/re.js +179 -0
  37. package/package.json +15 -5
  38. package/preload.js +46 -0
  39. package/ranges/gtr.js +4 -0
  40. package/ranges/intersects.js +7 -0
  41. package/ranges/ltr.js +4 -0
  42. package/ranges/max-satisfying.js +25 -0
  43. package/ranges/min-satisfying.js +24 -0
  44. package/ranges/min-version.js +57 -0
  45. package/ranges/outside.js +80 -0
  46. package/ranges/to-comparators.js +8 -0
  47. package/ranges/valid.js +11 -0
  48. package/bin/.semver.js.swp +0 -0
  49. package/semver.js +0 -1589
package/semver.js DELETED
@@ -1,1589 +0,0 @@
1
- exports = module.exports = SemVer
2
-
3
- var debug
4
- /* istanbul ignore next */
5
- if (typeof process === 'object' &&
6
- process.env &&
7
- process.env.NODE_DEBUG &&
8
- /\bsemver\b/i.test(process.env.NODE_DEBUG)) {
9
- debug = function () {
10
- var args = Array.prototype.slice.call(arguments, 0)
11
- args.unshift('SEMVER')
12
- console.log.apply(console, args)
13
- }
14
- } else {
15
- debug = function () {}
16
- }
17
-
18
- // Note: this is the semver.org version of the spec that it implements
19
- // Not necessarily the package version of this code.
20
- exports.SEMVER_SPEC_VERSION = '2.0.0'
21
-
22
- var MAX_LENGTH = 256
23
- var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER ||
24
- /* istanbul ignore next */ 9007199254740991
25
-
26
- // Max safe segment length for coercion.
27
- var MAX_SAFE_COMPONENT_LENGTH = 16
28
-
29
- // The actual regexps go on exports.re
30
- var re = exports.re = []
31
- var src = exports.src = []
32
- var R = 0
33
-
34
- // The following Regular Expressions can be used for tokenizing,
35
- // validating, and parsing SemVer version strings.
36
-
37
- // ## Numeric Identifier
38
- // A single `0`, or a non-zero digit followed by zero or more digits.
39
-
40
- var NUMERICIDENTIFIER = R++
41
- src[NUMERICIDENTIFIER] = '0|[1-9]\\d*'
42
- var NUMERICIDENTIFIERLOOSE = R++
43
- src[NUMERICIDENTIFIERLOOSE] = '[0-9]+'
44
-
45
- // ## Non-numeric Identifier
46
- // Zero or more digits, followed by a letter or hyphen, and then zero or
47
- // more letters, digits, or hyphens.
48
-
49
- var NONNUMERICIDENTIFIER = R++
50
- src[NONNUMERICIDENTIFIER] = '\\d*[a-zA-Z-][a-zA-Z0-9-]*'
51
-
52
- // ## Main Version
53
- // Three dot-separated numeric identifiers.
54
-
55
- var MAINVERSION = R++
56
- src[MAINVERSION] = '(' + src[NUMERICIDENTIFIER] + ')\\.' +
57
- '(' + src[NUMERICIDENTIFIER] + ')\\.' +
58
- '(' + src[NUMERICIDENTIFIER] + ')'
59
-
60
- var MAINVERSIONLOOSE = R++
61
- src[MAINVERSIONLOOSE] = '(' + src[NUMERICIDENTIFIERLOOSE] + ')\\.' +
62
- '(' + src[NUMERICIDENTIFIERLOOSE] + ')\\.' +
63
- '(' + src[NUMERICIDENTIFIERLOOSE] + ')'
64
-
65
- // ## Pre-release Version Identifier
66
- // A numeric identifier, or a non-numeric identifier.
67
-
68
- var PRERELEASEIDENTIFIER = R++
69
- src[PRERELEASEIDENTIFIER] = '(?:' + src[NUMERICIDENTIFIER] +
70
- '|' + src[NONNUMERICIDENTIFIER] + ')'
71
-
72
- var PRERELEASEIDENTIFIERLOOSE = R++
73
- src[PRERELEASEIDENTIFIERLOOSE] = '(?:' + src[NUMERICIDENTIFIERLOOSE] +
74
- '|' + src[NONNUMERICIDENTIFIER] + ')'
75
-
76
- // ## Pre-release Version
77
- // Hyphen, followed by one or more dot-separated pre-release version
78
- // identifiers.
79
-
80
- var PRERELEASE = R++
81
- src[PRERELEASE] = '(?:-(' + src[PRERELEASEIDENTIFIER] +
82
- '(?:\\.' + src[PRERELEASEIDENTIFIER] + ')*))'
83
-
84
- var PRERELEASELOOSE = R++
85
- src[PRERELEASELOOSE] = '(?:-?(' + src[PRERELEASEIDENTIFIERLOOSE] +
86
- '(?:\\.' + src[PRERELEASEIDENTIFIERLOOSE] + ')*))'
87
-
88
- // ## Build Metadata Identifier
89
- // Any combination of digits, letters, or hyphens.
90
-
91
- var BUILDIDENTIFIER = R++
92
- src[BUILDIDENTIFIER] = '[0-9A-Za-z-]+'
93
-
94
- // ## Build Metadata
95
- // Plus sign, followed by one or more period-separated build metadata
96
- // identifiers.
97
-
98
- var BUILD = R++
99
- src[BUILD] = '(?:\\+(' + src[BUILDIDENTIFIER] +
100
- '(?:\\.' + src[BUILDIDENTIFIER] + ')*))'
101
-
102
- // ## Full Version String
103
- // A main version, followed optionally by a pre-release version and
104
- // build metadata.
105
-
106
- // Note that the only major, minor, patch, and pre-release sections of
107
- // the version string are capturing groups. The build metadata is not a
108
- // capturing group, because it should not ever be used in version
109
- // comparison.
110
-
111
- var FULL = R++
112
- var FULLPLAIN = 'v?' + src[MAINVERSION] +
113
- src[PRERELEASE] + '?' +
114
- src[BUILD] + '?'
115
-
116
- src[FULL] = '^' + FULLPLAIN + '$'
117
-
118
- // like full, but allows v1.2.3 and =1.2.3, which people do sometimes.
119
- // also, 1.0.0alpha1 (prerelease without the hyphen) which is pretty
120
- // common in the npm registry.
121
- var LOOSEPLAIN = '[v=\\s]*' + src[MAINVERSIONLOOSE] +
122
- src[PRERELEASELOOSE] + '?' +
123
- src[BUILD] + '?'
124
-
125
- var LOOSE = R++
126
- src[LOOSE] = '^' + LOOSEPLAIN + '$'
127
-
128
- var GTLT = R++
129
- src[GTLT] = '((?:<|>)?=?)'
130
-
131
- // Something like "2.*" or "1.2.x".
132
- // Note that "x.x" is a valid xRange identifer, meaning "any version"
133
- // Only the first item is strictly required.
134
- var XRANGEIDENTIFIERLOOSE = R++
135
- src[XRANGEIDENTIFIERLOOSE] = src[NUMERICIDENTIFIERLOOSE] + '|x|X|\\*'
136
- var XRANGEIDENTIFIER = R++
137
- src[XRANGEIDENTIFIER] = src[NUMERICIDENTIFIER] + '|x|X|\\*'
138
-
139
- var XRANGEPLAIN = R++
140
- src[XRANGEPLAIN] = '[v=\\s]*(' + src[XRANGEIDENTIFIER] + ')' +
141
- '(?:\\.(' + src[XRANGEIDENTIFIER] + ')' +
142
- '(?:\\.(' + src[XRANGEIDENTIFIER] + ')' +
143
- '(?:' + src[PRERELEASE] + ')?' +
144
- src[BUILD] + '?' +
145
- ')?)?'
146
-
147
- var XRANGEPLAINLOOSE = R++
148
- src[XRANGEPLAINLOOSE] = '[v=\\s]*(' + src[XRANGEIDENTIFIERLOOSE] + ')' +
149
- '(?:\\.(' + src[XRANGEIDENTIFIERLOOSE] + ')' +
150
- '(?:\\.(' + src[XRANGEIDENTIFIERLOOSE] + ')' +
151
- '(?:' + src[PRERELEASELOOSE] + ')?' +
152
- src[BUILD] + '?' +
153
- ')?)?'
154
-
155
- var XRANGE = R++
156
- src[XRANGE] = '^' + src[GTLT] + '\\s*' + src[XRANGEPLAIN] + '$'
157
- var XRANGELOOSE = R++
158
- src[XRANGELOOSE] = '^' + src[GTLT] + '\\s*' + src[XRANGEPLAINLOOSE] + '$'
159
-
160
- // Coercion.
161
- // Extract anything that could conceivably be a part of a valid semver
162
- var COERCE = R++
163
- src[COERCE] = '(^|[^\\d])' +
164
- '(\\d{1,' + MAX_SAFE_COMPONENT_LENGTH + '})' +
165
- '(?:\\.(\\d{1,' + MAX_SAFE_COMPONENT_LENGTH + '}))?' +
166
- '(?:\\.(\\d{1,' + MAX_SAFE_COMPONENT_LENGTH + '}))?' +
167
- '(?:$|[^\\d])'
168
- var COERCERTL = R++
169
- re[COERCERTL] = new RegExp(src[COERCE], 'g')
170
-
171
- // Tilde ranges.
172
- // Meaning is "reasonably at or greater than"
173
- var LONETILDE = R++
174
- src[LONETILDE] = '(?:~>?)'
175
-
176
- var TILDETRIM = R++
177
- src[TILDETRIM] = '(\\s*)' + src[LONETILDE] + '\\s+'
178
- re[TILDETRIM] = new RegExp(src[TILDETRIM], 'g')
179
- var tildeTrimReplace = '$1~'
180
-
181
- var TILDE = R++
182
- src[TILDE] = '^' + src[LONETILDE] + src[XRANGEPLAIN] + '$'
183
- var TILDELOOSE = R++
184
- src[TILDELOOSE] = '^' + src[LONETILDE] + src[XRANGEPLAINLOOSE] + '$'
185
-
186
- // Caret ranges.
187
- // Meaning is "at least and backwards compatible with"
188
- var LONECARET = R++
189
- src[LONECARET] = '(?:\\^)'
190
-
191
- var CARETTRIM = R++
192
- src[CARETTRIM] = '(\\s*)' + src[LONECARET] + '\\s+'
193
- re[CARETTRIM] = new RegExp(src[CARETTRIM], 'g')
194
- var caretTrimReplace = '$1^'
195
-
196
- var CARET = R++
197
- src[CARET] = '^' + src[LONECARET] + src[XRANGEPLAIN] + '$'
198
- var CARETLOOSE = R++
199
- src[CARETLOOSE] = '^' + src[LONECARET] + src[XRANGEPLAINLOOSE] + '$'
200
-
201
- // A simple gt/lt/eq thing, or just "" to indicate "any version"
202
- var COMPARATORLOOSE = R++
203
- src[COMPARATORLOOSE] = '^' + src[GTLT] + '\\s*(' + LOOSEPLAIN + ')$|^$'
204
- var COMPARATOR = R++
205
- src[COMPARATOR] = '^' + src[GTLT] + '\\s*(' + FULLPLAIN + ')$|^$'
206
-
207
- // An expression to strip any whitespace between the gtlt and the thing
208
- // it modifies, so that `> 1.2.3` ==> `>1.2.3`
209
- var COMPARATORTRIM = R++
210
- src[COMPARATORTRIM] = '(\\s*)' + src[GTLT] +
211
- '\\s*(' + LOOSEPLAIN + '|' + src[XRANGEPLAIN] + ')'
212
-
213
- // this one has to use the /g flag
214
- re[COMPARATORTRIM] = new RegExp(src[COMPARATORTRIM], 'g')
215
- var comparatorTrimReplace = '$1$2$3'
216
-
217
- // Something like `1.2.3 - 1.2.4`
218
- // Note that these all use the loose form, because they'll be
219
- // checked against either the strict or loose comparator form
220
- // later.
221
- var HYPHENRANGE = R++
222
- src[HYPHENRANGE] = '^\\s*(' + src[XRANGEPLAIN] + ')' +
223
- '\\s+-\\s+' +
224
- '(' + src[XRANGEPLAIN] + ')' +
225
- '\\s*$'
226
-
227
- var HYPHENRANGELOOSE = R++
228
- src[HYPHENRANGELOOSE] = '^\\s*(' + src[XRANGEPLAINLOOSE] + ')' +
229
- '\\s+-\\s+' +
230
- '(' + src[XRANGEPLAINLOOSE] + ')' +
231
- '\\s*$'
232
-
233
- // Star ranges basically just allow anything at all.
234
- var STAR = R++
235
- src[STAR] = '(<|>)?=?\\s*\\*'
236
-
237
- // Compile to actual regexp objects.
238
- // All are flag-free, unless they were created above with a flag.
239
- for (var i = 0; i < R; i++) {
240
- debug(i, src[i])
241
- if (!re[i]) {
242
- re[i] = new RegExp(src[i])
243
- }
244
- }
245
-
246
- exports.parse = parse
247
- function parse (version, options) {
248
- if (!options || typeof options !== 'object') {
249
- options = {
250
- loose: !!options,
251
- includePrerelease: false
252
- }
253
- }
254
-
255
- if (version instanceof SemVer) {
256
- return version
257
- }
258
-
259
- if (typeof version !== 'string') {
260
- return null
261
- }
262
-
263
- if (version.length > MAX_LENGTH) {
264
- return null
265
- }
266
-
267
- var r = options.loose ? re[LOOSE] : re[FULL]
268
- if (!r.test(version)) {
269
- return null
270
- }
271
-
272
- try {
273
- return new SemVer(version, options)
274
- } catch (er) {
275
- return null
276
- }
277
- }
278
-
279
- exports.valid = valid
280
- function valid (version, options) {
281
- var v = parse(version, options)
282
- return v ? v.version : null
283
- }
284
-
285
- exports.clean = clean
286
- function clean (version, options) {
287
- var s = parse(version.trim().replace(/^[=v]+/, ''), options)
288
- return s ? s.version : null
289
- }
290
-
291
- exports.SemVer = SemVer
292
-
293
- function SemVer (version, options) {
294
- if (!options || typeof options !== 'object') {
295
- options = {
296
- loose: !!options,
297
- includePrerelease: false
298
- }
299
- }
300
- if (version instanceof SemVer) {
301
- if (version.loose === options.loose) {
302
- return version
303
- } else {
304
- version = version.version
305
- }
306
- } else if (typeof version !== 'string') {
307
- throw new TypeError('Invalid Version: ' + version)
308
- }
309
-
310
- if (version.length > MAX_LENGTH) {
311
- throw new TypeError('version is longer than ' + MAX_LENGTH + ' characters')
312
- }
313
-
314
- if (!(this instanceof SemVer)) {
315
- return new SemVer(version, options)
316
- }
317
-
318
- debug('SemVer', version, options)
319
- this.options = options
320
- this.loose = !!options.loose
321
-
322
- var m = version.trim().match(options.loose ? re[LOOSE] : re[FULL])
323
-
324
- if (!m) {
325
- throw new TypeError('Invalid Version: ' + version)
326
- }
327
-
328
- this.raw = version
329
-
330
- // these are actually numbers
331
- this.major = +m[1]
332
- this.minor = +m[2]
333
- this.patch = +m[3]
334
-
335
- if (this.major > MAX_SAFE_INTEGER || this.major < 0) {
336
- throw new TypeError('Invalid major version')
337
- }
338
-
339
- if (this.minor > MAX_SAFE_INTEGER || this.minor < 0) {
340
- throw new TypeError('Invalid minor version')
341
- }
342
-
343
- if (this.patch > MAX_SAFE_INTEGER || this.patch < 0) {
344
- throw new TypeError('Invalid patch version')
345
- }
346
-
347
- // numberify any prerelease numeric ids
348
- if (!m[4]) {
349
- this.prerelease = []
350
- } else {
351
- this.prerelease = m[4].split('.').map(function (id) {
352
- if (/^[0-9]+$/.test(id)) {
353
- var num = +id
354
- if (num >= 0 && num < MAX_SAFE_INTEGER) {
355
- return num
356
- }
357
- }
358
- return id
359
- })
360
- }
361
-
362
- this.build = m[5] ? m[5].split('.') : []
363
- this.format()
364
- }
365
-
366
- SemVer.prototype.format = function () {
367
- this.version = this.major + '.' + this.minor + '.' + this.patch
368
- if (this.prerelease.length) {
369
- this.version += '-' + this.prerelease.join('.')
370
- }
371
- return this.version
372
- }
373
-
374
- SemVer.prototype.toString = function () {
375
- return this.version
376
- }
377
-
378
- SemVer.prototype.compare = function (other) {
379
- debug('SemVer.compare', this.version, this.options, other)
380
- if (!(other instanceof SemVer)) {
381
- other = new SemVer(other, this.options)
382
- }
383
-
384
- return this.compareMain(other) || this.comparePre(other)
385
- }
386
-
387
- SemVer.prototype.compareMain = function (other) {
388
- if (!(other instanceof SemVer)) {
389
- other = new SemVer(other, this.options)
390
- }
391
-
392
- return compareIdentifiers(this.major, other.major) ||
393
- compareIdentifiers(this.minor, other.minor) ||
394
- compareIdentifiers(this.patch, other.patch)
395
- }
396
-
397
- SemVer.prototype.comparePre = function (other) {
398
- if (!(other instanceof SemVer)) {
399
- other = new SemVer(other, this.options)
400
- }
401
-
402
- // NOT having a prerelease is > having one
403
- if (this.prerelease.length && !other.prerelease.length) {
404
- return -1
405
- } else if (!this.prerelease.length && other.prerelease.length) {
406
- return 1
407
- } else if (!this.prerelease.length && !other.prerelease.length) {
408
- return 0
409
- }
410
-
411
- var i = 0
412
- do {
413
- var a = this.prerelease[i]
414
- var b = other.prerelease[i]
415
- debug('prerelease compare', i, a, b)
416
- if (a === undefined && b === undefined) {
417
- return 0
418
- } else if (b === undefined) {
419
- return 1
420
- } else if (a === undefined) {
421
- return -1
422
- } else if (a === b) {
423
- continue
424
- } else {
425
- return compareIdentifiers(a, b)
426
- }
427
- } while (++i)
428
- }
429
-
430
- SemVer.prototype.compareBuild = function (other) {
431
- if (!(other instanceof SemVer)) {
432
- other = new SemVer(other, this.options)
433
- }
434
-
435
- var i = 0
436
- do {
437
- var a = this.build[i]
438
- var b = other.build[i]
439
- debug('prerelease compare', i, a, b)
440
- if (a === undefined && b === undefined) {
441
- return 0
442
- } else if (b === undefined) {
443
- return 1
444
- } else if (a === undefined) {
445
- return -1
446
- } else if (a === b) {
447
- continue
448
- } else {
449
- return compareIdentifiers(a, b)
450
- }
451
- } while (++i)
452
- }
453
-
454
- // preminor will bump the version up to the next minor release, and immediately
455
- // down to pre-release. premajor and prepatch work the same way.
456
- SemVer.prototype.inc = function (release, identifier) {
457
- switch (release) {
458
- case 'premajor':
459
- this.prerelease.length = 0
460
- this.patch = 0
461
- this.minor = 0
462
- this.major++
463
- this.inc('pre', identifier)
464
- break
465
- case 'preminor':
466
- this.prerelease.length = 0
467
- this.patch = 0
468
- this.minor++
469
- this.inc('pre', identifier)
470
- break
471
- case 'prepatch':
472
- // If this is already a prerelease, it will bump to the next version
473
- // drop any prereleases that might already exist, since they are not
474
- // relevant at this point.
475
- this.prerelease.length = 0
476
- this.inc('patch', identifier)
477
- this.inc('pre', identifier)
478
- break
479
- // If the input is a non-prerelease version, this acts the same as
480
- // prepatch.
481
- case 'prerelease':
482
- if (this.prerelease.length === 0) {
483
- this.inc('patch', identifier)
484
- }
485
- this.inc('pre', identifier)
486
- break
487
-
488
- case 'major':
489
- // If this is a pre-major version, bump up to the same major version.
490
- // Otherwise increment major.
491
- // 1.0.0-5 bumps to 1.0.0
492
- // 1.1.0 bumps to 2.0.0
493
- if (this.minor !== 0 ||
494
- this.patch !== 0 ||
495
- this.prerelease.length === 0) {
496
- this.major++
497
- }
498
- this.minor = 0
499
- this.patch = 0
500
- this.prerelease = []
501
- break
502
- case 'minor':
503
- // If this is a pre-minor version, bump up to the same minor version.
504
- // Otherwise increment minor.
505
- // 1.2.0-5 bumps to 1.2.0
506
- // 1.2.1 bumps to 1.3.0
507
- if (this.patch !== 0 || this.prerelease.length === 0) {
508
- this.minor++
509
- }
510
- this.patch = 0
511
- this.prerelease = []
512
- break
513
- case 'patch':
514
- // If this is not a pre-release version, it will increment the patch.
515
- // If it is a pre-release it will bump up to the same patch version.
516
- // 1.2.0-5 patches to 1.2.0
517
- // 1.2.0 patches to 1.2.1
518
- if (this.prerelease.length === 0) {
519
- this.patch++
520
- }
521
- this.prerelease = []
522
- break
523
- // This probably shouldn't be used publicly.
524
- // 1.0.0 "pre" would become 1.0.0-0 which is the wrong direction.
525
- case 'pre':
526
- if (this.prerelease.length === 0) {
527
- this.prerelease = [0]
528
- } else {
529
- var i = this.prerelease.length
530
- while (--i >= 0) {
531
- if (typeof this.prerelease[i] === 'number') {
532
- this.prerelease[i]++
533
- i = -2
534
- }
535
- }
536
- if (i === -1) {
537
- // didn't increment anything
538
- this.prerelease.push(0)
539
- }
540
- }
541
- if (identifier) {
542
- // 1.2.0-beta.1 bumps to 1.2.0-beta.2,
543
- // 1.2.0-beta.fooblz or 1.2.0-beta bumps to 1.2.0-beta.0
544
- if (this.prerelease[0] === identifier) {
545
- if (isNaN(this.prerelease[1])) {
546
- this.prerelease = [identifier, 0]
547
- }
548
- } else {
549
- this.prerelease = [identifier, 0]
550
- }
551
- }
552
- break
553
-
554
- default:
555
- throw new Error('invalid increment argument: ' + release)
556
- }
557
- this.format()
558
- this.raw = this.version
559
- return this
560
- }
561
-
562
- exports.inc = inc
563
- function inc (version, release, loose, identifier) {
564
- if (typeof (loose) === 'string') {
565
- identifier = loose
566
- loose = undefined
567
- }
568
-
569
- try {
570
- return new SemVer(version, loose).inc(release, identifier).version
571
- } catch (er) {
572
- return null
573
- }
574
- }
575
-
576
- exports.diff = diff
577
- function diff (version1, version2) {
578
- if (eq(version1, version2)) {
579
- return null
580
- } else {
581
- var v1 = parse(version1)
582
- var v2 = parse(version2)
583
- var prefix = ''
584
- if (v1.prerelease.length || v2.prerelease.length) {
585
- prefix = 'pre'
586
- var defaultResult = 'prerelease'
587
- }
588
- for (var key in v1) {
589
- if (key === 'major' || key === 'minor' || key === 'patch') {
590
- if (v1[key] !== v2[key]) {
591
- return prefix + key
592
- }
593
- }
594
- }
595
- return defaultResult // may be undefined
596
- }
597
- }
598
-
599
- exports.compareIdentifiers = compareIdentifiers
600
-
601
- var numeric = /^[0-9]+$/
602
- function compareIdentifiers (a, b) {
603
- var anum = numeric.test(a)
604
- var bnum = numeric.test(b)
605
-
606
- if (anum && bnum) {
607
- a = +a
608
- b = +b
609
- }
610
-
611
- return a === b ? 0
612
- : (anum && !bnum) ? -1
613
- : (bnum && !anum) ? 1
614
- : a < b ? -1
615
- : 1
616
- }
617
-
618
- exports.rcompareIdentifiers = rcompareIdentifiers
619
- function rcompareIdentifiers (a, b) {
620
- return compareIdentifiers(b, a)
621
- }
622
-
623
- exports.major = major
624
- function major (a, loose) {
625
- return new SemVer(a, loose).major
626
- }
627
-
628
- exports.minor = minor
629
- function minor (a, loose) {
630
- return new SemVer(a, loose).minor
631
- }
632
-
633
- exports.patch = patch
634
- function patch (a, loose) {
635
- return new SemVer(a, loose).patch
636
- }
637
-
638
- exports.compare = compare
639
- function compare (a, b, loose) {
640
- return new SemVer(a, loose).compare(new SemVer(b, loose))
641
- }
642
-
643
- exports.compareLoose = compareLoose
644
- function compareLoose (a, b) {
645
- return compare(a, b, true)
646
- }
647
-
648
- exports.compareBuild = compareBuild
649
- function compareBuild (a, b, loose) {
650
- var versionA = new SemVer(a, loose)
651
- var versionB = new SemVer(b, loose)
652
- return versionA.compare(versionB) || versionA.compareBuild(versionB)
653
- }
654
-
655
- exports.rcompare = rcompare
656
- function rcompare (a, b, loose) {
657
- return compare(b, a, loose)
658
- }
659
-
660
- exports.sort = sort
661
- function sort (list, loose) {
662
- return list.sort(function (a, b) {
663
- return exports.compareBuild(a, b, loose)
664
- })
665
- }
666
-
667
- exports.rsort = rsort
668
- function rsort (list, loose) {
669
- return list.sort(function (a, b) {
670
- return exports.compareBuild(b, a, loose)
671
- })
672
- }
673
-
674
- exports.gt = gt
675
- function gt (a, b, loose) {
676
- return compare(a, b, loose) > 0
677
- }
678
-
679
- exports.lt = lt
680
- function lt (a, b, loose) {
681
- return compare(a, b, loose) < 0
682
- }
683
-
684
- exports.eq = eq
685
- function eq (a, b, loose) {
686
- return compare(a, b, loose) === 0
687
- }
688
-
689
- exports.neq = neq
690
- function neq (a, b, loose) {
691
- return compare(a, b, loose) !== 0
692
- }
693
-
694
- exports.gte = gte
695
- function gte (a, b, loose) {
696
- return compare(a, b, loose) >= 0
697
- }
698
-
699
- exports.lte = lte
700
- function lte (a, b, loose) {
701
- return compare(a, b, loose) <= 0
702
- }
703
-
704
- exports.cmp = cmp
705
- function cmp (a, op, b, loose) {
706
- switch (op) {
707
- case '===':
708
- if (typeof a === 'object')
709
- a = a.version
710
- if (typeof b === 'object')
711
- b = b.version
712
- return a === b
713
-
714
- case '!==':
715
- if (typeof a === 'object')
716
- a = a.version
717
- if (typeof b === 'object')
718
- b = b.version
719
- return a !== b
720
-
721
- case '':
722
- case '=':
723
- case '==':
724
- return eq(a, b, loose)
725
-
726
- case '!=':
727
- return neq(a, b, loose)
728
-
729
- case '>':
730
- return gt(a, b, loose)
731
-
732
- case '>=':
733
- return gte(a, b, loose)
734
-
735
- case '<':
736
- return lt(a, b, loose)
737
-
738
- case '<=':
739
- return lte(a, b, loose)
740
-
741
- default:
742
- throw new TypeError('Invalid operator: ' + op)
743
- }
744
- }
745
-
746
- exports.Comparator = Comparator
747
- function Comparator (comp, options) {
748
- if (!options || typeof options !== 'object') {
749
- options = {
750
- loose: !!options,
751
- includePrerelease: false
752
- }
753
- }
754
-
755
- if (comp instanceof Comparator) {
756
- if (comp.loose === !!options.loose) {
757
- return comp
758
- } else {
759
- comp = comp.value
760
- }
761
- }
762
-
763
- if (!(this instanceof Comparator)) {
764
- return new Comparator(comp, options)
765
- }
766
-
767
- debug('comparator', comp, options)
768
- this.options = options
769
- this.loose = !!options.loose
770
- this.parse(comp)
771
-
772
- if (this.semver === ANY) {
773
- this.value = ''
774
- } else {
775
- this.value = this.operator + this.semver.version
776
- }
777
-
778
- debug('comp', this)
779
- }
780
-
781
- var ANY = {}
782
- Comparator.prototype.parse = function (comp) {
783
- var r = this.options.loose ? re[COMPARATORLOOSE] : re[COMPARATOR]
784
- var m = comp.match(r)
785
-
786
- if (!m) {
787
- throw new TypeError('Invalid comparator: ' + comp)
788
- }
789
-
790
- this.operator = m[1] !== undefined ? m[1] : ''
791
- if (this.operator === '=') {
792
- this.operator = ''
793
- }
794
-
795
- // if it literally is just '>' or '' then allow anything.
796
- if (!m[2]) {
797
- this.semver = ANY
798
- } else {
799
- this.semver = new SemVer(m[2], this.options.loose)
800
- }
801
- }
802
-
803
- Comparator.prototype.toString = function () {
804
- return this.value
805
- }
806
-
807
- Comparator.prototype.test = function (version) {
808
- debug('Comparator.test', version, this.options.loose)
809
-
810
- if (this.semver === ANY || version === ANY) {
811
- return true
812
- }
813
-
814
- if (typeof version === 'string') {
815
- try {
816
- version = new SemVer(version, this.options)
817
- } catch (er) {
818
- return false
819
- }
820
- }
821
-
822
- return cmp(version, this.operator, this.semver, this.options)
823
- }
824
-
825
- Comparator.prototype.intersects = function (comp, options) {
826
- if (!(comp instanceof Comparator)) {
827
- throw new TypeError('a Comparator is required')
828
- }
829
-
830
- if (!options || typeof options !== 'object') {
831
- options = {
832
- loose: !!options,
833
- includePrerelease: false
834
- }
835
- }
836
-
837
- var rangeTmp
838
-
839
- if (this.operator === '') {
840
- if (this.value === '') {
841
- return true
842
- }
843
- rangeTmp = new Range(comp.value, options)
844
- return satisfies(this.value, rangeTmp, options)
845
- } else if (comp.operator === '') {
846
- if (comp.value === '') {
847
- return true
848
- }
849
- rangeTmp = new Range(this.value, options)
850
- return satisfies(comp.semver, rangeTmp, options)
851
- }
852
-
853
- var sameDirectionIncreasing =
854
- (this.operator === '>=' || this.operator === '>') &&
855
- (comp.operator === '>=' || comp.operator === '>')
856
- var sameDirectionDecreasing =
857
- (this.operator === '<=' || this.operator === '<') &&
858
- (comp.operator === '<=' || comp.operator === '<')
859
- var sameSemVer = this.semver.version === comp.semver.version
860
- var differentDirectionsInclusive =
861
- (this.operator === '>=' || this.operator === '<=') &&
862
- (comp.operator === '>=' || comp.operator === '<=')
863
- var oppositeDirectionsLessThan =
864
- cmp(this.semver, '<', comp.semver, options) &&
865
- ((this.operator === '>=' || this.operator === '>') &&
866
- (comp.operator === '<=' || comp.operator === '<'))
867
- var oppositeDirectionsGreaterThan =
868
- cmp(this.semver, '>', comp.semver, options) &&
869
- ((this.operator === '<=' || this.operator === '<') &&
870
- (comp.operator === '>=' || comp.operator === '>'))
871
-
872
- return sameDirectionIncreasing || sameDirectionDecreasing ||
873
- (sameSemVer && differentDirectionsInclusive) ||
874
- oppositeDirectionsLessThan || oppositeDirectionsGreaterThan
875
- }
876
-
877
- exports.Range = Range
878
- function Range (range, options) {
879
- if (!options || typeof options !== 'object') {
880
- options = {
881
- loose: !!options,
882
- includePrerelease: false
883
- }
884
- }
885
-
886
- if (range instanceof Range) {
887
- if (range.loose === !!options.loose &&
888
- range.includePrerelease === !!options.includePrerelease) {
889
- return range
890
- } else {
891
- return new Range(range.raw, options)
892
- }
893
- }
894
-
895
- if (range instanceof Comparator) {
896
- return new Range(range.value, options)
897
- }
898
-
899
- if (!(this instanceof Range)) {
900
- return new Range(range, options)
901
- }
902
-
903
- this.options = options
904
- this.loose = !!options.loose
905
- this.includePrerelease = !!options.includePrerelease
906
-
907
- // First, split based on boolean or ||
908
- this.raw = range
909
- this.set = range.split(/\s*\|\|\s*/).map(function (range) {
910
- return this.parseRange(range.trim())
911
- }, this).filter(function (c) {
912
- // throw out any that are not relevant for whatever reason
913
- return c.length
914
- })
915
-
916
- if (!this.set.length) {
917
- throw new TypeError('Invalid SemVer Range: ' + range)
918
- }
919
-
920
- this.format()
921
- }
922
-
923
- Range.prototype.format = function () {
924
- this.range = this.set.map(function (comps) {
925
- return comps.join(' ').trim()
926
- }).join('||').trim()
927
- return this.range
928
- }
929
-
930
- Range.prototype.toString = function () {
931
- return this.range
932
- }
933
-
934
- Range.prototype.parseRange = function (range) {
935
- var loose = this.options.loose
936
- range = range.trim()
937
- // `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4`
938
- var hr = loose ? re[HYPHENRANGELOOSE] : re[HYPHENRANGE]
939
- range = range.replace(hr, hyphenReplace)
940
- debug('hyphen replace', range)
941
- // `> 1.2.3 < 1.2.5` => `>1.2.3 <1.2.5`
942
- range = range.replace(re[COMPARATORTRIM], comparatorTrimReplace)
943
- debug('comparator trim', range, re[COMPARATORTRIM])
944
-
945
- // `~ 1.2.3` => `~1.2.3`
946
- range = range.replace(re[TILDETRIM], tildeTrimReplace)
947
-
948
- // `^ 1.2.3` => `^1.2.3`
949
- range = range.replace(re[CARETTRIM], caretTrimReplace)
950
-
951
- // normalize spaces
952
- range = range.split(/\s+/).join(' ')
953
-
954
- // At this point, the range is completely trimmed and
955
- // ready to be split into comparators.
956
-
957
- var compRe = loose ? re[COMPARATORLOOSE] : re[COMPARATOR]
958
- var set = range.split(' ').map(function (comp) {
959
- return parseComparator(comp, this.options)
960
- }, this).join(' ').split(/\s+/)
961
- if (this.options.loose) {
962
- // in loose mode, throw out any that are not valid comparators
963
- set = set.filter(function (comp) {
964
- return !!comp.match(compRe)
965
- })
966
- }
967
- set = set.map(function (comp) {
968
- return new Comparator(comp, this.options)
969
- }, this)
970
-
971
- return set
972
- }
973
-
974
- Range.prototype.intersects = function (range, options) {
975
- if (!(range instanceof Range)) {
976
- throw new TypeError('a Range is required')
977
- }
978
-
979
- return this.set.some(function (thisComparators) {
980
- return (
981
- isSatisfiable(thisComparators, options) &&
982
- range.set.some(function (rangeComparators) {
983
- return (
984
- isSatisfiable(rangeComparators, options) &&
985
- thisComparators.every(function (thisComparator) {
986
- return rangeComparators.every(function (rangeComparator) {
987
- return thisComparator.intersects(rangeComparator, options)
988
- })
989
- })
990
- )
991
- })
992
- )
993
- })
994
- }
995
-
996
- // take a set of comparators and determine whether there
997
- // exists a version which can satisfy it
998
- function isSatisfiable (comparators, options) {
999
- var result = true
1000
- var remainingComparators = comparators.slice()
1001
- var testComparator = remainingComparators.pop()
1002
-
1003
- while (result && remainingComparators.length) {
1004
- result = remainingComparators.every(function (otherComparator) {
1005
- return testComparator.intersects(otherComparator, options)
1006
- })
1007
-
1008
- testComparator = remainingComparators.pop()
1009
- }
1010
-
1011
- return result
1012
- }
1013
-
1014
- // Mostly just for testing and legacy API reasons
1015
- exports.toComparators = toComparators
1016
- function toComparators (range, options) {
1017
- return new Range(range, options).set.map(function (comp) {
1018
- return comp.map(function (c) {
1019
- return c.value
1020
- }).join(' ').trim().split(' ')
1021
- })
1022
- }
1023
-
1024
- // comprised of xranges, tildes, stars, and gtlt's at this point.
1025
- // already replaced the hyphen ranges
1026
- // turn into a set of JUST comparators.
1027
- function parseComparator (comp, options) {
1028
- debug('comp', comp, options)
1029
- comp = replaceCarets(comp, options)
1030
- debug('caret', comp)
1031
- comp = replaceTildes(comp, options)
1032
- debug('tildes', comp)
1033
- comp = replaceXRanges(comp, options)
1034
- debug('xrange', comp)
1035
- comp = replaceStars(comp, options)
1036
- debug('stars', comp)
1037
- return comp
1038
- }
1039
-
1040
- function isX (id) {
1041
- return !id || id.toLowerCase() === 'x' || id === '*'
1042
- }
1043
-
1044
- // ~, ~> --> * (any, kinda silly)
1045
- // ~2, ~2.x, ~2.x.x, ~>2, ~>2.x ~>2.x.x --> >=2.0.0 <3.0.0
1046
- // ~2.0, ~2.0.x, ~>2.0, ~>2.0.x --> >=2.0.0 <2.1.0
1047
- // ~1.2, ~1.2.x, ~>1.2, ~>1.2.x --> >=1.2.0 <1.3.0
1048
- // ~1.2.3, ~>1.2.3 --> >=1.2.3 <1.3.0
1049
- // ~1.2.0, ~>1.2.0 --> >=1.2.0 <1.3.0
1050
- function replaceTildes (comp, options) {
1051
- return comp.trim().split(/\s+/).map(function (comp) {
1052
- return replaceTilde(comp, options)
1053
- }).join(' ')
1054
- }
1055
-
1056
- function replaceTilde (comp, options) {
1057
- var r = options.loose ? re[TILDELOOSE] : re[TILDE]
1058
- return comp.replace(r, function (_, M, m, p, pr) {
1059
- debug('tilde', comp, _, M, m, p, pr)
1060
- var ret
1061
-
1062
- if (isX(M)) {
1063
- ret = ''
1064
- } else if (isX(m)) {
1065
- ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0'
1066
- } else if (isX(p)) {
1067
- // ~1.2 == >=1.2.0 <1.3.0
1068
- ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0'
1069
- } else if (pr) {
1070
- debug('replaceTilde pr', pr)
1071
- ret = '>=' + M + '.' + m + '.' + p + '-' + pr +
1072
- ' <' + M + '.' + (+m + 1) + '.0'
1073
- } else {
1074
- // ~1.2.3 == >=1.2.3 <1.3.0
1075
- ret = '>=' + M + '.' + m + '.' + p +
1076
- ' <' + M + '.' + (+m + 1) + '.0'
1077
- }
1078
-
1079
- debug('tilde return', ret)
1080
- return ret
1081
- })
1082
- }
1083
-
1084
- // ^ --> * (any, kinda silly)
1085
- // ^2, ^2.x, ^2.x.x --> >=2.0.0 <3.0.0
1086
- // ^2.0, ^2.0.x --> >=2.0.0 <3.0.0
1087
- // ^1.2, ^1.2.x --> >=1.2.0 <2.0.0
1088
- // ^1.2.3 --> >=1.2.3 <2.0.0
1089
- // ^1.2.0 --> >=1.2.0 <2.0.0
1090
- function replaceCarets (comp, options) {
1091
- return comp.trim().split(/\s+/).map(function (comp) {
1092
- return replaceCaret(comp, options)
1093
- }).join(' ')
1094
- }
1095
-
1096
- function replaceCaret (comp, options) {
1097
- debug('caret', comp, options)
1098
- var r = options.loose ? re[CARETLOOSE] : re[CARET]
1099
- return comp.replace(r, function (_, M, m, p, pr) {
1100
- debug('caret', comp, _, M, m, p, pr)
1101
- var ret
1102
-
1103
- if (isX(M)) {
1104
- ret = ''
1105
- } else if (isX(m)) {
1106
- ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0'
1107
- } else if (isX(p)) {
1108
- if (M === '0') {
1109
- ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0'
1110
- } else {
1111
- ret = '>=' + M + '.' + m + '.0 <' + (+M + 1) + '.0.0'
1112
- }
1113
- } else if (pr) {
1114
- debug('replaceCaret pr', pr)
1115
- if (M === '0') {
1116
- if (m === '0') {
1117
- ret = '>=' + M + '.' + m + '.' + p + '-' + pr +
1118
- ' <' + M + '.' + m + '.' + (+p + 1)
1119
- } else {
1120
- ret = '>=' + M + '.' + m + '.' + p + '-' + pr +
1121
- ' <' + M + '.' + (+m + 1) + '.0'
1122
- }
1123
- } else {
1124
- ret = '>=' + M + '.' + m + '.' + p + '-' + pr +
1125
- ' <' + (+M + 1) + '.0.0'
1126
- }
1127
- } else {
1128
- debug('no pr')
1129
- if (M === '0') {
1130
- if (m === '0') {
1131
- ret = '>=' + M + '.' + m + '.' + p +
1132
- ' <' + M + '.' + m + '.' + (+p + 1)
1133
- } else {
1134
- ret = '>=' + M + '.' + m + '.' + p +
1135
- ' <' + M + '.' + (+m + 1) + '.0'
1136
- }
1137
- } else {
1138
- ret = '>=' + M + '.' + m + '.' + p +
1139
- ' <' + (+M + 1) + '.0.0'
1140
- }
1141
- }
1142
-
1143
- debug('caret return', ret)
1144
- return ret
1145
- })
1146
- }
1147
-
1148
- function replaceXRanges (comp, options) {
1149
- debug('replaceXRanges', comp, options)
1150
- return comp.split(/\s+/).map(function (comp) {
1151
- return replaceXRange(comp, options)
1152
- }).join(' ')
1153
- }
1154
-
1155
- function replaceXRange (comp, options) {
1156
- comp = comp.trim()
1157
- var r = options.loose ? re[XRANGELOOSE] : re[XRANGE]
1158
- return comp.replace(r, function (ret, gtlt, M, m, p, pr) {
1159
- debug('xRange', comp, ret, gtlt, M, m, p, pr)
1160
- var xM = isX(M)
1161
- var xm = xM || isX(m)
1162
- var xp = xm || isX(p)
1163
- var anyX = xp
1164
-
1165
- if (gtlt === '=' && anyX) {
1166
- gtlt = ''
1167
- }
1168
-
1169
- // if we're including prereleases in the match, then we need
1170
- // to fix this to -0, the lowest possible prerelease value
1171
- pr = options.includePrerelease ? '-0' : ''
1172
-
1173
- if (xM) {
1174
- if (gtlt === '>' || gtlt === '<') {
1175
- // nothing is allowed
1176
- ret = '<0.0.0-0'
1177
- } else {
1178
- // nothing is forbidden
1179
- ret = '*'
1180
- }
1181
- } else if (gtlt && anyX) {
1182
- // we know patch is an x, because we have any x at all.
1183
- // replace X with 0
1184
- if (xm) {
1185
- m = 0
1186
- }
1187
- p = 0
1188
-
1189
- if (gtlt === '>') {
1190
- // >1 => >=2.0.0
1191
- // >1.2 => >=1.3.0
1192
- // >1.2.3 => >= 1.2.4
1193
- gtlt = '>='
1194
- if (xm) {
1195
- M = +M + 1
1196
- m = 0
1197
- p = 0
1198
- } else {
1199
- m = +m + 1
1200
- p = 0
1201
- }
1202
- } else if (gtlt === '<=') {
1203
- // <=0.7.x is actually <0.8.0, since any 0.7.x should
1204
- // pass. Similarly, <=7.x is actually <8.0.0, etc.
1205
- gtlt = '<'
1206
- if (xm) {
1207
- M = +M + 1
1208
- } else {
1209
- m = +m + 1
1210
- }
1211
- }
1212
-
1213
- ret = gtlt + M + '.' + m + '.' + p + pr
1214
- } else if (xm) {
1215
- ret = '>=' + M + '.0.0' + pr + ' <' + (+M + 1) + '.0.0' + pr
1216
- } else if (xp) {
1217
- ret = '>=' + M + '.' + m + '.0' + pr +
1218
- ' <' + M + '.' + (+m + 1) + '.0' + pr
1219
- }
1220
-
1221
- debug('xRange return', ret)
1222
-
1223
- return ret
1224
- })
1225
- }
1226
-
1227
- // Because * is AND-ed with everything else in the comparator,
1228
- // and '' means "any version", just remove the *s entirely.
1229
- function replaceStars (comp, options) {
1230
- debug('replaceStars', comp, options)
1231
- // Looseness is ignored here. star is always as loose as it gets!
1232
- return comp.trim().replace(re[STAR], '')
1233
- }
1234
-
1235
- // This function is passed to string.replace(re[HYPHENRANGE])
1236
- // M, m, patch, prerelease, build
1237
- // 1.2 - 3.4.5 => >=1.2.0 <=3.4.5
1238
- // 1.2.3 - 3.4 => >=1.2.0 <3.5.0 Any 3.4.x will do
1239
- // 1.2 - 3.4 => >=1.2.0 <3.5.0
1240
- function hyphenReplace ($0,
1241
- from, fM, fm, fp, fpr, fb,
1242
- to, tM, tm, tp, tpr, tb) {
1243
- if (isX(fM)) {
1244
- from = ''
1245
- } else if (isX(fm)) {
1246
- from = '>=' + fM + '.0.0'
1247
- } else if (isX(fp)) {
1248
- from = '>=' + fM + '.' + fm + '.0'
1249
- } else {
1250
- from = '>=' + from
1251
- }
1252
-
1253
- if (isX(tM)) {
1254
- to = ''
1255
- } else if (isX(tm)) {
1256
- to = '<' + (+tM + 1) + '.0.0'
1257
- } else if (isX(tp)) {
1258
- to = '<' + tM + '.' + (+tm + 1) + '.0'
1259
- } else if (tpr) {
1260
- to = '<=' + tM + '.' + tm + '.' + tp + '-' + tpr
1261
- } else {
1262
- to = '<=' + to
1263
- }
1264
-
1265
- return (from + ' ' + to).trim()
1266
- }
1267
-
1268
- // if ANY of the sets match ALL of its comparators, then pass
1269
- Range.prototype.test = function (version) {
1270
- if (!version) {
1271
- return false
1272
- }
1273
-
1274
- if (typeof version === 'string') {
1275
- try {
1276
- version = new SemVer(version, this.options)
1277
- } catch (er) {
1278
- return false
1279
- }
1280
- }
1281
-
1282
- for (var i = 0; i < this.set.length; i++) {
1283
- if (testSet(this.set[i], version, this.options)) {
1284
- return true
1285
- }
1286
- }
1287
- return false
1288
- }
1289
-
1290
- function testSet (set, version, options) {
1291
- for (var i = 0; i < set.length; i++) {
1292
- if (!set[i].test(version)) {
1293
- return false
1294
- }
1295
- }
1296
-
1297
- if (version.prerelease.length && !options.includePrerelease) {
1298
- // Find the set of versions that are allowed to have prereleases
1299
- // For example, ^1.2.3-pr.1 desugars to >=1.2.3-pr.1 <2.0.0
1300
- // That should allow `1.2.3-pr.2` to pass.
1301
- // However, `1.2.4-alpha.notready` should NOT be allowed,
1302
- // even though it's within the range set by the comparators.
1303
- for (i = 0; i < set.length; i++) {
1304
- debug(set[i].semver)
1305
- if (set[i].semver === ANY) {
1306
- continue
1307
- }
1308
-
1309
- if (set[i].semver.prerelease.length > 0) {
1310
- var allowed = set[i].semver
1311
- if (allowed.major === version.major &&
1312
- allowed.minor === version.minor &&
1313
- allowed.patch === version.patch) {
1314
- return true
1315
- }
1316
- }
1317
- }
1318
-
1319
- // Version has a -pre, but it's not one of the ones we like.
1320
- return false
1321
- }
1322
-
1323
- return true
1324
- }
1325
-
1326
- exports.satisfies = satisfies
1327
- function satisfies (version, range, options) {
1328
- try {
1329
- range = new Range(range, options)
1330
- } catch (er) {
1331
- return false
1332
- }
1333
- return range.test(version)
1334
- }
1335
-
1336
- exports.maxSatisfying = maxSatisfying
1337
- function maxSatisfying (versions, range, options) {
1338
- var max = null
1339
- var maxSV = null
1340
- try {
1341
- var rangeObj = new Range(range, options)
1342
- } catch (er) {
1343
- return null
1344
- }
1345
- versions.forEach(function (v) {
1346
- if (rangeObj.test(v)) {
1347
- // satisfies(v, range, options)
1348
- if (!max || maxSV.compare(v) === -1) {
1349
- // compare(max, v, true)
1350
- max = v
1351
- maxSV = new SemVer(max, options)
1352
- }
1353
- }
1354
- })
1355
- return max
1356
- }
1357
-
1358
- exports.minSatisfying = minSatisfying
1359
- function minSatisfying (versions, range, options) {
1360
- var min = null
1361
- var minSV = null
1362
- try {
1363
- var rangeObj = new Range(range, options)
1364
- } catch (er) {
1365
- return null
1366
- }
1367
- versions.forEach(function (v) {
1368
- if (rangeObj.test(v)) {
1369
- // satisfies(v, range, options)
1370
- if (!min || minSV.compare(v) === 1) {
1371
- // compare(min, v, true)
1372
- min = v
1373
- minSV = new SemVer(min, options)
1374
- }
1375
- }
1376
- })
1377
- return min
1378
- }
1379
-
1380
- exports.minVersion = minVersion
1381
- function minVersion (range, loose) {
1382
- range = new Range(range, loose)
1383
-
1384
- var minver = new SemVer('0.0.0')
1385
- if (range.test(minver)) {
1386
- return minver
1387
- }
1388
-
1389
- minver = new SemVer('0.0.0-0')
1390
- if (range.test(minver)) {
1391
- return minver
1392
- }
1393
-
1394
- minver = null
1395
- for (var i = 0; i < range.set.length; ++i) {
1396
- var comparators = range.set[i]
1397
-
1398
- comparators.forEach(function (comparator) {
1399
- // Clone to avoid manipulating the comparator's semver object.
1400
- var compver = new SemVer(comparator.semver.version)
1401
- switch (comparator.operator) {
1402
- case '>':
1403
- if (compver.prerelease.length === 0) {
1404
- compver.patch++
1405
- } else {
1406
- compver.prerelease.push(0)
1407
- }
1408
- compver.raw = compver.format()
1409
- /* fallthrough */
1410
- case '':
1411
- case '>=':
1412
- if (!minver || gt(minver, compver)) {
1413
- minver = compver
1414
- }
1415
- break
1416
- case '<':
1417
- case '<=':
1418
- /* Ignore maximum versions */
1419
- break
1420
- /* istanbul ignore next */
1421
- default:
1422
- throw new Error('Unexpected operation: ' + comparator.operator)
1423
- }
1424
- })
1425
- }
1426
-
1427
- if (minver && range.test(minver)) {
1428
- return minver
1429
- }
1430
-
1431
- return null
1432
- }
1433
-
1434
- exports.validRange = validRange
1435
- function validRange (range, options) {
1436
- try {
1437
- // Return '*' instead of '' so that truthiness works.
1438
- // This will throw if it's invalid anyway
1439
- return new Range(range, options).range || '*'
1440
- } catch (er) {
1441
- return null
1442
- }
1443
- }
1444
-
1445
- // Determine if version is less than all the versions possible in the range
1446
- exports.ltr = ltr
1447
- function ltr (version, range, options) {
1448
- return outside(version, range, '<', options)
1449
- }
1450
-
1451
- // Determine if version is greater than all the versions possible in the range.
1452
- exports.gtr = gtr
1453
- function gtr (version, range, options) {
1454
- return outside(version, range, '>', options)
1455
- }
1456
-
1457
- exports.outside = outside
1458
- function outside (version, range, hilo, options) {
1459
- version = new SemVer(version, options)
1460
- range = new Range(range, options)
1461
-
1462
- var gtfn, ltefn, ltfn, comp, ecomp
1463
- switch (hilo) {
1464
- case '>':
1465
- gtfn = gt
1466
- ltefn = lte
1467
- ltfn = lt
1468
- comp = '>'
1469
- ecomp = '>='
1470
- break
1471
- case '<':
1472
- gtfn = lt
1473
- ltefn = gte
1474
- ltfn = gt
1475
- comp = '<'
1476
- ecomp = '<='
1477
- break
1478
- default:
1479
- throw new TypeError('Must provide a hilo val of "<" or ">"')
1480
- }
1481
-
1482
- // If it satisifes the range it is not outside
1483
- if (satisfies(version, range, options)) {
1484
- return false
1485
- }
1486
-
1487
- // From now on, variable terms are as if we're in "gtr" mode.
1488
- // but note that everything is flipped for the "ltr" function.
1489
-
1490
- for (var i = 0; i < range.set.length; ++i) {
1491
- var comparators = range.set[i]
1492
-
1493
- var high = null
1494
- var low = null
1495
-
1496
- comparators.forEach(function (comparator) {
1497
- if (comparator.semver === ANY) {
1498
- comparator = new Comparator('>=0.0.0')
1499
- }
1500
- high = high || comparator
1501
- low = low || comparator
1502
- if (gtfn(comparator.semver, high.semver, options)) {
1503
- high = comparator
1504
- } else if (ltfn(comparator.semver, low.semver, options)) {
1505
- low = comparator
1506
- }
1507
- })
1508
-
1509
- // If the edge version comparator has a operator then our version
1510
- // isn't outside it
1511
- if (high.operator === comp || high.operator === ecomp) {
1512
- return false
1513
- }
1514
-
1515
- // If the lowest version comparator has an operator and our version
1516
- // is less than it then it isn't higher than the range
1517
- if ((!low.operator || low.operator === comp) &&
1518
- ltefn(version, low.semver)) {
1519
- return false
1520
- } else if (low.operator === ecomp && ltfn(version, low.semver)) {
1521
- return false
1522
- }
1523
- }
1524
- return true
1525
- }
1526
-
1527
- exports.prerelease = prerelease
1528
- function prerelease (version, options) {
1529
- var parsed = parse(version, options)
1530
- return (parsed && parsed.prerelease.length) ? parsed.prerelease : null
1531
- }
1532
-
1533
- exports.intersects = intersects
1534
- function intersects (r1, r2, options) {
1535
- r1 = new Range(r1, options)
1536
- r2 = new Range(r2, options)
1537
- return r1.intersects(r2)
1538
- }
1539
-
1540
- exports.coerce = coerce
1541
- function coerce (version, options) {
1542
- if (version instanceof SemVer) {
1543
- return version
1544
- }
1545
-
1546
- if (typeof version === 'number') {
1547
- version = String(version)
1548
- }
1549
-
1550
- if (typeof version !== 'string') {
1551
- return null
1552
- }
1553
-
1554
- options = options || {}
1555
-
1556
- var match = null
1557
- if (!options.rtl) {
1558
- match = version.match(re[COERCE])
1559
- } else {
1560
- // Find the right-most coercible string that does not share
1561
- // a terminus with a more left-ward coercible string.
1562
- // Eg, '1.2.3.4' wants to coerce '2.3.4', not '3.4' or '4'
1563
- //
1564
- // Walk through the string checking with a /g regexp
1565
- // Manually set the index so as to pick up overlapping matches.
1566
- // Stop when we get a match that ends at the string end, since no
1567
- // coercible string can be more right-ward without the same terminus.
1568
- var next
1569
- while ((next = re[COERCERTL].exec(version)) &&
1570
- (!match || match.index + match[0].length !== version.length)
1571
- ) {
1572
- if (!match ||
1573
- next.index + next[0].length !== match.index + match[0].length) {
1574
- match = next
1575
- }
1576
- re[COERCERTL].lastIndex = next.index + next[1].length + next[2].length
1577
- }
1578
- // leave it in a clean state
1579
- re[COERCERTL].lastIndex = -1
1580
- }
1581
-
1582
- if (match === null) {
1583
- return null
1584
- }
1585
-
1586
- return parse(match[2] +
1587
- '.' + (match[3] || '0') +
1588
- '.' + (match[4] || '0'), options)
1589
- }