@vltpkg/semver 0.0.0-0.1730239248325

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.
@@ -0,0 +1,246 @@
1
+ import { Range } from './range.js';
2
+ import { IncrementType, Version } from './version.js';
3
+ export * from './comparator.js';
4
+ export * from './range.js';
5
+ export * from './version.js';
6
+ /** Return the parsed version string, or `undefined` if invalid */
7
+ export declare const parse: (version: Version | string) => Version | undefined;
8
+ /** Return the parsed version range, or `undefined` if invalid */
9
+ export declare const parseRange: (range: Range | string, includePrerelease?: boolean) => Range | undefined;
10
+ /**
11
+ * return true if the version is valid
12
+ *
13
+ * Note: do not use this if you intend to immediately parse the version if it's
14
+ * valid. Just use {@link parse}, and guard the possible undefined value, or
15
+ * use `Version.parse(..)` to throw on invalid values.
16
+ */
17
+ export declare const valid: (version: Version | string) => boolean;
18
+ /**
19
+ * return true if the range is valid
20
+ *
21
+ * Note: do not use this if you intend to immediately parse the range if it's
22
+ * valid. Just use {@link parseRange}, and guard the possible undefined value,
23
+ * or use `new Range(..)` to throw on invalid values.
24
+ */
25
+ export declare const validRange: (range: Range | string) => boolean;
26
+ /**
27
+ * Return true if the version satisfies the range.
28
+ */
29
+ export declare const satisfies: (version: Version | string, range: Range | string, includePrerelease?: boolean) => boolean;
30
+ /**
31
+ * Increment the specified part of the version, and return the resulting
32
+ * object. If a Version object is provided, it will be modified in-place.
33
+ *
34
+ * Part behaviors:
35
+ *
36
+ * - `'major'` If the version is a `M.0.0-...` version with a prerelease, then
37
+ * simply drop the prerelease. Otherwise, set the minor and patch to 0, and
38
+ * increment the major. So `1.0.0-beta` becomes `1.0.0`, and `1.2.3` becomes
39
+ * `2.0.0`
40
+ *
41
+ * - `'minor'` If the version is a `M.m.0-...` version with a prerelease, then
42
+ * simply drop the prerelease. Otherwise, set the patch to 0, and increment the
43
+ * minor. So `1.2.0-beta` becomes `1.2.0`, and `1.2.3` becomes `1.3.0`.
44
+ *
45
+ * - `'patch'` If the version has a prerelease, then simply drop the
46
+ * prerelease. Otherwise, increment the patch value. So `1.2.3-beta` becomes
47
+ * `1.2.3` and `1.2.3` becomes `1.2.4`.
48
+ *
49
+ * - `'premajor'` Set the patch and minor versions to `0`, increment the major
50
+ * version, and add a prerelease, using the optional identifier.
51
+ *
52
+ * - `'preminor'` Set the patch version to `0`, increment the minor version,
53
+ * and add a prerelease, using the optional identifier.
54
+ *
55
+ * - `'prepatch'` If a prerelease is already present, increment the patch
56
+ * version, otherwise leave it untouched, and add a prerelease, using the
57
+ * optional identifier.
58
+ *
59
+ * - `'prerelease'` If a prerelease version is present, then behave the same as
60
+ * `'prepatch'`. Otherwise, add a prerelease, using the optional identifier.
61
+ *
62
+ * - `'pre'` This is mostly for use by the other prerelease incrementers.
63
+ *
64
+ * - If a prerelease identifier is provided:
65
+ *
66
+ * Update that named portion of the prerelease. For example,
67
+ * `inc('1.2.3-beta.4', 'pre', 'beta')` would result in `1.2.3-beta.5`.
68
+ *
69
+ * If there is no prerelease identifier by that name, then replace the
70
+ * prerelease with `[name]`. So `inc('1.2.3-alpha.4', 'pre', 'beta')`
71
+ * would result in `1.2.3-beta`.
72
+ *
73
+ * If the prerelease identifer is present, but has no numeric value
74
+ * following it, then add `0`. So `inc('1.2.3-beta', 'pre', 'beta')`
75
+ * would result in `1.2.3-beta.0`.
76
+ *
77
+ * - If no prerelease identifier is provided:
78
+ *
79
+ * If there is no current prerelease, then set the prerelease to `0`. So,
80
+ * `inc('1.2.3', 'pre')` becomes `1.2.3-0`.
81
+ *
82
+ * If the last item in the prerelease is numeric, then increment it. So,
83
+ * `inc('1.2.3-beta.3', 'pre')` becomes `1.2.3-beta.4`.
84
+ */
85
+ export declare const inc: (version: Version | string, part: IncrementType, prereleaseIdentifier?: string) => Version;
86
+ /**
87
+ * The method used by {@link sort}, exported for passing directly to
88
+ * `Array.sort`.
89
+ *
90
+ * Usage:
91
+ *
92
+ * ```ts
93
+ * import { sortMethod } from '@vltpkg/semver'
94
+ * const versions = ['1.2.3', '5.2.3', '2.3.4']
95
+ * console.log(versions.sort(sortMethod))
96
+ * // ['1.2.3', '2.3.4', '5.2.3']
97
+ * ```
98
+ */
99
+ export declare const sortMethod: (a: Version | string, b: Version | string) => number;
100
+ /**
101
+ * Sort an array of version strings or objects in ascending SemVer precedence
102
+ * order (ie, lowest versions first).
103
+ *
104
+ * Invalid version strings are sorted to the end of the array in ascending
105
+ * alphabetical order.
106
+ *
107
+ * Note: when using this method, the list is cloned prior to sorting, to
108
+ * prevent surprising mutation. To sort the list in place, see
109
+ * {@link sortMethod}.
110
+ */
111
+ export declare const sort: <T extends Version | string = string | Version>(list: T[]) => T[];
112
+ /**
113
+ * Sort an array of version strings or objects in descending SemVer
114
+ * precedence order (ie, highest versions first).
115
+ *
116
+ * Invalid version strings are sorted to the end of the array in ascending
117
+ * alphabetical order.
118
+ *
119
+ * Note: when using this method, the list is cloned prior to sorting, to
120
+ * prevent surprising mutation. To sort the list in place, see
121
+ * {@link rsortMethod}.
122
+ */
123
+ export declare const rsort: <T extends Version | string = string | Version>(list: T[]) => T[];
124
+ /**
125
+ * The method used by {@link rsort}, exported for passing directly to
126
+ * `Array.sort`.
127
+ *
128
+ * Usage:
129
+ *
130
+ * ```ts
131
+ * import { rsortMethod } from '@vltpkg/semver'
132
+ * const versions = ['1.2.3', '5.2.3', '2.3.4']
133
+ * console.log(versions.sort(rsortMethod))
134
+ * // ['5.2.3', '2.3.4', '1.2.3']
135
+ * ```
136
+ */
137
+ export declare const rsortMethod: (a: Version | string, b: Version | string) => number;
138
+ /**
139
+ * Method used by {@link filter}, for use in `Array.filter` directly.
140
+ *
141
+ * Usage:
142
+ *
143
+ * ```ts
144
+ * import { filterMethod } from '@vltpkg/semver'
145
+ * const versions = ['1.2.3', '5.2.3', '2.3.4']
146
+ * console.log(versions.filter(filterMethod('>=2.x')))
147
+ * // ['5.2.3', '2.3.4']
148
+ * ```
149
+ */
150
+ export declare const filterMethod: (range: Range | string, includePrerelease?: boolean) => ((version: Version | string) => boolean);
151
+ /**
152
+ * Filter a list of versions to find all that match a given range.
153
+ */
154
+ export declare const filter: <T extends Version | string = string | Version>(list: T[], range: Range | string, includePrerelease?: boolean) => T[];
155
+ /**
156
+ * Find the highest-precedence match for a range within a list of versions
157
+ *
158
+ * Returns `undefined` if no match was found.
159
+ */
160
+ export declare const highest: (list: (Version | string)[], range: Range | string, includePrerelease?: boolean) => Version | undefined;
161
+ /**
162
+ * Faster form of {@link highest}, for use when the list is sorted
163
+ * in precedence order (lower-precedence versions first).
164
+ *
165
+ * Note: This stops at the first match, and will produce incorrect results
166
+ * when the list is not properly sorted!
167
+ */
168
+ export declare const sortedHighest: (list: (Version | string)[], range: Range | string, includePrerelease?: boolean) => Version | undefined;
169
+ /**
170
+ * Faster form of {@link highest}, for use when the list is sorted
171
+ * in reverse precedence order (higher-precedence versions first).
172
+ *
173
+ * Note: This stops at the first match, and will produce incorrect results
174
+ * when the list is not properly sorted!
175
+ */
176
+ export declare const rsortedHighest: (list: (Version | string)[], range: Range | string, includePrerelease?: boolean) => Version | undefined;
177
+ /**
178
+ * Find the lowest-precedence match for a range within a list of versions
179
+ *
180
+ * Returns `undefined` if no match was found.
181
+ */
182
+ export declare const lowest: (list: (Version | string)[], range: Range | string, includePrerelease?: boolean) => Version | undefined;
183
+ /**
184
+ * Faster form of {@link lowest}, for use when the list is sorted
185
+ * in precedence order (lower-precedence versions first).
186
+ *
187
+ * Note: This stops at the first match, and will produce incorrect results
188
+ * when the list is not properly sorted!
189
+ */
190
+ export declare const sortedLowest: (list: (Version | string)[], range: Range | string, includePrerelease?: boolean) => Version | undefined;
191
+ /**
192
+ * Faster form of {@link lowest}, for use when the list is sorted
193
+ * in reverse precedence order (higher-precedence versions first).
194
+ *
195
+ * Note: This stops at the first match, and will produce incorrect results
196
+ * when the list is not properly sorted!
197
+ */
198
+ export declare const rsortedLowest: (list: (Version | string)[], range: Range | string, includePrerelease?: boolean) => Version | undefined;
199
+ /**
200
+ * Same as {@link sortMethod}, but throws if either version is not valid.
201
+ * 1 if versionA is higher precedence than versionB
202
+ * -1 if versionA is lower precedence than versionB
203
+ * 0 if they have equal precedence
204
+ */
205
+ export declare const compare: (versionA: Version | string, versionB: Version | string) => 0 | 1 | -1;
206
+ /**
207
+ * Inverse of {@link compare}
208
+ *
209
+ * Same as {@link rsortMethod}, but throws if either version is not valid.
210
+ *
211
+ * -1 if versionA is higher precedence than versionB
212
+ * 1 if versionA is lower precedence than versionB
213
+ * 0 if they have equal precedence
214
+ */
215
+ export declare const rcompare: (versionA: Version | string, versionB: Version | string) => 0 | 1 | -1;
216
+ /** true if versionA is > versionB. throws on invalid values */
217
+ export declare const gt: (versionA: Version | string, versionB: Version | string) => boolean;
218
+ /** true if versionA is >= versionB. throws on invalid values */
219
+ export declare const gte: (versionA: Version | string, versionB: Version | string) => boolean;
220
+ /** true if versionA is < versionB. throws on invalid values */
221
+ export declare const lt: (versionA: Version | string, versionB: Version | string) => boolean;
222
+ /** true if versionA is <= versionB. throws on invalid values */
223
+ export declare const lte: (versionA: Version | string, versionB: Version | string) => boolean;
224
+ /** true if versionA is not equal to versionB. throws on invalid values */
225
+ export declare const neq: (versionA: Version | string, versionB: Version | string) => boolean;
226
+ /** true if versionA is equal to versionB. throws on invalid values */
227
+ export declare const eq: (versionA: Version | string, versionB: Version | string) => boolean;
228
+ /** extract the major version number, or undefined if invalid */
229
+ export declare const major: (version: Version | string) => number | undefined;
230
+ /** extract the minor version number, or undefined if invalid */
231
+ export declare const minor: (version: Version | string) => number | undefined;
232
+ /** extract the patch version number, or undefined if invalid */
233
+ export declare const patch: (version: Version | string) => number | undefined;
234
+ /**
235
+ * extract the list of prerelease identifiers, or undefined if the version
236
+ * is invalid. If no prerelease identifiers are present, returns `[]`.
237
+ */
238
+ export declare const prerelease: (version: Version | string) => (string | number)[] | undefined;
239
+ /**
240
+ * extract the list of build identifiers, or undefined if the version
241
+ * is invalid. If no build identifiers are present, returns `[]`.
242
+ */
243
+ export declare const build: (version: Version | string) => string[] | undefined;
244
+ /** return all versions that do not have any prerelease identifiers */
245
+ export declare const stable: <T extends Version | string = string | Version>(versions: T[]) => T[];
246
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAGrD,cAAc,iBAAiB,CAAA;AAC/B,cAAc,YAAY,CAAA;AAC1B,cAAc,cAAc,CAAA;AAE5B,kEAAkE;AAClE,eAAO,MAAM,KAAK,YAAa,OAAO,GAAG,MAAM,wBAO9C,CAAA;AAED,iEAAiE;AACjE,eAAO,MAAM,UAAU,UACd,KAAK,GAAG,MAAM,mDAYtB,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,KAAK,YAAa,OAAO,GAAG,MAAM,YAAqB,CAAA;AAEpE;;;;;;GAMG;AACH,eAAO,MAAM,UAAU,UAAW,KAAK,GAAG,MAAM,YAC3B,CAAA;AAErB;;GAEG;AACH,eAAO,MAAM,SAAS,YACX,OAAO,GAAG,MAAM,SAClB,KAAK,GAAG,MAAM,yCActB,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AACH,eAAO,MAAM,GAAG,YACL,OAAO,GAAG,MAAM,QACnB,aAAa,yBACI,MAAM,YAKI,CAAA;AAEnC;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,UAAU,MAClB,OAAO,GAAG,MAAM,KAChB,OAAO,GAAG,MAAM,WAUpB,CAAA;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,IAAI,GAAI,CAAC,SAAS,OAAO,GAAG,MAAM,2BACvC,CAAC,EAAE,KACR,CAAC,EAAmC,CAAA;AAEvC;;;;;;;;;;GAUG;AACH,eAAO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AAG,MAAM,yBAI9C,CAAA;AAED,sEAAsE;AACtE,eAAO,MAAM,MAAM,GAAI,CAAC,SAAS,OAAO,GAAG,MAAM,+BACrC,CAAC,EAAE,KACZ,CAAC,EAKA,CAAA"}
@@ -0,0 +1,400 @@
1
+ import { Range } from './range.js';
2
+ import { Version } from './version.js';
3
+ import { syntaxError } from '@vltpkg/error-cause';
4
+ export * from './comparator.js';
5
+ export * from './range.js';
6
+ export * from './version.js';
7
+ /** Return the parsed version string, or `undefined` if invalid */
8
+ export const parse = (version) => {
9
+ if (version instanceof Version)
10
+ return version;
11
+ try {
12
+ return Version.parse(String(version));
13
+ }
14
+ catch {
15
+ return undefined;
16
+ }
17
+ };
18
+ /** Return the parsed version range, or `undefined` if invalid */
19
+ export const parseRange = (range, includePrerelease = false) => {
20
+ if (typeof range === 'object') {
21
+ if (range.includePrerelease === includePrerelease)
22
+ return range;
23
+ range = range.raw;
24
+ }
25
+ try {
26
+ return new Range(range, includePrerelease);
27
+ }
28
+ catch {
29
+ return undefined;
30
+ }
31
+ };
32
+ /**
33
+ * return true if the version is valid
34
+ *
35
+ * Note: do not use this if you intend to immediately parse the version if it's
36
+ * valid. Just use {@link parse}, and guard the possible undefined value, or
37
+ * use `Version.parse(..)` to throw on invalid values.
38
+ */
39
+ export const valid = (version) => !!parse(version);
40
+ /**
41
+ * return true if the range is valid
42
+ *
43
+ * Note: do not use this if you intend to immediately parse the range if it's
44
+ * valid. Just use {@link parseRange}, and guard the possible undefined value,
45
+ * or use `new Range(..)` to throw on invalid values.
46
+ */
47
+ export const validRange = (range) => !!parseRange(range);
48
+ /**
49
+ * Return true if the version satisfies the range.
50
+ */
51
+ export const satisfies = (version, range, includePrerelease = false) => {
52
+ if (typeof version === 'string') {
53
+ const parsed = parse(version);
54
+ if (!parsed)
55
+ return false;
56
+ version = parsed;
57
+ }
58
+ if (typeof range === 'string') {
59
+ const parsed = parseRange(range, includePrerelease);
60
+ if (!parsed)
61
+ return false;
62
+ range = parsed;
63
+ }
64
+ return version.satisfies(range);
65
+ };
66
+ /**
67
+ * Increment the specified part of the version, and return the resulting
68
+ * object. If a Version object is provided, it will be modified in-place.
69
+ *
70
+ * Part behaviors:
71
+ *
72
+ * - `'major'` If the version is a `M.0.0-...` version with a prerelease, then
73
+ * simply drop the prerelease. Otherwise, set the minor and patch to 0, and
74
+ * increment the major. So `1.0.0-beta` becomes `1.0.0`, and `1.2.3` becomes
75
+ * `2.0.0`
76
+ *
77
+ * - `'minor'` If the version is a `M.m.0-...` version with a prerelease, then
78
+ * simply drop the prerelease. Otherwise, set the patch to 0, and increment the
79
+ * minor. So `1.2.0-beta` becomes `1.2.0`, and `1.2.3` becomes `1.3.0`.
80
+ *
81
+ * - `'patch'` If the version has a prerelease, then simply drop the
82
+ * prerelease. Otherwise, increment the patch value. So `1.2.3-beta` becomes
83
+ * `1.2.3` and `1.2.3` becomes `1.2.4`.
84
+ *
85
+ * - `'premajor'` Set the patch and minor versions to `0`, increment the major
86
+ * version, and add a prerelease, using the optional identifier.
87
+ *
88
+ * - `'preminor'` Set the patch version to `0`, increment the minor version,
89
+ * and add a prerelease, using the optional identifier.
90
+ *
91
+ * - `'prepatch'` If a prerelease is already present, increment the patch
92
+ * version, otherwise leave it untouched, and add a prerelease, using the
93
+ * optional identifier.
94
+ *
95
+ * - `'prerelease'` If a prerelease version is present, then behave the same as
96
+ * `'prepatch'`. Otherwise, add a prerelease, using the optional identifier.
97
+ *
98
+ * - `'pre'` This is mostly for use by the other prerelease incrementers.
99
+ *
100
+ * - If a prerelease identifier is provided:
101
+ *
102
+ * Update that named portion of the prerelease. For example,
103
+ * `inc('1.2.3-beta.4', 'pre', 'beta')` would result in `1.2.3-beta.5`.
104
+ *
105
+ * If there is no prerelease identifier by that name, then replace the
106
+ * prerelease with `[name]`. So `inc('1.2.3-alpha.4', 'pre', 'beta')`
107
+ * would result in `1.2.3-beta`.
108
+ *
109
+ * If the prerelease identifer is present, but has no numeric value
110
+ * following it, then add `0`. So `inc('1.2.3-beta', 'pre', 'beta')`
111
+ * would result in `1.2.3-beta.0`.
112
+ *
113
+ * - If no prerelease identifier is provided:
114
+ *
115
+ * If there is no current prerelease, then set the prerelease to `0`. So,
116
+ * `inc('1.2.3', 'pre')` becomes `1.2.3-0`.
117
+ *
118
+ * If the last item in the prerelease is numeric, then increment it. So,
119
+ * `inc('1.2.3-beta.3', 'pre')` becomes `1.2.3-beta.4`.
120
+ */
121
+ export const inc = (version, part, prereleaseIdentifier) => (typeof version === 'string' ?
122
+ Version.parse(version)
123
+ : version).inc(part, prereleaseIdentifier);
124
+ /**
125
+ * The method used by {@link sort}, exported for passing directly to
126
+ * `Array.sort`.
127
+ *
128
+ * Usage:
129
+ *
130
+ * ```ts
131
+ * import { sortMethod } from '@vltpkg/semver'
132
+ * const versions = ['1.2.3', '5.2.3', '2.3.4']
133
+ * console.log(versions.sort(sortMethod))
134
+ * // ['1.2.3', '2.3.4', '5.2.3']
135
+ * ```
136
+ */
137
+ export const sortMethod = (a, b) => {
138
+ const pa = parse(a);
139
+ const pb = parse(b);
140
+ /* c8 ignore start - nondeterministic */
141
+ if (!pa && !pb)
142
+ return String(a).localeCompare(String(b), 'en');
143
+ if (!pa)
144
+ return 1;
145
+ if (!pb)
146
+ return -1;
147
+ /* c8 ignore stop */
148
+ return pa.compare(pb);
149
+ };
150
+ /**
151
+ * Sort an array of version strings or objects in ascending SemVer precedence
152
+ * order (ie, lowest versions first).
153
+ *
154
+ * Invalid version strings are sorted to the end of the array in ascending
155
+ * alphabetical order.
156
+ *
157
+ * Note: when using this method, the list is cloned prior to sorting, to
158
+ * prevent surprising mutation. To sort the list in place, see
159
+ * {@link sortMethod}.
160
+ */
161
+ export const sort = (list) => list.slice().sort(sortMethod);
162
+ /**
163
+ * Sort an array of version strings or objects in descending SemVer
164
+ * precedence order (ie, highest versions first).
165
+ *
166
+ * Invalid version strings are sorted to the end of the array in ascending
167
+ * alphabetical order.
168
+ *
169
+ * Note: when using this method, the list is cloned prior to sorting, to
170
+ * prevent surprising mutation. To sort the list in place, see
171
+ * {@link rsortMethod}.
172
+ */
173
+ export const rsort = (list) => list.slice().sort(rsortMethod);
174
+ /**
175
+ * The method used by {@link rsort}, exported for passing directly to
176
+ * `Array.sort`.
177
+ *
178
+ * Usage:
179
+ *
180
+ * ```ts
181
+ * import { rsortMethod } from '@vltpkg/semver'
182
+ * const versions = ['1.2.3', '5.2.3', '2.3.4']
183
+ * console.log(versions.sort(rsortMethod))
184
+ * // ['5.2.3', '2.3.4', '1.2.3']
185
+ * ```
186
+ */
187
+ export const rsortMethod = (a, b) => {
188
+ const pa = parse(a);
189
+ const pb = parse(b);
190
+ /* c8 ignore start - nondeterministic */
191
+ if (!pa && !pb)
192
+ return String(a).localeCompare(String(b), 'en');
193
+ if (!pa)
194
+ return 1;
195
+ if (!pb)
196
+ return -1;
197
+ /* c8 ignore stop */
198
+ return pa.rcompare(pb);
199
+ };
200
+ /**
201
+ * Method used by {@link filter}, for use in `Array.filter` directly.
202
+ *
203
+ * Usage:
204
+ *
205
+ * ```ts
206
+ * import { filterMethod } from '@vltpkg/semver'
207
+ * const versions = ['1.2.3', '5.2.3', '2.3.4']
208
+ * console.log(versions.filter(filterMethod('>=2.x')))
209
+ * // ['5.2.3', '2.3.4']
210
+ * ```
211
+ */
212
+ export const filterMethod = (range, includePrerelease = false) => {
213
+ const r = parseRange(range, includePrerelease);
214
+ return !r ?
215
+ () => false
216
+ : version => satisfies(version, r, r.includePrerelease);
217
+ };
218
+ /**
219
+ * Filter a list of versions to find all that match a given range.
220
+ */
221
+ export const filter = (list, range, includePrerelease = false) => list.filter(filterMethod(range, includePrerelease));
222
+ /**
223
+ * Find the highest-precedence match for a range within a list of versions
224
+ *
225
+ * Returns `undefined` if no match was found.
226
+ */
227
+ export const highest = (list, range, includePrerelease = false) => {
228
+ const r = parseRange(range, includePrerelease);
229
+ if (!r)
230
+ return undefined;
231
+ let max = undefined;
232
+ for (const v of list) {
233
+ const version = parse(v);
234
+ if (!version)
235
+ continue;
236
+ if (!version.satisfies(r))
237
+ continue;
238
+ if (!max)
239
+ max = version;
240
+ else if (version.greaterThan(max))
241
+ max = version;
242
+ }
243
+ return max;
244
+ };
245
+ /**
246
+ * Faster form of {@link highest}, for use when the list is sorted
247
+ * in precedence order (lower-precedence versions first).
248
+ *
249
+ * Note: This stops at the first match, and will produce incorrect results
250
+ * when the list is not properly sorted!
251
+ */
252
+ export const sortedHighest = (list, range, includePrerelease = false) => {
253
+ const r = parseRange(range, includePrerelease);
254
+ if (!r)
255
+ return undefined;
256
+ for (let i = list.length - 1; i >= 0; i--) {
257
+ const v = list[i];
258
+ /* c8 ignore next */
259
+ if (!v)
260
+ continue;
261
+ const version = parse(v);
262
+ if (!version)
263
+ continue;
264
+ if (!version.satisfies(r))
265
+ continue;
266
+ return version;
267
+ }
268
+ };
269
+ /**
270
+ * Faster form of {@link highest}, for use when the list is sorted
271
+ * in reverse precedence order (higher-precedence versions first).
272
+ *
273
+ * Note: This stops at the first match, and will produce incorrect results
274
+ * when the list is not properly sorted!
275
+ */
276
+ export const rsortedHighest = (list, range, includePrerelease = false) => {
277
+ const r = parseRange(range, includePrerelease);
278
+ if (!r)
279
+ return undefined;
280
+ for (const v of list) {
281
+ const version = parse(v);
282
+ if (!version)
283
+ continue;
284
+ if (!version.satisfies(r))
285
+ continue;
286
+ return version;
287
+ }
288
+ };
289
+ /**
290
+ * Find the lowest-precedence match for a range within a list of versions
291
+ *
292
+ * Returns `undefined` if no match was found.
293
+ */
294
+ export const lowest = (list, range, includePrerelease = false) => {
295
+ const r = parseRange(range, includePrerelease);
296
+ if (!r)
297
+ return undefined;
298
+ let min = undefined;
299
+ for (const v of list) {
300
+ const version = parse(v);
301
+ if (!version)
302
+ continue;
303
+ if (!version.satisfies(r))
304
+ continue;
305
+ if (!min)
306
+ min = version;
307
+ else if (version.lessThan(min))
308
+ min = version;
309
+ }
310
+ return min;
311
+ };
312
+ /**
313
+ * Faster form of {@link lowest}, for use when the list is sorted
314
+ * in precedence order (lower-precedence versions first).
315
+ *
316
+ * Note: This stops at the first match, and will produce incorrect results
317
+ * when the list is not properly sorted!
318
+ */
319
+ export const sortedLowest = (list, range, includePrerelease = false) => rsortedHighest(list, range, includePrerelease);
320
+ /**
321
+ * Faster form of {@link lowest}, for use when the list is sorted
322
+ * in reverse precedence order (higher-precedence versions first).
323
+ *
324
+ * Note: This stops at the first match, and will produce incorrect results
325
+ * when the list is not properly sorted!
326
+ */
327
+ export const rsortedLowest = (list, range, includePrerelease = false) => sortedHighest(list, range, includePrerelease);
328
+ /**
329
+ * Same as {@link sortMethod}, but throws if either version is not valid.
330
+ * 1 if versionA is higher precedence than versionB
331
+ * -1 if versionA is lower precedence than versionB
332
+ * 0 if they have equal precedence
333
+ */
334
+ export const compare = (versionA, versionB) => {
335
+ const a = parse(versionA);
336
+ if (!a) {
337
+ throw syntaxError('invalid version', { found: versionA });
338
+ }
339
+ const b = parse(versionB);
340
+ if (!b) {
341
+ throw syntaxError('invalid version', { found: versionB });
342
+ }
343
+ return a.compare(b);
344
+ };
345
+ /**
346
+ * Inverse of {@link compare}
347
+ *
348
+ * Same as {@link rsortMethod}, but throws if either version is not valid.
349
+ *
350
+ * -1 if versionA is higher precedence than versionB
351
+ * 1 if versionA is lower precedence than versionB
352
+ * 0 if they have equal precedence
353
+ */
354
+ export const rcompare = (versionA, versionB) => compare(versionB, versionA);
355
+ /** true if versionA is > versionB. throws on invalid values */
356
+ export const gt = (versionA, versionB) => compare(versionA, versionB) > 0;
357
+ /** true if versionA is >= versionB. throws on invalid values */
358
+ export const gte = (versionA, versionB) => compare(versionA, versionB) >= 0;
359
+ /** true if versionA is < versionB. throws on invalid values */
360
+ export const lt = (versionA, versionB) => compare(versionA, versionB) < 0;
361
+ /** true if versionA is <= versionB. throws on invalid values */
362
+ export const lte = (versionA, versionB) => compare(versionA, versionB) <= 0;
363
+ /** true if versionA is not equal to versionB. throws on invalid values */
364
+ export const neq = (versionA, versionB) => compare(versionA, versionB) !== 0;
365
+ /** true if versionA is equal to versionB. throws on invalid values */
366
+ export const eq = (versionA, versionB) => compare(versionA, versionB) === 0;
367
+ /** extract the major version number, or undefined if invalid */
368
+ export const major = (version) => parse(version)?.major;
369
+ /** extract the minor version number, or undefined if invalid */
370
+ export const minor = (version) => parse(version)?.minor;
371
+ /** extract the patch version number, or undefined if invalid */
372
+ export const patch = (version) => parse(version)?.patch;
373
+ /**
374
+ * extract the list of prerelease identifiers, or undefined if the version
375
+ * is invalid. If no prerelease identifiers are present, returns `[]`.
376
+ */
377
+ export const prerelease = (version) => {
378
+ const p = parse(version);
379
+ if (!p)
380
+ return undefined;
381
+ return p.prerelease ?? [];
382
+ };
383
+ /**
384
+ * extract the list of build identifiers, or undefined if the version
385
+ * is invalid. If no build identifiers are present, returns `[]`.
386
+ */
387
+ export const build = (version) => {
388
+ const p = parse(version);
389
+ if (!p)
390
+ return undefined;
391
+ return p.build ?? [];
392
+ };
393
+ /** return all versions that do not have any prerelease identifiers */
394
+ export const stable = (versions) => versions.filter(v => {
395
+ const p = parse(v);
396
+ if (!p)
397
+ return false;
398
+ return !p.prerelease?.length;
399
+ });
400
+ //# sourceMappingURL=index.js.map