cdk-gitlab-runner 2.1.394 → 2.2.0
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.
- package/.jsii +93 -117
- package/API.md +28 -47
- package/README.md +49 -17
- package/lib/gitlab-runner-autoscaling.d.ts +5 -0
- package/lib/gitlab-runner-autoscaling.js +9 -4
- package/lib/gitlab-runner-instance.d.ts +8 -38
- package/lib/gitlab-runner-instance.js +14 -6
- package/lib/integ.api.js +3 -2
- package/lib/integ.gitlab-runner-autoscaling.js +2 -1
- package/node_modules/compare-versions/LICENSE +21 -0
- package/node_modules/compare-versions/README.md +133 -0
- package/node_modules/compare-versions/lib/esm/compare.d.ts +19 -0
- package/node_modules/compare-versions/lib/esm/compare.js +44 -0
- package/node_modules/compare-versions/lib/esm/compare.js.map +1 -0
- package/node_modules/compare-versions/lib/esm/compareVersions.d.ts +8 -0
- package/node_modules/compare-versions/lib/esm/compareVersions.js +29 -0
- package/node_modules/compare-versions/lib/esm/compareVersions.js.map +1 -0
- package/node_modules/compare-versions/lib/esm/index.d.ts +5 -0
- package/node_modules/compare-versions/lib/esm/index.js +5 -0
- package/node_modules/compare-versions/lib/esm/index.js.map +1 -0
- package/node_modules/compare-versions/lib/esm/satisfies.d.ts +14 -0
- package/node_modules/compare-versions/lib/esm/satisfies.js +66 -0
- package/node_modules/compare-versions/lib/esm/satisfies.js.map +1 -0
- package/node_modules/compare-versions/lib/esm/utils.d.ts +7 -0
- package/node_modules/compare-versions/lib/esm/utils.js +37 -0
- package/node_modules/compare-versions/lib/esm/utils.js.map +1 -0
- package/node_modules/compare-versions/lib/esm/validate.d.ts +28 -0
- package/node_modules/compare-versions/lib/esm/validate.js +31 -0
- package/node_modules/compare-versions/lib/esm/validate.js.map +1 -0
- package/node_modules/compare-versions/lib/umd/index.js +216 -0
- package/node_modules/compare-versions/lib/umd/index.js.map +1 -0
- package/node_modules/compare-versions/package.json +45 -0
- package/node_modules/compare-versions/src/compare.ts +54 -0
- package/node_modules/compare-versions/src/compareVersions.ts +31 -0
- package/node_modules/compare-versions/src/index.ts +5 -0
- package/node_modules/compare-versions/src/satisfies.ts +69 -0
- package/node_modules/compare-versions/src/utils.ts +50 -0
- package/node_modules/compare-versions/src/validate.ts +36 -0
- package/package.json +7 -1
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { compare } from './compare';
|
|
2
|
+
import { compareSegments, validateAndParse } from './utils';
|
|
3
|
+
/**
|
|
4
|
+
* Match [npm semver](https://docs.npmjs.com/cli/v6/using-npm/semver) version range.
|
|
5
|
+
*
|
|
6
|
+
* @param version Version number to match
|
|
7
|
+
* @param range Range pattern for version
|
|
8
|
+
* @returns `true` if the version number is within the range, `false` otherwise.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```
|
|
12
|
+
* satisfies('1.1.0', '^1.0.0'); // return true
|
|
13
|
+
* satisfies('1.1.0', '~1.0.0'); // return false
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export const satisfies = (version, range) => {
|
|
17
|
+
// clean input
|
|
18
|
+
range = range.replace(/([><=]+)\s+/g, '$1');
|
|
19
|
+
// handle multiple comparators
|
|
20
|
+
if (range.includes('||')) {
|
|
21
|
+
return range.split('||').some((r) => satisfies(version, r));
|
|
22
|
+
}
|
|
23
|
+
else if (range.includes(' - ')) {
|
|
24
|
+
const [a, b] = range.split(' - ', 2);
|
|
25
|
+
return satisfies(version, `>=${a} <=${b}`);
|
|
26
|
+
}
|
|
27
|
+
else if (range.includes(' ')) {
|
|
28
|
+
return range
|
|
29
|
+
.trim()
|
|
30
|
+
.replace(/\s{2,}/g, ' ')
|
|
31
|
+
.split(' ')
|
|
32
|
+
.every((r) => satisfies(version, r));
|
|
33
|
+
}
|
|
34
|
+
// if no range operator then "="
|
|
35
|
+
const m = range.match(/^([<>=~^]+)/);
|
|
36
|
+
const op = m ? m[1] : '=';
|
|
37
|
+
// if gt/lt/eq then operator compare
|
|
38
|
+
if (op !== '^' && op !== '~')
|
|
39
|
+
return compare(version, range, op);
|
|
40
|
+
// else range of either "~" or "^" is assumed
|
|
41
|
+
const [v1, v2, v3, , vp] = validateAndParse(version);
|
|
42
|
+
const [r1, r2, r3, , rp] = validateAndParse(range);
|
|
43
|
+
const v = [v1, v2, v3];
|
|
44
|
+
const r = [r1, r2 !== null && r2 !== void 0 ? r2 : 'x', r3 !== null && r3 !== void 0 ? r3 : 'x'];
|
|
45
|
+
// validate pre-release
|
|
46
|
+
if (rp) {
|
|
47
|
+
if (!vp)
|
|
48
|
+
return false;
|
|
49
|
+
if (compareSegments(v, r) !== 0)
|
|
50
|
+
return false;
|
|
51
|
+
if (compareSegments(vp.split('.'), rp.split('.')) === -1)
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
// first non-zero number
|
|
55
|
+
const nonZero = r.findIndex((v) => v !== '0') + 1;
|
|
56
|
+
// pointer to where segments can be >=
|
|
57
|
+
const i = op === '~' ? 2 : nonZero > 1 ? nonZero : 1;
|
|
58
|
+
// before pointer must be equal
|
|
59
|
+
if (compareSegments(v.slice(0, i), r.slice(0, i)) !== 0)
|
|
60
|
+
return false;
|
|
61
|
+
// after pointer must be >=
|
|
62
|
+
if (compareSegments(v.slice(i), r.slice(i)) === -1)
|
|
63
|
+
return false;
|
|
64
|
+
return true;
|
|
65
|
+
};
|
|
66
|
+
//# sourceMappingURL=satisfies.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"satisfies.js","sourceRoot":"","sources":["../../src/satisfies.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAmB,eAAe,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAE7E;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,OAAe,EAAE,KAAa,EAAW,EAAE;IACnE,cAAc;IACd,KAAK,GAAG,KAAK,CAAC,OAAO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KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QAAE,OAAO,KAAK,CAAC;IAEjE,OAAO,IAAI,CAAC;AACd,CAAC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Allowed arithmetic operators
|
|
3
|
+
*/
|
|
4
|
+
export type CompareOperator = '>' | '>=' | '=' | '<' | '<=' | '!=';
|
|
5
|
+
export declare const semver: RegExp;
|
|
6
|
+
export declare const validateAndParse: (version: string) => RegExpMatchArray;
|
|
7
|
+
export declare const compareSegments: (a: string | string[] | RegExpMatchArray, b: string | string[] | RegExpMatchArray) => 0 | 1 | -1;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export const semver = /^[v^~<>=]*?(\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+))?(?:-([\da-z\-]+(?:\.[\da-z\-]+)*))?(?:\+[\da-z\-]+(?:\.[\da-z\-]+)*)?)?)?$/i;
|
|
2
|
+
export const validateAndParse = (version) => {
|
|
3
|
+
if (typeof version !== 'string') {
|
|
4
|
+
throw new TypeError('Invalid argument expected string');
|
|
5
|
+
}
|
|
6
|
+
const match = version.match(semver);
|
|
7
|
+
if (!match) {
|
|
8
|
+
throw new Error(`Invalid argument not valid semver ('${version}' received)`);
|
|
9
|
+
}
|
|
10
|
+
match.shift();
|
|
11
|
+
return match;
|
|
12
|
+
};
|
|
13
|
+
const isWildcard = (s) => s === '*' || s === 'x' || s === 'X';
|
|
14
|
+
const tryParse = (v) => {
|
|
15
|
+
const n = parseInt(v, 10);
|
|
16
|
+
return isNaN(n) ? v : n;
|
|
17
|
+
};
|
|
18
|
+
const forceType = (a, b) => typeof a !== typeof b ? [String(a), String(b)] : [a, b];
|
|
19
|
+
const compareStrings = (a, b) => {
|
|
20
|
+
if (isWildcard(a) || isWildcard(b))
|
|
21
|
+
return 0;
|
|
22
|
+
const [ap, bp] = forceType(tryParse(a), tryParse(b));
|
|
23
|
+
if (ap > bp)
|
|
24
|
+
return 1;
|
|
25
|
+
if (ap < bp)
|
|
26
|
+
return -1;
|
|
27
|
+
return 0;
|
|
28
|
+
};
|
|
29
|
+
export const compareSegments = (a, b) => {
|
|
30
|
+
for (let i = 0; i < Math.max(a.length, b.length); i++) {
|
|
31
|
+
const r = compareStrings(a[i] || '0', b[i] || '0');
|
|
32
|
+
if (r !== 0)
|
|
33
|
+
return r;
|
|
34
|
+
}
|
|
35
|
+
return 0;
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAKA,MAAM,CAAC,MAAM,MAAM,GACjB,4IAA4I,CAAC;AAE/I,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,OAAe,EAAE,EAAE;IAClD,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;QAC/B,MAAM,IAAI,SAAS,CAAC,kCAAkC,CAAC,CAAC;KACzD;IACD,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IACpC,IAAI,CAAC,KAAK,EAAE;QACV,MAAM,IAAI,KAAK,CACb,uCAAuC,OAAO,aAAa,CAC5D,CAAC;KACH;IACD,KAAK,CAAC,KAAK,EAAE,CAAC;IACd,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF,MAAM,UAAU,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,GAAG,CAAC;AAEtE,MAAM,QAAQ,GAAG,CAAC,CAAS,EAAE,EAAE;IAC7B,MAAM,CAAC,GAAG,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAC1B,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;A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3
|
+
*
|
|
4
|
+
* @param version Version number to validate
|
|
5
|
+
* @returns `true` if the version number is a valid semver version number, `false` otherwise.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```
|
|
9
|
+
* validate('1.0.0-rc.1'); // return true
|
|
10
|
+
* validate('1.0-rc.1'); // return false
|
|
11
|
+
* validate('foo'); // return false
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export declare const validate: (version: string) => boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Validate [semver](https://semver.org/) version strings strictly. Will not accept wildcards and version ranges.
|
|
17
|
+
*
|
|
18
|
+
* @param version Version number to validate
|
|
19
|
+
* @returns `true` if the version number is a valid semver version number `false` otherwise
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```
|
|
23
|
+
* validate('1.0.0-rc.1'); // return true
|
|
24
|
+
* validate('1.0-rc.1'); // return false
|
|
25
|
+
* validate('foo'); // return false
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare const validateStrict: (version: string) => boolean;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { semver } from './utils';
|
|
2
|
+
/**
|
|
3
|
+
* Validate [semver](https://semver.org/) version strings.
|
|
4
|
+
*
|
|
5
|
+
* @param version Version number to validate
|
|
6
|
+
* @returns `true` if the version number is a valid semver version number, `false` otherwise.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```
|
|
10
|
+
* validate('1.0.0-rc.1'); // return true
|
|
11
|
+
* validate('1.0-rc.1'); // return false
|
|
12
|
+
* validate('foo'); // return false
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export const validate = (version) => typeof version === 'string' && /^[v\d]/.test(version) && semver.test(version);
|
|
16
|
+
/**
|
|
17
|
+
* Validate [semver](https://semver.org/) version strings strictly. Will not accept wildcards and version ranges.
|
|
18
|
+
*
|
|
19
|
+
* @param version Version number to validate
|
|
20
|
+
* @returns `true` if the version number is a valid semver version number `false` otherwise
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```
|
|
24
|
+
* validate('1.0.0-rc.1'); // return true
|
|
25
|
+
* validate('1.0-rc.1'); // return false
|
|
26
|
+
* validate('foo'); // return false
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export const validateStrict = (version) => typeof version === 'string' &&
|
|
30
|
+
/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/.test(version);
|
|
31
|
+
//# sourceMappingURL=validate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../../src/validate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEjC;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,OAAe,EAAE,EAAE,CAC1C,OAAO,OAAO,KAAK,QAAQ,IAAI,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AAEhF;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,OAAe,EAAE,EAAE,CAChD,OAAO,OAAO,KAAK,QAAQ;IAC3B,qLAAqL,CAAC,IAAI,CACxL,OAAO,CACR,CAAC"}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.compareVersions = {}));
|
|
5
|
+
})(this, (function (exports) { 'use strict';
|
|
6
|
+
|
|
7
|
+
const semver = /^[v^~<>=]*?(\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+))?(?:-([\da-z\-]+(?:\.[\da-z\-]+)*))?(?:\+[\da-z\-]+(?:\.[\da-z\-]+)*)?)?)?$/i;
|
|
8
|
+
const validateAndParse = (version) => {
|
|
9
|
+
if (typeof version !== 'string') {
|
|
10
|
+
throw new TypeError('Invalid argument expected string');
|
|
11
|
+
}
|
|
12
|
+
const match = version.match(semver);
|
|
13
|
+
if (!match) {
|
|
14
|
+
throw new Error(`Invalid argument not valid semver ('${version}' received)`);
|
|
15
|
+
}
|
|
16
|
+
match.shift();
|
|
17
|
+
return match;
|
|
18
|
+
};
|
|
19
|
+
const isWildcard = (s) => s === '*' || s === 'x' || s === 'X';
|
|
20
|
+
const tryParse = (v) => {
|
|
21
|
+
const n = parseInt(v, 10);
|
|
22
|
+
return isNaN(n) ? v : n;
|
|
23
|
+
};
|
|
24
|
+
const forceType = (a, b) => typeof a !== typeof b ? [String(a), String(b)] : [a, b];
|
|
25
|
+
const compareStrings = (a, b) => {
|
|
26
|
+
if (isWildcard(a) || isWildcard(b))
|
|
27
|
+
return 0;
|
|
28
|
+
const [ap, bp] = forceType(tryParse(a), tryParse(b));
|
|
29
|
+
if (ap > bp)
|
|
30
|
+
return 1;
|
|
31
|
+
if (ap < bp)
|
|
32
|
+
return -1;
|
|
33
|
+
return 0;
|
|
34
|
+
};
|
|
35
|
+
const compareSegments = (a, b) => {
|
|
36
|
+
for (let i = 0; i < Math.max(a.length, b.length); i++) {
|
|
37
|
+
const r = compareStrings(a[i] || '0', b[i] || '0');
|
|
38
|
+
if (r !== 0)
|
|
39
|
+
return r;
|
|
40
|
+
}
|
|
41
|
+
return 0;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Compare [semver](https://semver.org/) version strings to find greater, equal or lesser.
|
|
46
|
+
* This library supports the full semver specification, including comparing versions with different number of digits like `1.0.0`, `1.0`, `1`, and pre-release versions like `1.0.0-alpha`.
|
|
47
|
+
* @param v1 - First version to compare
|
|
48
|
+
* @param v2 - Second version to compare
|
|
49
|
+
* @returns Numeric value compatible with the [Array.sort(fn) interface](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#Parameters).
|
|
50
|
+
*/
|
|
51
|
+
const compareVersions = (v1, v2) => {
|
|
52
|
+
// validate input and split into segments
|
|
53
|
+
const n1 = validateAndParse(v1);
|
|
54
|
+
const n2 = validateAndParse(v2);
|
|
55
|
+
// pop off the patch
|
|
56
|
+
const p1 = n1.pop();
|
|
57
|
+
const p2 = n2.pop();
|
|
58
|
+
// validate numbers
|
|
59
|
+
const r = compareSegments(n1, n2);
|
|
60
|
+
if (r !== 0)
|
|
61
|
+
return r;
|
|
62
|
+
// validate pre-release
|
|
63
|
+
if (p1 && p2) {
|
|
64
|
+
return compareSegments(p1.split('.'), p2.split('.'));
|
|
65
|
+
}
|
|
66
|
+
else if (p1 || p2) {
|
|
67
|
+
return p1 ? -1 : 1;
|
|
68
|
+
}
|
|
69
|
+
return 0;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Compare [semver](https://semver.org/) version strings using the specified operator.
|
|
74
|
+
*
|
|
75
|
+
* @param v1 First version to compare
|
|
76
|
+
* @param v2 Second version to compare
|
|
77
|
+
* @param operator Allowed arithmetic operator to use
|
|
78
|
+
* @returns `true` if the comparison between the firstVersion and the secondVersion satisfies the operator, `false` otherwise.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```
|
|
82
|
+
* compare('10.1.8', '10.0.4', '>'); // return true
|
|
83
|
+
* compare('10.0.1', '10.0.1', '='); // return true
|
|
84
|
+
* compare('10.1.1', '10.2.2', '<'); // return true
|
|
85
|
+
* compare('10.1.1', '10.2.2', '<='); // return true
|
|
86
|
+
* compare('10.1.1', '10.2.2', '>='); // return false
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
const compare = (v1, v2, operator) => {
|
|
90
|
+
// validate input operator
|
|
91
|
+
assertValidOperator(operator);
|
|
92
|
+
// since result of compareVersions can only be -1 or 0 or 1
|
|
93
|
+
// a simple map can be used to replace switch
|
|
94
|
+
const res = compareVersions(v1, v2);
|
|
95
|
+
return operatorResMap[operator].includes(res);
|
|
96
|
+
};
|
|
97
|
+
const operatorResMap = {
|
|
98
|
+
'>': [1],
|
|
99
|
+
'>=': [0, 1],
|
|
100
|
+
'=': [0],
|
|
101
|
+
'<=': [-1, 0],
|
|
102
|
+
'<': [-1],
|
|
103
|
+
'!=': [-1, 1],
|
|
104
|
+
};
|
|
105
|
+
const allowedOperators = Object.keys(operatorResMap);
|
|
106
|
+
const assertValidOperator = (op) => {
|
|
107
|
+
if (typeof op !== 'string') {
|
|
108
|
+
throw new TypeError(`Invalid operator type, expected string but got ${typeof op}`);
|
|
109
|
+
}
|
|
110
|
+
if (allowedOperators.indexOf(op) === -1) {
|
|
111
|
+
throw new Error(`Invalid operator, expected one of ${allowedOperators.join('|')}`);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Match [npm semver](https://docs.npmjs.com/cli/v6/using-npm/semver) version range.
|
|
117
|
+
*
|
|
118
|
+
* @param version Version number to match
|
|
119
|
+
* @param range Range pattern for version
|
|
120
|
+
* @returns `true` if the version number is within the range, `false` otherwise.
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```
|
|
124
|
+
* satisfies('1.1.0', '^1.0.0'); // return true
|
|
125
|
+
* satisfies('1.1.0', '~1.0.0'); // return false
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
const satisfies = (version, range) => {
|
|
129
|
+
// clean input
|
|
130
|
+
range = range.replace(/([><=]+)\s+/g, '$1');
|
|
131
|
+
// handle multiple comparators
|
|
132
|
+
if (range.includes('||')) {
|
|
133
|
+
return range.split('||').some((r) => satisfies(version, r));
|
|
134
|
+
}
|
|
135
|
+
else if (range.includes(' - ')) {
|
|
136
|
+
const [a, b] = range.split(' - ', 2);
|
|
137
|
+
return satisfies(version, `>=${a} <=${b}`);
|
|
138
|
+
}
|
|
139
|
+
else if (range.includes(' ')) {
|
|
140
|
+
return range
|
|
141
|
+
.trim()
|
|
142
|
+
.replace(/\s{2,}/g, ' ')
|
|
143
|
+
.split(' ')
|
|
144
|
+
.every((r) => satisfies(version, r));
|
|
145
|
+
}
|
|
146
|
+
// if no range operator then "="
|
|
147
|
+
const m = range.match(/^([<>=~^]+)/);
|
|
148
|
+
const op = m ? m[1] : '=';
|
|
149
|
+
// if gt/lt/eq then operator compare
|
|
150
|
+
if (op !== '^' && op !== '~')
|
|
151
|
+
return compare(version, range, op);
|
|
152
|
+
// else range of either "~" or "^" is assumed
|
|
153
|
+
const [v1, v2, v3, , vp] = validateAndParse(version);
|
|
154
|
+
const [r1, r2, r3, , rp] = validateAndParse(range);
|
|
155
|
+
const v = [v1, v2, v3];
|
|
156
|
+
const r = [r1, r2 !== null && r2 !== void 0 ? r2 : 'x', r3 !== null && r3 !== void 0 ? r3 : 'x'];
|
|
157
|
+
// validate pre-release
|
|
158
|
+
if (rp) {
|
|
159
|
+
if (!vp)
|
|
160
|
+
return false;
|
|
161
|
+
if (compareSegments(v, r) !== 0)
|
|
162
|
+
return false;
|
|
163
|
+
if (compareSegments(vp.split('.'), rp.split('.')) === -1)
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
// first non-zero number
|
|
167
|
+
const nonZero = r.findIndex((v) => v !== '0') + 1;
|
|
168
|
+
// pointer to where segments can be >=
|
|
169
|
+
const i = op === '~' ? 2 : nonZero > 1 ? nonZero : 1;
|
|
170
|
+
// before pointer must be equal
|
|
171
|
+
if (compareSegments(v.slice(0, i), r.slice(0, i)) !== 0)
|
|
172
|
+
return false;
|
|
173
|
+
// after pointer must be >=
|
|
174
|
+
if (compareSegments(v.slice(i), r.slice(i)) === -1)
|
|
175
|
+
return false;
|
|
176
|
+
return true;
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Validate [semver](https://semver.org/) version strings.
|
|
181
|
+
*
|
|
182
|
+
* @param version Version number to validate
|
|
183
|
+
* @returns `true` if the version number is a valid semver version number, `false` otherwise.
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* ```
|
|
187
|
+
* validate('1.0.0-rc.1'); // return true
|
|
188
|
+
* validate('1.0-rc.1'); // return false
|
|
189
|
+
* validate('foo'); // return false
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
const validate = (version) => typeof version === 'string' && /^[v\d]/.test(version) && semver.test(version);
|
|
193
|
+
/**
|
|
194
|
+
* Validate [semver](https://semver.org/) version strings strictly. Will not accept wildcards and version ranges.
|
|
195
|
+
*
|
|
196
|
+
* @param version Version number to validate
|
|
197
|
+
* @returns `true` if the version number is a valid semver version number `false` otherwise
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
* ```
|
|
201
|
+
* validate('1.0.0-rc.1'); // return true
|
|
202
|
+
* validate('1.0-rc.1'); // return false
|
|
203
|
+
* validate('foo'); // return false
|
|
204
|
+
* ```
|
|
205
|
+
*/
|
|
206
|
+
const validateStrict = (version) => typeof version === 'string' &&
|
|
207
|
+
/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/.test(version);
|
|
208
|
+
|
|
209
|
+
exports.compare = compare;
|
|
210
|
+
exports.compareVersions = compareVersions;
|
|
211
|
+
exports.satisfies = satisfies;
|
|
212
|
+
exports.validate = validate;
|
|
213
|
+
exports.validateStrict = validateStrict;
|
|
214
|
+
|
|
215
|
+
}));
|
|
216
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../esm/utils.js","../esm/compareVersions.js","../esm/compare.js","../esm/satisfies.js","../esm/validate.js"],"sourcesContent":["export const semver = /^[v^~<>=]*?(\\d+)(?:\\.([x*]|\\d+)(?:\\.([x*]|\\d+)(?:\\.([x*]|\\d+))?(?:-([\\da-z\\-]+(?:\\.[\\da-z\\-]+)*))?(?:\\+[\\da-z\\-]+(?:\\.[\\da-z\\-]+)*)?)?)?$/i;\nexport const validateAndParse = (version) => {\n if (typeof version !== 'string') {\n throw new TypeError('Invalid argument expected string');\n }\n const match = version.match(semver);\n if (!match) {\n throw new Error(`Invalid argument not valid semver ('${version}' received)`);\n }\n match.shift();\n return match;\n};\nconst isWildcard = (s) => s === '*' || s === 'x' || s === 'X';\nconst tryParse = (v) => {\n const n = parseInt(v, 10);\n return isNaN(n) ? v : n;\n};\nconst forceType = (a, b) => typeof a !== typeof b ? [String(a), String(b)] : [a, b];\nconst compareStrings = (a, b) => {\n if (isWildcard(a) || isWildcard(b))\n return 0;\n const [ap, bp] = forceType(tryParse(a), tryParse(b));\n if (ap > bp)\n return 1;\n if (ap < bp)\n return -1;\n return 0;\n};\nexport const compareSegments = (a, b) => {\n for (let i = 0; i < Math.max(a.length, b.length); i++) {\n const r = compareStrings(a[i] || '0', b[i] || '0');\n if (r !== 0)\n return r;\n }\n return 0;\n};\n//# sourceMappingURL=utils.js.map","import { compareSegments, validateAndParse } from './utils';\n/**\n * Compare [semver](https://semver.org/) version strings to find greater, equal or lesser.\n * This library supports the full semver specification, including comparing versions with different number of digits like `1.0.0`, `1.0`, `1`, and pre-release versions like `1.0.0-alpha`.\n * @param v1 - First version to compare\n * @param v2 - Second version to compare\n * @returns Numeric value compatible with the [Array.sort(fn) interface](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#Parameters).\n */\nexport const compareVersions = (v1, v2) => {\n // validate input and split into segments\n const n1 = validateAndParse(v1);\n const n2 = validateAndParse(v2);\n // pop off the patch\n const p1 = n1.pop();\n const p2 = n2.pop();\n // validate numbers\n const r = compareSegments(n1, n2);\n if (r !== 0)\n return r;\n // validate pre-release\n if (p1 && p2) {\n return compareSegments(p1.split('.'), p2.split('.'));\n }\n else if (p1 || p2) {\n return p1 ? -1 : 1;\n }\n return 0;\n};\n//# sourceMappingURL=compareVersions.js.map","import { compareVersions } from './compareVersions';\n/**\n * Compare [semver](https://semver.org/) version strings using the specified operator.\n *\n * @param v1 First version to compare\n * @param v2 Second version to compare\n * @param operator Allowed arithmetic operator to use\n * @returns `true` if the comparison between the firstVersion and the secondVersion satisfies the operator, `false` otherwise.\n *\n * @example\n * ```\n * compare('10.1.8', '10.0.4', '>'); // return true\n * compare('10.0.1', '10.0.1', '='); // return true\n * compare('10.1.1', '10.2.2', '<'); // return true\n * compare('10.1.1', '10.2.2', '<='); // return true\n * compare('10.1.1', '10.2.2', '>='); // return false\n * ```\n */\nexport const compare = (v1, v2, operator) => {\n // validate input operator\n assertValidOperator(operator);\n // since result of compareVersions can only be -1 or 0 or 1\n // a simple map can be used to replace switch\n const res = compareVersions(v1, v2);\n return operatorResMap[operator].includes(res);\n};\nconst operatorResMap = {\n '>': [1],\n '>=': [0, 1],\n '=': [0],\n '<=': [-1, 0],\n '<': [-1],\n '!=': [-1, 1],\n};\nconst allowedOperators = Object.keys(operatorResMap);\nconst assertValidOperator = (op) => {\n if (typeof op !== 'string') {\n throw new TypeError(`Invalid operator type, expected string but got ${typeof op}`);\n }\n if (allowedOperators.indexOf(op) === -1) {\n throw new Error(`Invalid operator, expected one of ${allowedOperators.join('|')}`);\n }\n};\n//# sourceMappingURL=compare.js.map","import { compare } from './compare';\nimport { compareSegments, validateAndParse } from './utils';\n/**\n * Match [npm semver](https://docs.npmjs.com/cli/v6/using-npm/semver) version range.\n *\n * @param version Version number to match\n * @param range Range pattern for version\n * @returns `true` if the version number is within the range, `false` otherwise.\n *\n * @example\n * ```\n * satisfies('1.1.0', '^1.0.0'); // return true\n * satisfies('1.1.0', '~1.0.0'); // return false\n * ```\n */\nexport const satisfies = (version, range) => {\n // clean input\n range = range.replace(/([><=]+)\\s+/g, '$1');\n // handle multiple comparators\n if (range.includes('||')) {\n return range.split('||').some((r) => satisfies(version, r));\n }\n else if (range.includes(' - ')) {\n const [a, b] = range.split(' - ', 2);\n return satisfies(version, `>=${a} <=${b}`);\n }\n else if (range.includes(' ')) {\n return range\n .trim()\n .replace(/\\s{2,}/g, ' ')\n .split(' ')\n .every((r) => satisfies(version, r));\n }\n // if no range operator then \"=\"\n const m = range.match(/^([<>=~^]+)/);\n const op = m ? m[1] : '=';\n // if gt/lt/eq then operator compare\n if (op !== '^' && op !== '~')\n return compare(version, range, op);\n // else range of either \"~\" or \"^\" is assumed\n const [v1, v2, v3, , vp] = validateAndParse(version);\n const [r1, r2, r3, , rp] = validateAndParse(range);\n const v = [v1, v2, v3];\n const r = [r1, r2 !== null && r2 !== void 0 ? r2 : 'x', r3 !== null && r3 !== void 0 ? r3 : 'x'];\n // validate pre-release\n if (rp) {\n if (!vp)\n return false;\n if (compareSegments(v, r) !== 0)\n return false;\n if (compareSegments(vp.split('.'), rp.split('.')) === -1)\n return false;\n }\n // first non-zero number\n const nonZero = r.findIndex((v) => v !== '0') + 1;\n // pointer to where segments can be >=\n const i = op === '~' ? 2 : nonZero > 1 ? nonZero : 1;\n // before pointer must be equal\n if (compareSegments(v.slice(0, i), r.slice(0, i)) !== 0)\n return false;\n // after pointer must be >=\n if (compareSegments(v.slice(i), r.slice(i)) === -1)\n return false;\n return true;\n};\n//# sourceMappingURL=satisfies.js.map","import { semver } from './utils';\n/**\n * Validate [semver](https://semver.org/) version strings.\n *\n * @param version Version number to validate\n * @returns `true` if the version number is a valid semver version number, `false` otherwise.\n *\n * @example\n * ```\n * validate('1.0.0-rc.1'); // return true\n * validate('1.0-rc.1'); // return false\n * validate('foo'); // return false\n * ```\n */\nexport const validate = (version) => typeof version === 'string' && /^[v\\d]/.test(version) && semver.test(version);\n/**\n * Validate [semver](https://semver.org/) version strings strictly. Will not accept wildcards and version ranges.\n *\n * @param version Version number to validate\n * @returns `true` if the version number is a valid semver version number `false` otherwise\n *\n * @example\n * ```\n * validate('1.0.0-rc.1'); // return true\n * validate('1.0-rc.1'); // return false\n * validate('foo'); // return false\n * ```\n */\nexport const validateStrict = (version) => typeof version === 'string' &&\n /^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$/.test(version);\n//# sourceMappingURL=validate.js.map"],"names":[],"mappings":";;;;;;IAAO,MAAM,MAAM,GAAG,4IAA4I,CAAC;IAC5J,MAAM,gBAAgB,GAAG,CAAC,OAAO,KAAK;IAC7C,IAAI,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;IACrC,QAAQ,MAAM,IAAI,SAAS,CAAC,kCAAkC,CAAC,CAAC;IAChE,KAAK;IACL,IAAI,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IACxC,IAAI,IAAI,CAAC,KAAK,EAAE;IAChB,QAAQ,MAAM,IAAI,KAAK,CAAC,CAAC,oCAAoC,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC;IACrF,KAAK;IACL,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;IAClB,IAAI,OAAO,KAAK,CAAC;IACjB,CAAC,CAAC;IACF,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,GAAG,CAAC;IAC9D,MAAM,Q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,CAAC;IACrB,IAAI,OAAO,IAAI,CAAC;IAChB;;IC/DA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;AACY,UAAC,QAAQ,GAAG,CAAC,OAAO,KAAK,OAAO,OAAO,KAAK,QAAQ,IAAI,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE;IACnH;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;AACY,UAAC,cAAc,GAAG,CAAC,OAAO,KAAK,OAAO,OAAO,KAAK,QAAQ;IACtE,IAAI,qLAAqL,CAAC,IAAI,CAAC,OAAO;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "compare-versions",
|
|
3
|
+
"version": "6.1.0",
|
|
4
|
+
"description": "Compare semver version strings to find greater, equal or lesser.",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/omichelsen/compare-versions.git"
|
|
8
|
+
},
|
|
9
|
+
"author": "Ole Michelsen",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/omichelsen/compare-versions/issues"
|
|
13
|
+
},
|
|
14
|
+
"homepage": "https://github.com/omichelsen/compare-versions#readme",
|
|
15
|
+
"keywords": [
|
|
16
|
+
"semver",
|
|
17
|
+
"version",
|
|
18
|
+
"compare",
|
|
19
|
+
"browser",
|
|
20
|
+
"node"
|
|
21
|
+
],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "npm run build:esm && npm run build:umd",
|
|
24
|
+
"build:esm": "tsc --module esnext --target es2017 --outDir lib/esm",
|
|
25
|
+
"build:umd": "rollup lib/esm/index.js --format umd --name compareVersions --sourcemap -o lib/umd/index.js",
|
|
26
|
+
"prepublishOnly": "npm run build",
|
|
27
|
+
"test": "c8 --reporter=lcov mocha -r ts-node/register test/**/*.ts"
|
|
28
|
+
},
|
|
29
|
+
"main": "./lib/umd/index.js",
|
|
30
|
+
"module": "./lib/esm/index.js",
|
|
31
|
+
"types": "./lib/esm/index.d.ts",
|
|
32
|
+
"sideEffects": false,
|
|
33
|
+
"files": [
|
|
34
|
+
"lib",
|
|
35
|
+
"src"
|
|
36
|
+
],
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@types/mocha": "^10.0.1",
|
|
39
|
+
"c8": "^8.0.1",
|
|
40
|
+
"mocha": "^10.0.0",
|
|
41
|
+
"rollup": "^3.7.4",
|
|
42
|
+
"ts-node": "^10.7.0",
|
|
43
|
+
"typescript": "^5.1.6"
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { compareVersions } from './compareVersions';
|
|
2
|
+
import { CompareOperator } from './utils';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Compare [semver](https://semver.org/) version strings using the specified operator.
|
|
6
|
+
*
|
|
7
|
+
* @param v1 First version to compare
|
|
8
|
+
* @param v2 Second version to compare
|
|
9
|
+
* @param operator Allowed arithmetic operator to use
|
|
10
|
+
* @returns `true` if the comparison between the firstVersion and the secondVersion satisfies the operator, `false` otherwise.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```
|
|
14
|
+
* compare('10.1.8', '10.0.4', '>'); // return true
|
|
15
|
+
* compare('10.0.1', '10.0.1', '='); // return true
|
|
16
|
+
* compare('10.1.1', '10.2.2', '<'); // return true
|
|
17
|
+
* compare('10.1.1', '10.2.2', '<='); // return true
|
|
18
|
+
* compare('10.1.1', '10.2.2', '>='); // return false
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export const compare = (v1: string, v2: string, operator: CompareOperator) => {
|
|
22
|
+
// validate input operator
|
|
23
|
+
assertValidOperator(operator);
|
|
24
|
+
|
|
25
|
+
// since result of compareVersions can only be -1 or 0 or 1
|
|
26
|
+
// a simple map can be used to replace switch
|
|
27
|
+
const res = compareVersions(v1, v2);
|
|
28
|
+
|
|
29
|
+
return operatorResMap[operator].includes(res);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const operatorResMap = {
|
|
33
|
+
'>': [1],
|
|
34
|
+
'>=': [0, 1],
|
|
35
|
+
'=': [0],
|
|
36
|
+
'<=': [-1, 0],
|
|
37
|
+
'<': [-1],
|
|
38
|
+
'!=': [-1, 1],
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const allowedOperators = Object.keys(operatorResMap);
|
|
42
|
+
|
|
43
|
+
const assertValidOperator = (op: string) => {
|
|
44
|
+
if (typeof op !== 'string') {
|
|
45
|
+
throw new TypeError(
|
|
46
|
+
`Invalid operator type, expected string but got ${typeof op}`
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
if (allowedOperators.indexOf(op) === -1) {
|
|
50
|
+
throw new Error(
|
|
51
|
+
`Invalid operator, expected one of ${allowedOperators.join('|')}`
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { compareSegments, validateAndParse } from './utils';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Compare [semver](https://semver.org/) version strings to find greater, equal or lesser.
|
|
5
|
+
* This library supports the full semver specification, including comparing versions with different number of digits like `1.0.0`, `1.0`, `1`, and pre-release versions like `1.0.0-alpha`.
|
|
6
|
+
* @param v1 - First version to compare
|
|
7
|
+
* @param v2 - Second version to compare
|
|
8
|
+
* @returns Numeric value compatible with the [Array.sort(fn) interface](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#Parameters).
|
|
9
|
+
*/
|
|
10
|
+
export const compareVersions = (v1: string, v2: string) => {
|
|
11
|
+
// validate input and split into segments
|
|
12
|
+
const n1 = validateAndParse(v1);
|
|
13
|
+
const n2 = validateAndParse(v2);
|
|
14
|
+
|
|
15
|
+
// pop off the patch
|
|
16
|
+
const p1 = n1.pop();
|
|
17
|
+
const p2 = n2.pop();
|
|
18
|
+
|
|
19
|
+
// validate numbers
|
|
20
|
+
const r = compareSegments(n1, n2);
|
|
21
|
+
if (r !== 0) return r;
|
|
22
|
+
|
|
23
|
+
// validate pre-release
|
|
24
|
+
if (p1 && p2) {
|
|
25
|
+
return compareSegments(p1.split('.'), p2.split('.'));
|
|
26
|
+
} else if (p1 || p2) {
|
|
27
|
+
return p1 ? -1 : 1;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return 0;
|
|
31
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { compare } from './compare';
|
|
2
|
+
import { CompareOperator, compareSegments, validateAndParse } from './utils';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Match [npm semver](https://docs.npmjs.com/cli/v6/using-npm/semver) version range.
|
|
6
|
+
*
|
|
7
|
+
* @param version Version number to match
|
|
8
|
+
* @param range Range pattern for version
|
|
9
|
+
* @returns `true` if the version number is within the range, `false` otherwise.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```
|
|
13
|
+
* satisfies('1.1.0', '^1.0.0'); // return true
|
|
14
|
+
* satisfies('1.1.0', '~1.0.0'); // return false
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export const satisfies = (version: string, range: string): boolean => {
|
|
18
|
+
// clean input
|
|
19
|
+
range = range.replace(/([><=]+)\s+/g, '$1');
|
|
20
|
+
|
|
21
|
+
// handle multiple comparators
|
|
22
|
+
if (range.includes('||')) {
|
|
23
|
+
return range.split('||').some((r) => satisfies(version, r));
|
|
24
|
+
} else if (range.includes(' - ')) {
|
|
25
|
+
const [a, b] = range.split(' - ', 2);
|
|
26
|
+
return satisfies(version, `>=${a} <=${b}`);
|
|
27
|
+
} else if (range.includes(' ')) {
|
|
28
|
+
return range
|
|
29
|
+
.trim()
|
|
30
|
+
.replace(/\s{2,}/g, ' ')
|
|
31
|
+
.split(' ')
|
|
32
|
+
.every((r) => satisfies(version, r));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// if no range operator then "="
|
|
36
|
+
const m = range.match(/^([<>=~^]+)/);
|
|
37
|
+
const op = m ? m[1] : '=';
|
|
38
|
+
|
|
39
|
+
// if gt/lt/eq then operator compare
|
|
40
|
+
if (op !== '^' && op !== '~')
|
|
41
|
+
return compare(version, range, op as CompareOperator);
|
|
42
|
+
|
|
43
|
+
// else range of either "~" or "^" is assumed
|
|
44
|
+
const [v1, v2, v3, , vp] = validateAndParse(version);
|
|
45
|
+
const [r1, r2, r3, , rp] = validateAndParse(range);
|
|
46
|
+
const v = [v1, v2, v3];
|
|
47
|
+
const r = [r1, r2 ?? 'x', r3 ?? 'x'];
|
|
48
|
+
|
|
49
|
+
// validate pre-release
|
|
50
|
+
if (rp) {
|
|
51
|
+
if (!vp) return false;
|
|
52
|
+
if (compareSegments(v, r) !== 0) return false;
|
|
53
|
+
if (compareSegments(vp.split('.'), rp.split('.')) === -1) return false;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// first non-zero number
|
|
57
|
+
const nonZero = r.findIndex((v) => v !== '0') + 1;
|
|
58
|
+
|
|
59
|
+
// pointer to where segments can be >=
|
|
60
|
+
const i = op === '~' ? 2 : nonZero > 1 ? nonZero : 1;
|
|
61
|
+
|
|
62
|
+
// before pointer must be equal
|
|
63
|
+
if (compareSegments(v.slice(0, i), r.slice(0, i)) !== 0) return false;
|
|
64
|
+
|
|
65
|
+
// after pointer must be >=
|
|
66
|
+
if (compareSegments(v.slice(i), r.slice(i)) === -1) return false;
|
|
67
|
+
|
|
68
|
+
return true;
|
|
69
|
+
};
|