@gjsify/semver 0.3.16 → 0.3.17
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/lib/esm/index.js +1 -394
- package/package.json +3 -3
package/lib/esm/index.js
CHANGED
|
@@ -1,394 +1 @@
|
|
|
1
|
-
|
|
2
|
-
const NUM_RE = /^(0|[1-9]\d*)$/;
|
|
3
|
-
const SEMVER_RE = /^(\d+)\.(\d+)\.(\d+)(?:-((?:[0-9A-Za-z-]+)(?:\.[0-9A-Za-z-]+)*))?(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?$/;
|
|
4
|
-
function parse(version) {
|
|
5
|
-
try {
|
|
6
|
-
return new SemVer(version);
|
|
7
|
-
} catch {
|
|
8
|
-
return null;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
function valid(version) {
|
|
12
|
-
const v = parse(version);
|
|
13
|
-
return v ? v.version : null;
|
|
14
|
-
}
|
|
15
|
-
function compare(a, b) {
|
|
16
|
-
const av = a instanceof SemVer ? a : new SemVer(a);
|
|
17
|
-
const bv = b instanceof SemVer ? b : new SemVer(b);
|
|
18
|
-
return av.compare(bv);
|
|
19
|
-
}
|
|
20
|
-
function satisfies(version, range) {
|
|
21
|
-
const r = range instanceof Range ? range : new Range(range);
|
|
22
|
-
const v = version instanceof SemVer ? version : parse(String(version));
|
|
23
|
-
if (!v) return false;
|
|
24
|
-
return r.test(v);
|
|
25
|
-
}
|
|
26
|
-
function maxSatisfying(versions, range) {
|
|
27
|
-
const r = range instanceof Range ? range : new Range(range);
|
|
28
|
-
let best = null;
|
|
29
|
-
for (const raw of versions) {
|
|
30
|
-
const v = parse(raw);
|
|
31
|
-
if (!v || !r.test(v)) continue;
|
|
32
|
-
if (best === null || v.compare(best) > 0) best = v;
|
|
33
|
-
}
|
|
34
|
-
return best ? best.version : null;
|
|
35
|
-
}
|
|
36
|
-
function minSatisfying(versions, range) {
|
|
37
|
-
const r = range instanceof Range ? range : new Range(range);
|
|
38
|
-
let best = null;
|
|
39
|
-
for (const raw of versions) {
|
|
40
|
-
const v = parse(raw);
|
|
41
|
-
if (!v || !r.test(v)) continue;
|
|
42
|
-
if (best === null || v.compare(best) < 0) best = v;
|
|
43
|
-
}
|
|
44
|
-
return best ? best.version : null;
|
|
45
|
-
}
|
|
46
|
-
function validRange(range) {
|
|
47
|
-
try {
|
|
48
|
-
return new Range(range).format();
|
|
49
|
-
} catch {
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
var SemVer = class {
|
|
54
|
-
major;
|
|
55
|
-
minor;
|
|
56
|
-
patch;
|
|
57
|
-
prerelease;
|
|
58
|
-
build;
|
|
59
|
-
version;
|
|
60
|
-
constructor(version) {
|
|
61
|
-
const trimmed = String(version).trim().replace(/^v/, "");
|
|
62
|
-
const m = SEMVER_RE.exec(trimmed);
|
|
63
|
-
if (!m) throw new TypeError(`Invalid Version: ${version}`);
|
|
64
|
-
this.major = Number(m[1]);
|
|
65
|
-
this.minor = Number(m[2]);
|
|
66
|
-
this.patch = Number(m[3]);
|
|
67
|
-
this.prerelease = m[4] ? m[4].split(".").map((id) => NUM_RE.test(id) ? Number(id) : id) : [];
|
|
68
|
-
this.build = m[5] ? m[5].split(".") : [];
|
|
69
|
-
this.version = `${this.major}.${this.minor}.${this.patch}` + (this.prerelease.length ? `-${this.prerelease.join(".")}` : "") + (this.build.length ? `+${this.build.join(".")}` : "");
|
|
70
|
-
}
|
|
71
|
-
compare(other) {
|
|
72
|
-
if (this.major !== other.major) return this.major < other.major ? -1 : 1;
|
|
73
|
-
if (this.minor !== other.minor) return this.minor < other.minor ? -1 : 1;
|
|
74
|
-
if (this.patch !== other.patch) return this.patch < other.patch ? -1 : 1;
|
|
75
|
-
return this.comparePre(other);
|
|
76
|
-
}
|
|
77
|
-
comparePre(other) {
|
|
78
|
-
const a = this.prerelease;
|
|
79
|
-
const b = other.prerelease;
|
|
80
|
-
if (a.length === 0 && b.length === 0) return 0;
|
|
81
|
-
if (a.length === 0) return 1;
|
|
82
|
-
if (b.length === 0) return -1;
|
|
83
|
-
for (let i = 0;; i++) {
|
|
84
|
-
const x = a[i];
|
|
85
|
-
const y = b[i];
|
|
86
|
-
if (x === undefined && y === undefined) return 0;
|
|
87
|
-
if (y === undefined) return 1;
|
|
88
|
-
if (x === undefined) return -1;
|
|
89
|
-
if (x === y) continue;
|
|
90
|
-
const xn = typeof x === "number";
|
|
91
|
-
const yn = typeof y === "number";
|
|
92
|
-
if (xn && !yn) return -1;
|
|
93
|
-
if (!xn && yn) return 1;
|
|
94
|
-
return x < y ? -1 : 1;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
toString() {
|
|
98
|
-
return this.version;
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
var Range = class Range {
|
|
102
|
-
raw;
|
|
103
|
-
set;
|
|
104
|
-
constructor(range) {
|
|
105
|
-
if (range instanceof Range) {
|
|
106
|
-
this.raw = range.raw;
|
|
107
|
-
this.set = range.set;
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
this.raw = String(range).trim();
|
|
111
|
-
const sets = this.raw.split(/\s*\|\|\s*/);
|
|
112
|
-
const parsed = [];
|
|
113
|
-
for (const part of sets) {
|
|
114
|
-
const c = parseRangePart(part);
|
|
115
|
-
if (c.length === 0) {
|
|
116
|
-
throw new TypeError(`Invalid range: ${this.raw}`);
|
|
117
|
-
}
|
|
118
|
-
parsed.push(c);
|
|
119
|
-
}
|
|
120
|
-
if (parsed.length === 0) {
|
|
121
|
-
throw new TypeError(`Invalid range: ${this.raw}`);
|
|
122
|
-
}
|
|
123
|
-
this.set = parsed;
|
|
124
|
-
}
|
|
125
|
-
test(version) {
|
|
126
|
-
const v = version instanceof SemVer ? version : parse(String(version));
|
|
127
|
-
if (!v) return false;
|
|
128
|
-
for (const conj of this.set) {
|
|
129
|
-
if (conj.every((c) => testComparator(c, v))) {
|
|
130
|
-
if (v.prerelease.length > 0) {
|
|
131
|
-
const allowed = conj.some((c) => c.semver !== null && c.semver.prerelease.length > 0 && c.semver.major === v.major && c.semver.minor === v.minor && c.semver.patch === v.patch);
|
|
132
|
-
if (!allowed) continue;
|
|
133
|
-
}
|
|
134
|
-
return true;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
return false;
|
|
138
|
-
}
|
|
139
|
-
format() {
|
|
140
|
-
return this.set.map((c) => c.map(formatComparator).join(" ")).join(" || ");
|
|
141
|
-
}
|
|
142
|
-
toString() {
|
|
143
|
-
return this.format();
|
|
144
|
-
}
|
|
145
|
-
};
|
|
146
|
-
function testComparator(c, v) {
|
|
147
|
-
if (c.semver === null) return true;
|
|
148
|
-
const cmp = v.compare(c.semver);
|
|
149
|
-
switch (c.operator) {
|
|
150
|
-
case "":
|
|
151
|
-
case "=": return cmp === 0;
|
|
152
|
-
case "<": return cmp < 0;
|
|
153
|
-
case "<=": return cmp <= 0;
|
|
154
|
-
case ">": return cmp > 0;
|
|
155
|
-
case ">=": return cmp >= 0;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
function formatComparator(c) {
|
|
159
|
-
if (c.semver === null) return "*";
|
|
160
|
-
return `${c.operator}${c.semver.version}`;
|
|
161
|
-
}
|
|
162
|
-
function parseRangePart(part) {
|
|
163
|
-
const trimmed = part.trim();
|
|
164
|
-
if (trimmed === "" || trimmed === "*" || trimmed.toLowerCase() === "latest") {
|
|
165
|
-
return [{
|
|
166
|
-
operator: ">=",
|
|
167
|
-
semver: new SemVer("0.0.0")
|
|
168
|
-
}];
|
|
169
|
-
}
|
|
170
|
-
const hyphen = trimmed.match(/^\s*(\S+)\s+-\s+(\S+)\s*$/);
|
|
171
|
-
if (hyphen) return hyphenRange(hyphen[1], hyphen[2]);
|
|
172
|
-
const glued = trimmed.replace(/(<=|>=|<|>|=)\s+(?=\S)/g, "$1");
|
|
173
|
-
const tokens = glued.split(/\s+/);
|
|
174
|
-
const out = [];
|
|
175
|
-
for (const tok of tokens) out.push(...parseSimple(tok));
|
|
176
|
-
return out;
|
|
177
|
-
}
|
|
178
|
-
function parseSimple(tok) {
|
|
179
|
-
if (tok === "*" || tok === "" || tok.toLowerCase() === "latest") {
|
|
180
|
-
return [{
|
|
181
|
-
operator: ">=",
|
|
182
|
-
semver: new SemVer("0.0.0")
|
|
183
|
-
}];
|
|
184
|
-
}
|
|
185
|
-
if (tok.startsWith("^")) return caretRange(tok.slice(1));
|
|
186
|
-
if (tok.startsWith("~")) return tildeRange(tok.slice(1).replace(/^>/, ""));
|
|
187
|
-
const opMatch = tok.match(/^(<=|>=|<|>|=)\s*(.+)$/);
|
|
188
|
-
if (opMatch) {
|
|
189
|
-
const op = opMatch[1];
|
|
190
|
-
return primitiveRange(op, opMatch[2]);
|
|
191
|
-
}
|
|
192
|
-
return partialRange(tok);
|
|
193
|
-
}
|
|
194
|
-
function parsePartial(s) {
|
|
195
|
-
const trimmed = s.trim().replace(/^v/, "");
|
|
196
|
-
if (trimmed === "" || trimmed === "*") {
|
|
197
|
-
return {
|
|
198
|
-
major: null,
|
|
199
|
-
minor: null,
|
|
200
|
-
patch: null,
|
|
201
|
-
pre: "",
|
|
202
|
-
build: ""
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
let pre = "";
|
|
206
|
-
let build = "";
|
|
207
|
-
let core = trimmed;
|
|
208
|
-
const plus = core.indexOf("+");
|
|
209
|
-
if (plus >= 0) {
|
|
210
|
-
build = core.slice(plus + 1);
|
|
211
|
-
core = core.slice(0, plus);
|
|
212
|
-
}
|
|
213
|
-
const dash = core.indexOf("-");
|
|
214
|
-
if (dash >= 0) {
|
|
215
|
-
pre = core.slice(dash + 1);
|
|
216
|
-
core = core.slice(0, dash);
|
|
217
|
-
}
|
|
218
|
-
const parts = core.split(".");
|
|
219
|
-
const xr = (part) => {
|
|
220
|
-
if (part === undefined || part === "") return null;
|
|
221
|
-
if (part === "x" || part === "X" || part === "*") return null;
|
|
222
|
-
if (!/^\d+$/.test(part)) {
|
|
223
|
-
throw new TypeError(`Invalid partial version: ${s}`);
|
|
224
|
-
}
|
|
225
|
-
return Number(part);
|
|
226
|
-
};
|
|
227
|
-
return {
|
|
228
|
-
major: xr(parts[0]),
|
|
229
|
-
minor: xr(parts[1]),
|
|
230
|
-
patch: xr(parts[2]),
|
|
231
|
-
pre,
|
|
232
|
-
build
|
|
233
|
-
};
|
|
234
|
-
}
|
|
235
|
-
function partialToVersion(p) {
|
|
236
|
-
return `${p.major ?? 0}.${p.minor ?? 0}.${p.patch ?? 0}${p.pre ? `-${p.pre}` : ""}${p.build ? `+${p.build}` : ""}`;
|
|
237
|
-
}
|
|
238
|
-
function partialRange(tok) {
|
|
239
|
-
const p = parsePartial(tok);
|
|
240
|
-
if (p.major === null) return [{
|
|
241
|
-
operator: ">=",
|
|
242
|
-
semver: new SemVer("0.0.0")
|
|
243
|
-
}];
|
|
244
|
-
if (p.minor === null) {
|
|
245
|
-
return [{
|
|
246
|
-
operator: ">=",
|
|
247
|
-
semver: new SemVer(`${p.major}.0.0`)
|
|
248
|
-
}, {
|
|
249
|
-
operator: "<",
|
|
250
|
-
semver: new SemVer(`${p.major + 1}.0.0`)
|
|
251
|
-
}];
|
|
252
|
-
}
|
|
253
|
-
if (p.patch === null) {
|
|
254
|
-
return [{
|
|
255
|
-
operator: ">=",
|
|
256
|
-
semver: new SemVer(`${p.major}.${p.minor}.0`)
|
|
257
|
-
}, {
|
|
258
|
-
operator: "<",
|
|
259
|
-
semver: new SemVer(`${p.major}.${p.minor + 1}.0`)
|
|
260
|
-
}];
|
|
261
|
-
}
|
|
262
|
-
return [{
|
|
263
|
-
operator: "=",
|
|
264
|
-
semver: new SemVer(partialToVersion(p))
|
|
265
|
-
}];
|
|
266
|
-
}
|
|
267
|
-
function caretRange(tok) {
|
|
268
|
-
const p = parsePartial(tok);
|
|
269
|
-
if (p.major === null) return [{
|
|
270
|
-
operator: ">=",
|
|
271
|
-
semver: new SemVer("0.0.0")
|
|
272
|
-
}];
|
|
273
|
-
const lower = `${p.major}.${p.minor ?? 0}.${p.patch ?? 0}${p.pre ? `-${p.pre}` : ""}`;
|
|
274
|
-
let upper;
|
|
275
|
-
if (p.major > 0 || p.minor === null) {
|
|
276
|
-
upper = `${p.major + 1}.0.0`;
|
|
277
|
-
} else if (p.minor > 0 || p.patch === null) {
|
|
278
|
-
upper = `0.${p.minor + 1}.0`;
|
|
279
|
-
} else {
|
|
280
|
-
upper = `0.0.${p.patch + 1}`;
|
|
281
|
-
}
|
|
282
|
-
return [{
|
|
283
|
-
operator: ">=",
|
|
284
|
-
semver: new SemVer(lower)
|
|
285
|
-
}, {
|
|
286
|
-
operator: "<",
|
|
287
|
-
semver: new SemVer(upper)
|
|
288
|
-
}];
|
|
289
|
-
}
|
|
290
|
-
function tildeRange(tok) {
|
|
291
|
-
const p = parsePartial(tok);
|
|
292
|
-
if (p.major === null) return [{
|
|
293
|
-
operator: ">=",
|
|
294
|
-
semver: new SemVer("0.0.0")
|
|
295
|
-
}];
|
|
296
|
-
const lower = `${p.major}.${p.minor ?? 0}.${p.patch ?? 0}${p.pre ? `-${p.pre}` : ""}`;
|
|
297
|
-
const upper = p.minor === null ? `${p.major + 1}.0.0` : `${p.major}.${p.minor + 1}.0`;
|
|
298
|
-
return [{
|
|
299
|
-
operator: ">=",
|
|
300
|
-
semver: new SemVer(lower)
|
|
301
|
-
}, {
|
|
302
|
-
operator: "<",
|
|
303
|
-
semver: new SemVer(upper)
|
|
304
|
-
}];
|
|
305
|
-
}
|
|
306
|
-
function primitiveRange(op, rhs) {
|
|
307
|
-
const p = parsePartial(rhs);
|
|
308
|
-
if (p.major === null) return [{
|
|
309
|
-
operator: ">=",
|
|
310
|
-
semver: new SemVer("0.0.0")
|
|
311
|
-
}];
|
|
312
|
-
if (op === "=" || op === "") return partialRange(rhs);
|
|
313
|
-
if (op === ">") {
|
|
314
|
-
if (p.minor === null) return [{
|
|
315
|
-
operator: ">=",
|
|
316
|
-
semver: new SemVer(`${p.major + 1}.0.0`)
|
|
317
|
-
}];
|
|
318
|
-
if (p.patch === null) return [{
|
|
319
|
-
operator: ">=",
|
|
320
|
-
semver: new SemVer(`${p.major}.${p.minor + 1}.0`)
|
|
321
|
-
}];
|
|
322
|
-
return [{
|
|
323
|
-
operator: ">",
|
|
324
|
-
semver: new SemVer(partialToVersion(p))
|
|
325
|
-
}];
|
|
326
|
-
}
|
|
327
|
-
if (op === "<") {
|
|
328
|
-
if (p.minor === null) return [{
|
|
329
|
-
operator: "<",
|
|
330
|
-
semver: new SemVer(`${p.major}.0.0`)
|
|
331
|
-
}];
|
|
332
|
-
if (p.patch === null) return [{
|
|
333
|
-
operator: "<",
|
|
334
|
-
semver: new SemVer(`${p.major}.${p.minor}.0`)
|
|
335
|
-
}];
|
|
336
|
-
return [{
|
|
337
|
-
operator: "<",
|
|
338
|
-
semver: new SemVer(partialToVersion(p))
|
|
339
|
-
}];
|
|
340
|
-
}
|
|
341
|
-
if (op === ">=") return [{
|
|
342
|
-
operator: ">=",
|
|
343
|
-
semver: new SemVer(partialToVersion(p))
|
|
344
|
-
}];
|
|
345
|
-
if (p.minor === null) return [{
|
|
346
|
-
operator: "<",
|
|
347
|
-
semver: new SemVer(`${p.major + 1}.0.0`)
|
|
348
|
-
}];
|
|
349
|
-
if (p.patch === null) return [{
|
|
350
|
-
operator: "<",
|
|
351
|
-
semver: new SemVer(`${p.major}.${p.minor + 1}.0`)
|
|
352
|
-
}];
|
|
353
|
-
return [{
|
|
354
|
-
operator: "<=",
|
|
355
|
-
semver: new SemVer(partialToVersion(p))
|
|
356
|
-
}];
|
|
357
|
-
}
|
|
358
|
-
function hyphenRange(left, right) {
|
|
359
|
-
const a = parsePartial(left);
|
|
360
|
-
const b = parsePartial(right);
|
|
361
|
-
const lower = a.major === null ? {
|
|
362
|
-
operator: ">=",
|
|
363
|
-
semver: new SemVer("0.0.0")
|
|
364
|
-
} : {
|
|
365
|
-
operator: ">=",
|
|
366
|
-
semver: new SemVer(`${a.major}.${a.minor ?? 0}.${a.patch ?? 0}${a.pre ? `-${a.pre}` : ""}`)
|
|
367
|
-
};
|
|
368
|
-
let upper;
|
|
369
|
-
if (b.major === null) {
|
|
370
|
-
upper = {
|
|
371
|
-
operator: ">=",
|
|
372
|
-
semver: new SemVer("0.0.0")
|
|
373
|
-
};
|
|
374
|
-
} else if (b.minor === null) {
|
|
375
|
-
upper = {
|
|
376
|
-
operator: "<",
|
|
377
|
-
semver: new SemVer(`${b.major + 1}.0.0`)
|
|
378
|
-
};
|
|
379
|
-
} else if (b.patch === null) {
|
|
380
|
-
upper = {
|
|
381
|
-
operator: "<",
|
|
382
|
-
semver: new SemVer(`${b.major}.${b.minor + 1}.0`)
|
|
383
|
-
};
|
|
384
|
-
} else {
|
|
385
|
-
upper = {
|
|
386
|
-
operator: "<=",
|
|
387
|
-
semver: new SemVer(`${b.major}.${b.minor}.${b.patch}${b.pre ? `-${b.pre}` : ""}`)
|
|
388
|
-
};
|
|
389
|
-
}
|
|
390
|
-
return [lower, upper];
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
//#endregion
|
|
394
|
-
export { Range, SemVer, compare, maxSatisfying, minSatisfying, parse, satisfies, valid, validRange };
|
|
1
|
+
const e=/^(0|[1-9]\d*)$/,t=/^(\d+)\.(\d+)\.(\d+)(?:-((?:[0-9A-Za-z-]+)(?:\.[0-9A-Za-z-]+)*))?(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?$/;function n(e){try{return new l(e)}catch{return null}}function r(e){let t=n(e);return t?t.version:null}function i(e,t){let n=e instanceof l?e:new l(e),r=t instanceof l?t:new l(t);return n.compare(r)}function a(e,t){let r=t instanceof u?t:new u(t),i=e instanceof l?e:n(String(e));return i?r.test(i):!1}function o(e,t){let r=t instanceof u?t:new u(t),i=null;for(let t of e){let e=n(t);!e||!r.test(e)||(i===null||e.compare(i)>0)&&(i=e)}return i?i.version:null}function s(e,t){let r=t instanceof u?t:new u(t),i=null;for(let t of e){let e=n(t);!e||!r.test(e)||(i===null||e.compare(i)<0)&&(i=e)}return i?i.version:null}function c(e){try{return new u(e).format()}catch{return null}}var l=class{major;minor;patch;prerelease;build;version;constructor(n){let r=String(n).trim().replace(/^v/,``),i=t.exec(r);if(!i)throw TypeError(`Invalid Version: ${n}`);this.major=Number(i[1]),this.minor=Number(i[2]),this.patch=Number(i[3]),this.prerelease=i[4]?i[4].split(`.`).map(t=>e.test(t)?Number(t):t):[],this.build=i[5]?i[5].split(`.`):[],this.version=`${this.major}.${this.minor}.${this.patch}`+(this.prerelease.length?`-${this.prerelease.join(`.`)}`:``)+(this.build.length?`+${this.build.join(`.`)}`:``)}compare(e){return this.major===e.major?this.minor===e.minor?this.patch===e.patch?this.comparePre(e):this.patch<e.patch?-1:1:this.minor<e.minor?-1:1:this.major<e.major?-1:1}comparePre(e){let t=this.prerelease,n=e.prerelease;if(t.length===0&&n.length===0)return 0;if(t.length===0)return 1;if(n.length===0)return-1;for(let e=0;;e++){let r=t[e],i=n[e];if(r===void 0&&i===void 0)return 0;if(i===void 0)return 1;if(r===void 0)return-1;if(r===i)continue;let a=typeof r==`number`,o=typeof i==`number`;return a&&!o?-1:!a&&o?1:r<i?-1:1}}toString(){return this.version}},u=class e{raw;set;constructor(t){if(t instanceof e){this.raw=t.raw,this.set=t.set;return}this.raw=String(t).trim();let n=this.raw.split(/\s*\|\|\s*/),r=[];for(let e of n){let t=p(e);if(t.length===0)throw TypeError(`Invalid range: ${this.raw}`);r.push(t)}if(r.length===0)throw TypeError(`Invalid range: ${this.raw}`);this.set=r}test(e){let t=e instanceof l?e:n(String(e));if(!t)return!1;for(let e of this.set)if(e.every(e=>d(e,t))){if(t.prerelease.length>0&&!e.some(e=>e.semver!==null&&e.semver.prerelease.length>0&&e.semver.major===t.major&&e.semver.minor===t.minor&&e.semver.patch===t.patch))continue;return!0}return!1}format(){return this.set.map(e=>e.map(f).join(` `)).join(` || `)}toString(){return this.format()}};function d(e,t){if(e.semver===null)return!0;let n=t.compare(e.semver);switch(e.operator){case``:case`=`:return n===0;case`<`:return n<0;case`<=`:return n<=0;case`>`:return n>0;case`>=`:return n>=0}}function f(e){return e.semver===null?`*`:`${e.operator}${e.semver.version}`}function p(e){let t=e.trim();if(t===``||t===`*`||t.toLowerCase()===`latest`)return[{operator:`>=`,semver:new l(`0.0.0`)}];let n=t.match(/^\s*(\S+)\s+-\s+(\S+)\s*$/);if(n)return x(n[1],n[2]);let r=t.replace(/(<=|>=|<|>|=)\s+(?=\S)/g,`$1`).split(/\s+/),i=[];for(let e of r)i.push(...m(e));return i}function m(e){if(e===`*`||e===``||e.toLowerCase()===`latest`)return[{operator:`>=`,semver:new l(`0.0.0`)}];if(e.startsWith(`^`))return v(e.slice(1));if(e.startsWith(`~`))return y(e.slice(1).replace(/^>/,``));let t=e.match(/^(<=|>=|<|>|=)\s*(.+)$/);if(t){let e=t[1];return b(e,t[2])}return _(e)}function h(e){let t=e.trim().replace(/^v/,``);if(t===``||t===`*`)return{major:null,minor:null,patch:null,pre:``,build:``};let n=``,r=``,i=t,a=i.indexOf(`+`);a>=0&&(r=i.slice(a+1),i=i.slice(0,a));let o=i.indexOf(`-`);o>=0&&(n=i.slice(o+1),i=i.slice(0,o));let s=i.split(`.`),c=t=>{if(t===void 0||t===``||t===`x`||t===`X`||t===`*`)return null;if(!/^\d+$/.test(t))throw TypeError(`Invalid partial version: ${e}`);return Number(t)};return{major:c(s[0]),minor:c(s[1]),patch:c(s[2]),pre:n,build:r}}function g(e){return`${e.major??0}.${e.minor??0}.${e.patch??0}${e.pre?`-${e.pre}`:``}${e.build?`+${e.build}`:``}`}function _(e){let t=h(e);return t.major===null?[{operator:`>=`,semver:new l(`0.0.0`)}]:t.minor===null?[{operator:`>=`,semver:new l(`${t.major}.0.0`)},{operator:`<`,semver:new l(`${t.major+1}.0.0`)}]:t.patch===null?[{operator:`>=`,semver:new l(`${t.major}.${t.minor}.0`)},{operator:`<`,semver:new l(`${t.major}.${t.minor+1}.0`)}]:[{operator:`=`,semver:new l(g(t))}]}function v(e){let t=h(e);if(t.major===null)return[{operator:`>=`,semver:new l(`0.0.0`)}];let n=`${t.major}.${t.minor??0}.${t.patch??0}${t.pre?`-${t.pre}`:``}`,r;return r=t.major>0||t.minor===null?`${t.major+1}.0.0`:t.minor>0||t.patch===null?`0.${t.minor+1}.0`:`0.0.${t.patch+1}`,[{operator:`>=`,semver:new l(n)},{operator:`<`,semver:new l(r)}]}function y(e){let t=h(e);if(t.major===null)return[{operator:`>=`,semver:new l(`0.0.0`)}];let n=`${t.major}.${t.minor??0}.${t.patch??0}${t.pre?`-${t.pre}`:``}`,r=t.minor===null?`${t.major+1}.0.0`:`${t.major}.${t.minor+1}.0`;return[{operator:`>=`,semver:new l(n)},{operator:`<`,semver:new l(r)}]}function b(e,t){let n=h(t);return n.major===null?[{operator:`>=`,semver:new l(`0.0.0`)}]:e===`=`||e===``?_(t):e===`>`?n.minor===null?[{operator:`>=`,semver:new l(`${n.major+1}.0.0`)}]:n.patch===null?[{operator:`>=`,semver:new l(`${n.major}.${n.minor+1}.0`)}]:[{operator:`>`,semver:new l(g(n))}]:e===`<`?n.minor===null?[{operator:`<`,semver:new l(`${n.major}.0.0`)}]:n.patch===null?[{operator:`<`,semver:new l(`${n.major}.${n.minor}.0`)}]:[{operator:`<`,semver:new l(g(n))}]:e===`>=`?[{operator:`>=`,semver:new l(g(n))}]:n.minor===null?[{operator:`<`,semver:new l(`${n.major+1}.0.0`)}]:n.patch===null?[{operator:`<`,semver:new l(`${n.major}.${n.minor+1}.0`)}]:[{operator:`<=`,semver:new l(g(n))}]}function x(e,t){let n=h(e),r=h(t),i=n.major===null?{operator:`>=`,semver:new l(`0.0.0`)}:{operator:`>=`,semver:new l(`${n.major}.${n.minor??0}.${n.patch??0}${n.pre?`-${n.pre}`:``}`)},a;return a=r.major===null?{operator:`>=`,semver:new l(`0.0.0`)}:r.minor===null?{operator:`<`,semver:new l(`${r.major+1}.0.0`)}:r.patch===null?{operator:`<`,semver:new l(`${r.major}.${r.minor+1}.0`)}:{operator:`<=`,semver:new l(`${r.major}.${r.minor}.${r.patch}${r.pre?`-${r.pre}`:``}`)},[i,a]}export{u as Range,l as SemVer,i as compare,o as maxSatisfying,s as minSatisfying,n as parse,a as satisfies,r as valid,c as validRange};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/semver",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.17",
|
|
4
4
|
"description": "Subset of node-semver for the gjsify install backend — cross-platform Node + GJS",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "lib/esm/index.js",
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
],
|
|
34
34
|
"license": "MIT",
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@gjsify/cli": "^0.3.
|
|
37
|
-
"@gjsify/unit": "^0.3.
|
|
36
|
+
"@gjsify/cli": "^0.3.17",
|
|
37
|
+
"@gjsify/unit": "^0.3.17",
|
|
38
38
|
"typescript": "^6.0.3"
|
|
39
39
|
}
|
|
40
40
|
}
|