Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

@vltpkg/semver

Package Overview
Dependencies
Maintainers
6
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vltpkg/semver - npm Package Compare versions

Comparing version
1.0.0-rc.10
to
1.0.0-rc.11
+76
dist/comparator.d.ts
import { Version } from './version.ts';
/** all comparators are expressed in terms of these operators */
export type SimpleOperator = '' | '<' | '<=' | '>' | '>=';
/** operators that are expanded to simpler forms */
export type ComplexOperator = '^' | '~' | '~>';
/** comparator expressed as a [operator,version] tuple */
export type OVTuple = [SimpleOperator, Version];
/**
* The result of parsing a version value that might be either a full
* version like `1.2.3` or an X-Range like `1.2.x`
*/
export type ParsedXRange = ParsedXMajor | ParsedXMinor | ParsedXPatch | ParsedXVersion;
/**
* a {@link ParsedXRange} that is just a `*`
*/
export type ParsedXMajor = [];
/**
* a {@link ParsedXRange} that is just a major version
*/
export type ParsedXMinor = [number];
/**
* a {@link ParsedXRange} that is just a major and minor version
*/
export type ParsedXPatch = [number, number];
/**
* a {@link ParsedXRange} that is a full version
*/
export type ParsedXVersion = [
M: number,
m: number,
p: number,
pr?: string | undefined,
b?: string | undefined
];
/**
* Class used to parse the `||` separated portions
* of a range, and evaluate versions against it.
*
* This does most of the heavy lifting of range testing, and provides
* little affordance for improperly formatted strings. It should be
* considered an internal class, and usually not accessed directly.
*/
export declare class Comparator {
#private;
/**
* does this range include prereleases, even when they do not
* match the tuple in the comparator?
*/
includePrerelease: boolean;
/** raw string used to create this comparator */
raw: string;
/** tokens extracted from the raw string input */
tokens: string[];
/**
* Either the `any` comparator, the `none` comparator, or an operator
* and a {@link ParsedXRange}
*/
tuples: (Comparator | OVTuple)[];
/** true if this comparator can not match anything */
isNone: boolean;
/**
* true if this comparator is a `'*'` type of range.
*
* Note that it still will not match versions with a prerelease value,
* unless the tuple in the version matches the tuple provided to the
* comparator, and the comparator version also has a prerelease value,
* unless `includePrerelease` is set.
*/
isAny: boolean;
/** the canonical strict simplified parsed form of this constructor */
toString(): string;
constructor(comp: string, includePrerelease?: boolean);
/** return true if the version is a match for this comparator */
test(v: Version): boolean;
}
//# sourceMappingURL=comparator.d.ts.map
{"version":3,"file":"comparator.d.ts","sourceRoot":"","sources":["../src/comparator.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtC,gEAAgE;AAChE,MAAM,MAAM,cAAc,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,GAAG,GAAG,GAAG,IAAI,CAAA;AACzD,mDAAmD;AACnD,MAAM,MAAM,eAAe,GAAG,GAAG,GAAG,GAAG,GAAG,IAAI,CAAA;AAe9C,yDAAyD;AACzD,MAAM,MAAM,OAAO,GAAG,CAAC,cAAc,EAAE,OAAO,CAAC,CAAA;AA+C/C;;;GAGG;AACH,MAAM,MAAM,YAAY,GACpB,YAAY,GACZ,YAAY,GACZ,YAAY,GACZ,cAAc,CAAA;AAClB;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,EAAE,CAAA;AAC7B;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,MAAM,CAAC,CAAA;AACnC;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;AAC3C;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,CAAC,EAAE,MAAM;IACT,CAAC,EAAE,MAAM;IACT,CAAC,EAAE,MAAM;IACT,EAAE,CAAC,EAAE,MAAM,GAAG,SAAS;IACvB,CAAC,CAAC,EAAE,MAAM,GAAG,SAAS;CACvB,CAAA;AAYD;;;;;;;GAOG;AACH,qBAAa,UAAU;;IACrB;;;OAGG;IACH,iBAAiB,EAAE,OAAO,CAAA;IAC1B,gDAAgD;IAChD,GAAG,EAAE,MAAM,CAAA;IACX,iDAAiD;IACjD,MAAM,EAAE,MAAM,EAAE,CAAA;IAChB;;;OAGG;IACH,MAAM,EAAE,CAAC,UAAU,GAAG,OAAO,CAAC,EAAE,CAAK;IACrC,qDAAqD;IACrD,MAAM,UAAQ;IACd;;;;;;;OAOG;IACH,KAAK,UAAQ;IAEb,sEAAsE;IACtE,QAAQ;gBASI,IAAI,EAAE,MAAM,EAAE,iBAAiB,UAAQ;IAwdnD,gEAAgE;IAChE,IAAI,CAAC,CAAC,EAAE,OAAO;CAqChB"}
// TODO: it might be faster to not have Version objects in the
// comparator tuples, and instead just keep the parsed number arrays?
import { syntaxError } from '@vltpkg/error-cause';
import { fastSplit } from '@vltpkg/fast-split';
import { Version } from "./version.js";
const isOperator = (o) => !!o &&
(o === '>' ||
o === '<' ||
o === '>=' ||
o === '<=' ||
o === '' ||
o === '~' ||
o === '^' ||
o === '~>');
const preJunk = new Set('=v \t');
const invalidComp = (c, message) => syntaxError(`invalid comparator: '${c}' ${message}`, { found: c }, Comparator);
const assertNumber = (value, c, field) => {
const n = Number(value);
if (n !== n) {
throw invalidComp(c, `${field} must be numeric or 'x', got: '${value}'`);
}
return n;
};
const assertVersion = (v, comp) => {
if (!v) {
throw invalidComp(comp, 'no value provided for operator');
}
};
const assertMissing = (value, c, field) => {
if (value && !isX(value)) {
throw invalidComp(c, `cannot omit '${field}' and include subsequent fields`);
}
};
const MAJOR = 0;
const MINOR = 1;
const PATCH = 2;
const isX = (c) => !c || c === 'X' || c === 'x' || c === '*';
const isFullVersion = (parsed) => undefined !== parsed[PATCH];
const isXPatch = (parsed) => undefined !== parsed[MINOR] && undefined === parsed[PATCH];
const isXMinor = (parsed) => undefined !== parsed[MAJOR] && undefined === parsed[MINOR];
const isXMajor = (parsed) => undefined === parsed[MAJOR];
/**
* Class used to parse the `||` separated portions
* of a range, and evaluate versions against it.
*
* This does most of the heavy lifting of range testing, and provides
* little affordance for improperly formatted strings. It should be
* considered an internal class, and usually not accessed directly.
*/
export class Comparator {
/**
* does this range include prereleases, even when they do not
* match the tuple in the comparator?
*/
includePrerelease;
/** raw string used to create this comparator */
raw;
/** tokens extracted from the raw string input */
tokens;
/**
* Either the `any` comparator, the `none` comparator, or an operator
* and a {@link ParsedXRange}
*/
tuples = [];
/** true if this comparator can not match anything */
isNone = false;
/**
* true if this comparator is a `'*'` type of range.
*
* Note that it still will not match versions with a prerelease value,
* unless the tuple in the version matches the tuple provided to the
* comparator, and the comparator version also has a prerelease value,
* unless `includePrerelease` is set.
*/
isAny = false;
/** the canonical strict simplified parsed form of this constructor */
toString() {
return (this.isNone ? '<0.0.0-0'
: this.isAny ? '*'
: /* c8 ignore next */
this.tuples.map(c => (isAny(c) ? '*' : c.join(''))).join(' '));
}
constructor(comp, includePrerelease = false) {
this.includePrerelease = includePrerelease;
comp = comp.trim();
this.raw = comp;
let hyphen = false;
const rawComps = fastSplit(comp, ' ', -1, (part, parts, i) => {
if (part === '-') {
if (hyphen) {
throw invalidComp(comp, 'multiple hyphen ranges not allowed');
}
if (parts.length !== 1 || i === -1) {
throw invalidComp(comp, 'hyphen must be between two versions');
}
hyphen = true;
}
else if (hyphen && parts.length !== 2) {
throw invalidComp(comp, 'hyphen range must be alone');
}
});
// remove excess spaces, `> 1 2` => `>1 2`
const comps = [];
let followingOperator = false;
let l = 0;
for (const c of rawComps) {
if (c === '')
continue;
if (!followingOperator) {
followingOperator = isOperator(c);
comps.push(c);
l++;
continue;
}
// we know this is not undefined since followingOperator guards that
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
comps[l - 1] += c;
followingOperator = false;
}
// TS mistakenly thinks hyphen is always false here
if (hyphen) {
const [min, _, max] = comps;
/* c8 ignore start - defense in depth for TS, already guaranteed */
if (!min || !max) {
throw invalidComp(comp, 'hyphen must be between two versions');
}
/* c8 ignore stop */
this.#parseHyphenRange(min, max);
}
else if (!comps.length ||
(comps.length === 1 && isX(comps[0]))) {
this.tuples.push(this.#getComparatorAny());
}
else {
for (const c of comps) {
this.#parse(c);
if (this.isNone)
break;
}
}
this.tokens = comps;
this.isAny = true;
for (const c of this.tuples) {
if (Array.isArray(c) || !c.isAny) {
this.isAny = false;
break;
}
}
}
// inclusive min
#xInclusiveMin(raw) {
const z = this.includePrerelease ? '0' : undefined;
const [M, m = 0, p = 0, pr = z, build] = this.#parseX(raw);
return M === undefined ?
this.#getComparatorAny()
: ['>=', new Version(raw, M, m, p, pr, build)];
}
// exclusive min
#xExclusiveMin(raw) {
const parsed = this.#parseX(raw);
if (isFullVersion(parsed)) {
return ['>', new Version(raw, ...parsed)];
}
const z = this.includePrerelease ? '0' : undefined;
if (isXPatch(parsed)) {
// >1.2 => >=1.3.0
return [
'>=',
new Version(raw, parsed[MAJOR], parsed[MINOR] + 1, 0, z, undefined),
];
}
if (isXMinor(parsed)) {
// >1 => >=2.0.0
return [
'>=',
new Version(raw, parsed[MAJOR] + 1, 0, 0, z, undefined),
];
}
this.isNone = true;
this.tuples.length = 0;
return comparatorNone;
}
#xInclusiveMax(raw) {
const parsed = this.#parseX(raw);
return (isFullVersion(parsed) ? ['<=', new Version(raw, ...parsed)]
: isXPatch(parsed) ?
[
'<',
new Version(raw, parsed[MAJOR], parsed[MINOR] + 1, 0, '0', undefined),
]
: isXMinor(parsed) ?
[
'<',
new Version(raw, parsed[MAJOR] + 1, 0, 0, '0', undefined),
]
: this.#getComparatorAny());
}
#xExclusiveMax(raw) {
const z = this.includePrerelease ? '0' : undefined;
const [M = 0, m = 0, p = 0, pr = z, build] = this.#parseX(raw);
if (M === 0 && m === 0 && p === 0 && pr === '0') {
this.isNone = true;
this.tuples.length = 0;
return comparatorNone;
}
return ['<', new Version(raw, M, m, p, pr, build)];
}
#validXM(raw, m, p) {
assertMissing(m, raw, 'major');
assertMissing(p, raw, 'major');
if (m === '' || p === '') {
throw invalidComp(raw, `(Did you mean '*'?)`);
}
return [];
}
#validXm(raw, M, m, p) {
assertMissing(p, raw, 'major');
if (m === '' || p === '') {
throw invalidComp(raw, `(Did you mean '${M}'?)`);
}
return [assertNumber(M, raw, 'major')];
}
#validXp(raw, M, m, p) {
if (p === '') {
throw invalidComp(raw, `(Did you mean '${M}.${m}'?)`);
}
return [
assertNumber(M, raw, 'major'),
assertNumber(m, raw, 'minor'),
];
}
#validTuple(raw, M, m, p) {
return [
assertNumber(M, raw, 'major'),
assertNumber(m, raw, 'minor'),
assertNumber(p, raw, 'patch'),
];
}
#validXbuild(raw, M, m, p, pl) {
// build, no prerelease
const patch = p.substring(0, pl);
const build = p.substring(pl + 1);
if (!patch) {
throw invalidComp(raw, 'cannot specify build without patch');
}
if (!build) {
throw invalidComp(raw, `encountered '+', but no build value`);
}
return [
assertNumber(M, raw, 'major'),
assertNumber(m, raw, 'minor'),
assertNumber(patch, raw, 'patch'),
undefined,
build,
];
}
#validXpr(raw, M, m, p, hy) {
{
// prerelease, no build
const patch = p.substring(0, hy);
const pr = p.substring(hy + 1);
if (!patch) {
throw invalidComp(raw, 'cannot specify prerelease without patch');
}
if (!pr) {
throw invalidComp(raw, `encountered '-', but no prerelease value`);
}
return [
assertNumber(M, raw, 'major'),
assertNumber(m, raw, 'minor'),
assertNumber(patch, raw, 'patch'),
pr,
undefined,
];
}
}
#validXprbuild(raw, M, m, p, hy, pl) {
// both prerelease and build
const patch = p.substring(0, hy);
const pr = p.substring(hy + 1, pl);
const build = p.substring(pl + 1);
if (!patch) {
throw invalidComp(raw, 'cannot specify prerelease without patch');
}
if (!pr) {
throw invalidComp(raw, `encountered '-', but no prerelease value`);
}
if (!build) {
throw invalidComp(raw, `encountered '+', but no build value`);
}
return [
assertNumber(M, raw, 'major'),
assertNumber(m, raw, 'minor'),
assertNumber(patch, raw, 'patch'),
pr,
build,
];
}
// pull the relevant values out of an X-range or version
// return the fields for creating a Version object.
// only call once operator is stripped off
#parseX(raw) {
let [M, m, p] = fastSplit(raw, '.', 3);
let prune = 0;
while (M && preJunk.has(M.charAt(prune)))
prune++;
if (M !== undefined && prune !== 0)
M = M.substring(prune);
// the `|| !M` is so TS knows we've handled undefined
if (!M || isX(M))
return this.#validXM(raw, m, p);
if (!m || isX(m))
return this.#validXm(raw, M, m, p);
if (!p || isX(p))
return this.#validXp(raw, M, m, p);
const hy = p.indexOf('-');
const pl = p.indexOf('+');
if (pl === -1 && hy === -1)
return this.#validTuple(raw, M, m, p);
if (pl === -1)
return this.#validXpr(raw, M, m, p, hy);
if (hy === -1)
return this.#validXbuild(raw, M, m, p, pl);
return this.#validXprbuild(raw, M, m, p, hy, pl);
}
#parseHyphenRange(min, max) {
const minv = this.#xInclusiveMin(min);
const maxv = this.#xInclusiveMax(max);
const minAny = isAny(minv);
const maxAny = isAny(maxv);
if (minAny && maxAny)
this.tuples.push(this.#getComparatorAny());
else if (minAny)
this.tuples.push(maxv);
else if (maxAny)
this.tuples.push(minv);
else
this.tuples.push(minv, maxv);
}
#parse(comp) {
const first = comp.charAt(0);
const first2 = comp.substring(0, 2);
const v1 = comp.substring(1);
const v2 = comp.substring(2);
switch (first2) {
case '~>':
assertVersion(v2, comp);
return this.#parseTilde(v2);
case '>=':
assertVersion(v2, comp);
return this.tuples.push(this.#xInclusiveMin(v2));
case '<=':
assertVersion(v2, comp);
return this.tuples.push(this.#xInclusiveMax(v2));
}
switch (first) {
case '~':
assertVersion(v1, comp);
return this.#parseTilde(v1);
case '^':
assertVersion(v1, comp);
return this.#parseCaret(v1);
case '>':
assertVersion(v1, comp);
return this.tuples.push(this.#xExclusiveMin(v1));
case '<':
assertVersion(v1, comp);
return this.tuples.push(this.#xExclusiveMax(v1));
}
return this.#parseEq(comp);
}
#parseTilde(comp) {
const parsed = this.#parseX(comp);
if (isXMajor(parsed)) {
this.tuples.push(this.#getComparatorAny());
return;
}
const z = this.includePrerelease ? '0' : undefined;
if (isXMinor(parsed)) {
const [M] = parsed;
this.tuples.push(['>=', new Version(comp, M, 0, 0, z, undefined)], ['<', new Version(comp, M + 1, 0, 0, '0', undefined)]);
return;
}
if (isXPatch(parsed)) {
const [M, m] = parsed;
const z = this.includePrerelease ? '0' : undefined;
this.tuples.push(['>=', new Version(comp, M, m, 0, z, undefined)], ['<', new Version(comp, M, m + 1, 0, '0', undefined)]);
return;
}
const [M, m, p, pr = z, build] = parsed;
this.tuples.push(['>=', new Version(comp, M, m, p, pr, build)], ['<', new Version(comp, M, m + 1, 0, '0', build)]);
}
#parseCaret(comp) {
const min = this.#xInclusiveMin(comp);
if (isAny(min)) {
this.tuples.push(min);
return;
}
const minv = min[1];
if (minv.major !== 0) {
this.tuples.push(min, [
'<',
new Version(comp, minv.major + 1, 0, 0, '0', undefined),
]);
}
else if (minv.minor !== 0) {
this.tuples.push(min, [
'<',
new Version(comp, minv.major, minv.minor + 1, 0, '0', undefined),
]);
}
else if (!minv.prerelease?.length) {
this.tuples.push(['', minv]);
}
else {
this.tuples.push(min, [
'<',
new Version(comp, minv.major, minv.minor, minv.patch + 1, '0', undefined),
]);
}
}
#parseEq(comp) {
const parsed = this.#parseX(comp);
const z = this.includePrerelease ? '0' : undefined;
if (isFullVersion(parsed)) {
this.tuples.push(['', new Version(comp, ...parsed)]);
}
else if (isXMajor(parsed)) {
this.tuples.push(this.#getComparatorAny());
}
else if (isXMinor(parsed)) {
this.tuples.push([
'>=',
new Version(comp, parsed[MAJOR], 0, 0, z, undefined),
]);
this.tuples.push([
'<',
new Version(comp, parsed[MAJOR] + 1, 0, 0, '0', undefined),
]);
}
else if (isXPatch(parsed)) {
this.tuples.push([
'>=',
new Version(comp, parsed[MAJOR], parsed[MINOR], 0, z, undefined),
], [
'<',
new Version(comp, parsed[MAJOR], parsed[MINOR] + 1, 0, '0', undefined),
]);
}
}
/** return true if the version is a match for this comparator */
test(v) {
if (this.isNone)
return false;
const ip = this.includePrerelease;
const hasPR = !!v.prerelease?.length;
let prOK = ip || !hasPR;
for (const c of this.tuples) {
if (isAny(c)) {
continue;
}
const [op, cv] = c;
prOK ||= !!cv.prerelease?.length && v.tupleEquals(cv);
switch (op) {
case '':
if (!v.equals(cv))
return false;
continue;
case '>':
if (!v.greaterThan(cv))
return false;
continue;
case '>=':
if (!v.greaterThanEqual(cv))
return false;
continue;
case '<':
if (!v.lessThan(cv))
return false;
continue;
case '<=':
if (!v.lessThanEqual(cv))
return false;
continue;
}
}
// they all passed, so it can only fail for having a prerelease
// if we allow prereleases, or saw a matching tuple, that's ok.
return prOK;
}
#getComparatorAny() {
return this.includePrerelease ? comparatorAnyPR : comparatorAny;
}
}
const isAny = (c) => c === comparatorAny || c === comparatorAnyPR;
const comparatorAny = {
isAny: true,
toString: () => '*',
includePrerelease: false,
test: (v) => !v.prerelease?.length,
};
const comparatorAnyPR = {
isAny: true,
toString: () => '*',
includePrerelease: true,
test: (_) => true,
};
const comparatorNone = {
isNone: true,
toString: () => '<0.0.0-0',
includePrerelease: false,
test: (_) => false,
};
//# sourceMappingURL=comparator.js.map
{"version":3,"file":"comparator.js","sourceRoot":"","sources":["../src/comparator.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,qEAAqE;AACrE,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAOtC,MAAM,UAAU,GAAG,CACjB,CAAU,EAC6B,EAAE,CACzC,CAAC,CAAC,CAAC;IACH,CAAC,CAAC,KAAK,GAAG;QACR,CAAC,KAAK,GAAG;QACT,CAAC,KAAK,IAAI;QACV,CAAC,KAAK,IAAI;QACV,CAAC,KAAK,EAAE;QACR,CAAC,KAAK,GAAG;QACT,CAAC,KAAK,GAAG;QACT,CAAC,KAAK,IAAI,CAAC,CAAA;AAKf,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAA;AAEhC,MAAM,WAAW,GAAG,CAAC,CAAS,EAAE,OAAe,EAAe,EAAE,CAC9D,WAAW,CACT,wBAAwB,CAAC,KAAK,OAAO,EAAE,EACvC,EAAE,KAAK,EAAE,CAAC,EAAE,EACZ,UAAU,CACX,CAAA;AAE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AAG,EAAE,CAAC,UAAU;IAC1B,iBAAiB,EAAE,KAAK;IACxB,IAAI,EAAE,CAAC,CAAU,EAAE,EAAE,CAAC,KAAK;CACH,CAAA","sourcesContent":["// TODO: it might be faster to not have Version objects in the\n// comparator tuples, and instead just keep the parsed number arrays?\nimport { syntaxError } from '@vltpkg/error-cause'\nimport { fastSplit } from '@vltpkg/fast-split'\nimport { Version } from './version.ts'\n\n/** all comparators are expressed in terms of these operators */\nexport type SimpleOperator = '' | '<' | '<=' | '>' | '>='\n/** operators that are expanded to simpler forms */\nexport type ComplexOperator = '^' | '~' | '~>'\n\nconst isOperator = (\n o?: string,\n): o is ComplexOperator | SimpleOperator =>\n !!o &&\n (o === '>' ||\n o === '<' ||\n o === '>=' ||\n o === '<=' ||\n o === '' ||\n o === '~' ||\n o === '^' ||\n o === '~>')\n\n/** comparator expressed as a [operator,version] tuple */\nexport type OVTuple = [SimpleOperator, Version]\n\nconst preJunk = new Set('=v \\t')\n\nconst invalidComp = (c: string, message: string): SyntaxError =>\n syntaxError(\n `invalid comparator: '${c}' ${message}`,\n { found: c },\n Comparator,\n )\n\nconst assertNumber = (value: string, c: string, field: string) => {\n const n = Number(value)\n if (n !== n) {\n throw invalidComp(\n c,\n `${field} must be numeric or 'x', got: '${value}'`,\n )\n }\n return n\n}\n\nconst assertVersion = (v: string, comp: string) => {\n if (!v) {\n throw invalidComp(comp, 'no value provided for operator')\n }\n}\n\nconst assertMissing = (\n value: string | undefined,\n c: string,\n field: string,\n) => {\n if (value && !isX(value)) {\n throw invalidComp(\n c,\n `cannot omit '${field}' and include subsequent fields`,\n )\n }\n}\n\nconst MAJOR = 0\nconst MINOR = 1\nconst PATCH = 2\n\nconst isX = (c?: string) => !c || c === 'X' || c === 'x' || c === '*'\n\n/**\n * The result of parsing a version value that might be either a full\n * version like `1.2.3` or an X-Range like `1.2.x`\n */\nexport type ParsedXRange =\n | ParsedXMajor\n | ParsedXMinor\n | ParsedXPatch\n | ParsedXVersion\n/**\n * a {@link ParsedXRange} that is just a `*`\n */\nexport type ParsedXMajor = []\n/**\n * a {@link ParsedXRange} that is just a major version\n */\nexport type ParsedXMinor = [number]\n/**\n * a {@link ParsedXRange} that is just a major and minor version\n */\nexport type ParsedXPatch = [number, number]\n/**\n * a {@link ParsedXRange} that is a full version\n */\nexport type ParsedXVersion = [\n M: number,\n m: number,\n p: number,\n pr?: string | undefined,\n b?: string | undefined,\n]\n\nconst isFullVersion = (\n parsed: ParsedXRange,\n): parsed is ParsedXVersion => undefined !== parsed[PATCH]\nconst isXPatch = (parsed: ParsedXRange): parsed is ParsedXPatch =>\n undefined !== parsed[MINOR] && undefined === parsed[PATCH]\nconst isXMinor = (parsed: ParsedXRange): parsed is ParsedXMinor =>\n undefined !== parsed[MAJOR] && undefined === parsed[MINOR]\nconst isXMajor = (parsed: ParsedXRange): parsed is ParsedXMajor =>\n undefined === parsed[MAJOR]\n\n/**\n * Class used to parse the `||` separated portions\n * of a range, and evaluate versions against it.\n *\n * This does most of the heavy lifting of range testing, and provides\n * little affordance for improperly formatted strings. It should be\n * considered an internal class, and usually not accessed directly.\n */\nexport class Comparator {\n /**\n * does this range include prereleases, even when they do not\n * match the tuple in the comparator?\n */\n includePrerelease: boolean\n /** raw string used to create this comparator */\n raw: string\n /** tokens extracted from the raw string input */\n tokens: string[]\n /**\n * Either the `any` comparator, the `none` comparator, or an operator\n * and a {@link ParsedXRange}\n */\n tuples: (Comparator | OVTuple)[] = []\n /** true if this comparator can not match anything */\n isNone = false\n /**\n * true if this comparator is a `'*'` type of range.\n *\n * Note that it still will not match versions with a prerelease value,\n * unless the tuple in the version matches the tuple provided to the\n * comparator, and the comparator version also has a prerelease value,\n * unless `includePrerelease` is set.\n */\n isAny = false\n\n /** the canonical strict simplified parsed form of this constructor */\n toString() {\n return (\n this.isNone ? '<0.0.0-0'\n : this.isAny ? '*'\n : /* c8 ignore next */\n this.tuples.map(c => (isAny(c) ? '*' : c.join(''))).join(' ')\n )\n }\n\n constructor(comp: string, includePrerelease = false) {\n this.includePrerelease = includePrerelease\n comp = comp.trim()\n this.raw = comp\n let hyphen = false as boolean\n const rawComps = fastSplit(comp, ' ', -1, (part, parts, i) => {\n if (part === '-') {\n if (hyphen) {\n throw invalidComp(\n comp,\n 'multiple hyphen ranges not allowed',\n )\n }\n if (parts.length !== 1 || i === -1) {\n throw invalidComp(\n comp,\n 'hyphen must be between two versions',\n )\n }\n hyphen = true\n } else if (hyphen && parts.length !== 2) {\n throw invalidComp(comp, 'hyphen range must be alone')\n }\n })\n\n // remove excess spaces, `> 1 2` => `>1 2`\n const comps: string[] = []\n let followingOperator = false\n\n let l = 0\n for (const c of rawComps) {\n if (c === '') continue\n if (!followingOperator) {\n followingOperator = isOperator(c)\n comps.push(c)\n l++\n continue\n }\n // we know this is not undefined since followingOperator guards that\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n comps[l - 1]! += c\n followingOperator = false\n }\n\n // TS mistakenly thinks hyphen is always false here\n if (hyphen) {\n const [min, _, max] = comps\n /* c8 ignore start - defense in depth for TS, already guaranteed */\n if (!min || !max) {\n throw invalidComp(comp, 'hyphen must be between two versions')\n }\n /* c8 ignore stop */\n this.#parseHyphenRange(min, max)\n } else if (\n !comps.length ||\n (comps.length === 1 && isX(comps[0]))\n ) {\n this.tuples.push(this.#getComparatorAny())\n } else {\n for (const c of comps) {\n this.#parse(c)\n if (this.isNone) break\n }\n }\n this.tokens = comps\n this.isAny = true\n for (const c of this.tuples) {\n if (Array.isArray(c) || !c.isAny) {\n this.isAny = false\n break\n }\n }\n }\n\n // inclusive min\n #xInclusiveMin(raw: string): Comparator | OVTuple {\n const z = this.includePrerelease ? '0' : undefined\n const [M, m = 0, p = 0, pr = z, build] = this.#parseX(raw)\n return M === undefined ?\n this.#getComparatorAny()\n : ['>=', new Version(raw, M, m, p, pr, build)]\n }\n\n // exclusive min\n #xExclusiveMin(raw: string): Comparator | OVTuple {\n const parsed = this.#parseX(raw)\n if (isFullVersion(parsed)) {\n return ['>', new Version(raw, ...parsed)]\n }\n const z = this.includePrerelease ? '0' : undefined\n if (isXPatch(parsed)) {\n // >1.2 => >=1.3.0\n return [\n '>=',\n new Version(\n raw,\n parsed[MAJOR],\n parsed[MINOR] + 1,\n 0,\n z,\n undefined,\n ),\n ]\n }\n if (isXMinor(parsed)) {\n // >1 => >=2.0.0\n return [\n '>=',\n new Version(raw, parsed[MAJOR] + 1, 0, 0, z, undefined),\n ]\n }\n this.isNone = true\n this.tuples.length = 0\n return comparatorNone\n }\n\n #xInclusiveMax(raw: string): Comparator | OVTuple {\n const parsed = this.#parseX(raw)\n return (\n isFullVersion(parsed) ? ['<=', new Version(raw, ...parsed)]\n : isXPatch(parsed) ?\n [\n '<',\n new Version(\n raw,\n parsed[MAJOR],\n parsed[MINOR] + 1,\n 0,\n '0',\n undefined,\n ),\n ]\n : isXMinor(parsed) ?\n [\n '<',\n new Version(raw, parsed[MAJOR] + 1, 0, 0, '0', undefined),\n ]\n : this.#getComparatorAny()\n )\n }\n\n #xExclusiveMax(raw: string): Comparator | OVTuple {\n const z = this.includePrerelease ? '0' : undefined\n const [M = 0, m = 0, p = 0, pr = z, build] = this.#parseX(raw)\n if (M === 0 && m === 0 && p === 0 && pr === '0') {\n this.isNone = true\n this.tuples.length = 0\n return comparatorNone\n }\n return ['<', new Version(raw, M, m, p, pr, build)]\n }\n\n #validXM(raw: string, m?: string, p?: string): ParsedXMajor {\n assertMissing(m, raw, 'major')\n assertMissing(p, raw, 'major')\n if (m === '' || p === '') {\n throw invalidComp(raw, `(Did you mean '*'?)`)\n }\n return []\n }\n #validXm(\n raw: string,\n M: string,\n m?: string,\n p?: string,\n ): ParsedXMinor {\n assertMissing(p, raw, 'major')\n if (m === '' || p === '') {\n throw invalidComp(raw, `(Did you mean '${M}'?)`)\n }\n return [assertNumber(M, raw, 'major')]\n }\n #validXp(\n raw: string,\n M: string,\n m: string,\n p?: string,\n ): ParsedXPatch {\n if (p === '') {\n throw invalidComp(raw, `(Did you mean '${M}.${m}'?)`)\n }\n return [\n assertNumber(M, raw, 'major'),\n assertNumber(m, raw, 'minor'),\n ]\n }\n #validTuple(\n raw: string,\n M: string,\n m: string,\n p: string,\n ): ParsedXVersion {\n return [\n assertNumber(M, raw, 'major'),\n assertNumber(m, raw, 'minor'),\n assertNumber(p, raw, 'patch'),\n ]\n }\n #validXbuild(\n raw: string,\n M: string,\n m: string,\n p: string,\n pl: number,\n ): ParsedXVersion {\n // build, no prerelease\n const patch = p.substring(0, pl)\n const build = p.substring(pl + 1)\n if (!patch) {\n throw invalidComp(raw, 'cannot specify build without patch')\n }\n if (!build) {\n throw invalidComp(raw, `encountered '+', but no build value`)\n }\n return [\n assertNumber(M, raw, 'major'),\n assertNumber(m, raw, 'minor'),\n assertNumber(patch, raw, 'patch'),\n undefined,\n build,\n ]\n }\n\n #validXpr(\n raw: string,\n M: string,\n m: string,\n p: string,\n hy: number,\n ): ParsedXVersion {\n {\n // prerelease, no build\n const patch = p.substring(0, hy)\n const pr = p.substring(hy + 1)\n if (!patch) {\n throw invalidComp(\n raw,\n 'cannot specify prerelease without patch',\n )\n }\n if (!pr) {\n throw invalidComp(\n raw,\n `encountered '-', but no prerelease value`,\n )\n }\n return [\n assertNumber(M, raw, 'major'),\n assertNumber(m, raw, 'minor'),\n assertNumber(patch, raw, 'patch'),\n pr,\n undefined,\n ]\n }\n }\n #validXprbuild(\n raw: string,\n M: string,\n m: string,\n p: string,\n hy: number,\n pl: number,\n ): ParsedXVersion {\n // both prerelease and build\n const patch = p.substring(0, hy)\n const pr = p.substring(hy + 1, pl)\n const build = p.substring(pl + 1)\n if (!patch) {\n throw invalidComp(\n raw,\n 'cannot specify prerelease without patch',\n )\n }\n if (!pr) {\n throw invalidComp(\n raw,\n `encountered '-', but no prerelease value`,\n )\n }\n if (!build) {\n throw invalidComp(raw, `encountered '+', but no build value`)\n }\n return [\n assertNumber(M, raw, 'major'),\n assertNumber(m, raw, 'minor'),\n assertNumber(patch, raw, 'patch'),\n pr,\n build,\n ]\n }\n\n // pull the relevant values out of an X-range or version\n // return the fields for creating a Version object.\n // only call once operator is stripped off\n #parseX(raw: string): ParsedXRange {\n let [M, m, p] = fastSplit(raw, '.', 3)\n let prune = 0\n while (M && preJunk.has(M.charAt(prune))) prune++\n if (M !== undefined && prune !== 0) M = M.substring(prune)\n // the `|| !M` is so TS knows we've handled undefined\n if (!M || isX(M)) return this.#validXM(raw, m, p)\n if (!m || isX(m)) return this.#validXm(raw, M, m, p)\n if (!p || isX(p)) return this.#validXp(raw, M, m, p)\n\n const hy = p.indexOf('-')\n const pl = p.indexOf('+')\n if (pl === -1 && hy === -1) return this.#validTuple(raw, M, m, p)\n if (pl === -1) return this.#validXpr(raw, M, m, p, hy)\n if (hy === -1) return this.#validXbuild(raw, M, m, p, pl)\n return this.#validXprbuild(raw, M, m, p, hy, pl)\n }\n\n #parseHyphenRange(min: string, max: string) {\n const minv = this.#xInclusiveMin(min)\n const maxv = this.#xInclusiveMax(max)\n const minAny = isAny(minv)\n const maxAny = isAny(maxv)\n if (minAny && maxAny) this.tuples.push(this.#getComparatorAny())\n else if (minAny) this.tuples.push(maxv)\n else if (maxAny) this.tuples.push(minv)\n else this.tuples.push(minv, maxv)\n }\n\n #parse(comp: string) {\n const first = comp.charAt(0)\n const first2 = comp.substring(0, 2)\n const v1 = comp.substring(1)\n const v2 = comp.substring(2)\n switch (first2) {\n case '~>':\n assertVersion(v2, comp)\n return this.#parseTilde(v2)\n case '>=':\n assertVersion(v2, comp)\n return this.tuples.push(this.#xInclusiveMin(v2))\n case '<=':\n assertVersion(v2, comp)\n return this.tuples.push(this.#xInclusiveMax(v2))\n }\n switch (first) {\n case '~':\n assertVersion(v1, comp)\n return this.#parseTilde(v1)\n case '^':\n assertVersion(v1, comp)\n return this.#parseCaret(v1)\n case '>':\n assertVersion(v1, comp)\n return this.tuples.push(this.#xExclusiveMin(v1))\n case '<':\n assertVersion(v1, comp)\n return this.tuples.push(this.#xExclusiveMax(v1))\n }\n return this.#parseEq(comp)\n }\n\n #parseTilde(comp: string) {\n const parsed = this.#parseX(comp)\n if (isXMajor(parsed)) {\n this.tuples.push(this.#getComparatorAny())\n return\n }\n const z = this.includePrerelease ? '0' : undefined\n if (isXMinor(parsed)) {\n const [M] = parsed\n this.tuples.push(\n ['>=', new Version(comp, M, 0, 0, z, undefined)],\n ['<', new Version(comp, M + 1, 0, 0, '0', undefined)],\n )\n return\n }\n if (isXPatch(parsed)) {\n const [M, m] = parsed\n const z = this.includePrerelease ? '0' : undefined\n this.tuples.push(\n ['>=', new Version(comp, M, m, 0, z, undefined)],\n ['<', new Version(comp, M, m + 1, 0, '0', undefined)],\n )\n return\n }\n const [M, m, p, pr = z, build] = parsed\n this.tuples.push(\n ['>=', new Version(comp, M, m, p, pr, build)],\n ['<', new Version(comp, M, m + 1, 0, '0', build)],\n )\n }\n\n #parseCaret(comp: string) {\n const min = this.#xInclusiveMin(comp)\n if (isAny(min)) {\n this.tuples.push(min)\n return\n }\n const minv = min[1]\n if (minv.major !== 0) {\n this.tuples.push(min, [\n '<',\n new Version(comp, minv.major + 1, 0, 0, '0', undefined),\n ])\n } else if (minv.minor !== 0) {\n this.tuples.push(min, [\n '<',\n new Version(\n comp,\n minv.major,\n minv.minor + 1,\n 0,\n '0',\n undefined,\n ),\n ])\n } else if (!minv.prerelease?.length) {\n this.tuples.push(['', minv])\n } else {\n this.tuples.push(min, [\n '<',\n new Version(\n comp,\n minv.major,\n minv.minor,\n minv.patch + 1,\n '0',\n undefined,\n ),\n ])\n }\n }\n\n #parseEq(comp: string) {\n const parsed = this.#parseX(comp)\n const z = this.includePrerelease ? '0' : undefined\n if (isFullVersion(parsed)) {\n this.tuples.push(['', new Version(comp, ...parsed)])\n } else if (isXMajor(parsed)) {\n this.tuples.push(this.#getComparatorAny())\n } else if (isXMinor(parsed)) {\n this.tuples.push([\n '>=',\n new Version(comp, parsed[MAJOR], 0, 0, z, undefined),\n ])\n this.tuples.push([\n '<',\n new Version(comp, parsed[MAJOR] + 1, 0, 0, '0', undefined),\n ])\n } else if (isXPatch(parsed)) {\n this.tuples.push(\n [\n '>=',\n new Version(\n comp,\n parsed[MAJOR],\n parsed[MINOR],\n 0,\n z,\n undefined,\n ),\n ],\n [\n '<',\n new Version(\n comp,\n parsed[MAJOR],\n parsed[MINOR] + 1,\n 0,\n '0',\n undefined,\n ),\n ],\n )\n }\n }\n\n /** return true if the version is a match for this comparator */\n test(v: Version) {\n if (this.isNone) return false\n const ip = this.includePrerelease\n const hasPR = !!v.prerelease?.length\n let prOK = ip || !hasPR\n for (const c of this.tuples) {\n if (isAny(c)) {\n continue\n }\n const [op, cv] = c\n prOK ||= !!cv.prerelease?.length && v.tupleEquals(cv)\n switch (op) {\n case '':\n if (!v.equals(cv)) return false\n continue\n case '>':\n if (!v.greaterThan(cv)) return false\n continue\n case '>=':\n if (!v.greaterThanEqual(cv)) return false\n continue\n case '<':\n if (!v.lessThan(cv)) return false\n continue\n case '<=':\n if (!v.lessThanEqual(cv)) return false\n continue\n }\n }\n // they all passed, so it can only fail for having a prerelease\n // if we allow prereleases, or saw a matching tuple, that's ok.\n return prOK\n }\n\n #getComparatorAny() {\n return this.includePrerelease ? comparatorAnyPR : comparatorAny\n }\n}\n\nconst isAny = (c: Comparator | OVTuple): c is Comparator =>\n c === comparatorAny || c === comparatorAnyPR\nconst comparatorAny = {\n isAny: true,\n toString: () => '*',\n includePrerelease: false,\n test: (v: Version) => !v.prerelease?.length,\n} as Comparator\nconst comparatorAnyPR = {\n isAny: true,\n toString: () => '*',\n includePrerelease: true,\n test: (_: Version) => true,\n} as Comparator\nconst comparatorNone = {\n isNone: true,\n toString: () => '<0.0.0-0',\n includePrerelease: false,\n test: (_: Version) => false,\n} as unknown as Comparator\n"]}
import { Range } from './range.ts';
import { Version } from './version.ts';
import type { IncrementType } from './version.ts';
export * from './comparator.ts';
export * from './range.ts';
export * from './version.ts';
/** Return the parsed version string, or `undefined` if invalid */
export declare const parse: (version: Version | string) => Version | undefined;
/** Return the parsed version range, or `undefined` if invalid */
export declare const parseRange: (range: Range | string, includePrerelease?: boolean) => Range | undefined;
/**
* return true if the version is valid
*
* Note: do not use this if you intend to immediately parse the version if it's
* valid. Just use {@link parse}, and guard the possible undefined value, or
* use `Version.parse(..)` to throw on invalid values.
*/
export declare const valid: (version: Version | string) => boolean;
/**
* return true if the range is valid
*
* Note: do not use this if you intend to immediately parse the range if it's
* valid. Just use {@link parseRange}, and guard the possible undefined value,
* or use `new Range(..)` to throw on invalid values.
*/
export declare const validRange: (range: Range | string) => boolean;
/**
* Return true if the version satisfies the range.
*/
export declare const satisfies: (version: Version | string, range: Range | string, includePrerelease?: boolean) => boolean;
/**
* Increment the specified part of the version, and return the resulting
* object. If a Version object is provided, it will be modified in-place.
*
* See {@link Version.inc} for full description.
*/
export declare const inc: (version: Version | string, part: IncrementType, prereleaseIdentifier?: string) => Version;
/**
* The method used by {@link sort}, exported for passing directly to
* `Array.sort`.
*
* Usage:
*
* ```ts
* import { sortMethod } from '@vltpkg/semver'
* const versions = ['1.2.3', '5.2.3', '2.3.4']
* console.log(versions.sort(sortMethod))
* // ['1.2.3', '2.3.4', '5.2.3']
* ```
*/
export declare const sortMethod: (a: Version | string, b: Version | string) => number;
/**
* Sort an array of version strings or objects in ascending SemVer precedence
* order (ie, lowest versions first).
*
* Invalid version strings are sorted to the end of the array in ascending
* alphabetical order.
*
* Note: when using this method, the list is cloned prior to sorting, to
* prevent surprising mutation. To sort the list in place, see
* {@link sortMethod}.
*/
export declare const sort: <T extends Version | string = string | Version>(list: T[]) => T[];
/**
* Sort an array of version strings or objects in descending SemVer
* precedence order (ie, highest versions first).
*
* Invalid version strings are sorted to the end of the array in ascending
* alphabetical order.
*
* Note: when using this method, the list is cloned prior to sorting, to
* prevent surprising mutation. To sort the list in place, see
* {@link rsortMethod}.
*/
export declare const rsort: <T extends Version | string = string | Version>(list: T[]) => T[];
/**
* The method used by {@link rsort}, exported for passing directly to
* `Array.sort`.
*
* Usage:
*
* ```ts
* import { rsortMethod } from '@vltpkg/semver'
* const versions = ['1.2.3', '5.2.3', '2.3.4']
* console.log(versions.sort(rsortMethod))
* // ['5.2.3', '2.3.4', '1.2.3']
* ```
*/
export declare const rsortMethod: (a: Version | string, b: Version | string) => number;
/**
* Method used by {@link filter}, for use in `Array.filter` directly.
*
* Usage:
*
* ```ts
* import { filterMethod } from '@vltpkg/semver'
* const versions = ['1.2.3', '5.2.3', '2.3.4']
* console.log(versions.filter(filterMethod('>=2.x')))
* // ['5.2.3', '2.3.4']
* ```
*/
export declare const filterMethod: (range: Range | string, includePrerelease?: boolean) => ((version: Version | string) => boolean);
/**
* Filter a list of versions to find all that match a given range.
*/
export declare const filter: <T extends Version | string = string | Version>(list: T[], range: Range | string, includePrerelease?: boolean) => T[];
/**
* Find the highest-precedence match for a range within a list of versions
*
* Returns `undefined` if no match was found.
*/
export declare const highest: (list: (Version | string)[], range: Range | string, includePrerelease?: boolean) => Version | undefined;
/**
* Faster form of {@link highest}, for use when the list is sorted
* in precedence order (lower-precedence versions first).
*
* Note: This stops at the first match, and will produce incorrect results
* when the list is not properly sorted!
*/
export declare const sortedHighest: (list: (Version | string)[], range: Range | string, includePrerelease?: boolean) => Version | undefined;
/**
* Faster form of {@link highest}, for use when the list is sorted
* in reverse precedence order (higher-precedence versions first).
*
* Note: This stops at the first match, and will produce incorrect results
* when the list is not properly sorted!
*/
export declare const rsortedHighest: (list: (Version | string)[], range: Range | string, includePrerelease?: boolean) => Version | undefined;
/**
* Find the lowest-precedence match for a range within a list of versions
*
* Returns `undefined` if no match was found.
*/
export declare const lowest: (list: (Version | string)[], range: Range | string, includePrerelease?: boolean) => Version | undefined;
/**
* Faster form of {@link lowest}, for use when the list is sorted
* in precedence order (lower-precedence versions first).
*
* Note: This stops at the first match, and will produce incorrect results
* when the list is not properly sorted!
*/
export declare const sortedLowest: (list: (Version | string)[], range: Range | string, includePrerelease?: boolean) => Version | undefined;
/**
* Faster form of {@link lowest}, for use when the list is sorted
* in reverse precedence order (higher-precedence versions first).
*
* Note: This stops at the first match, and will produce incorrect results
* when the list is not properly sorted!
*/
export declare const rsortedLowest: (list: (Version | string)[], range: Range | string, includePrerelease?: boolean) => Version | undefined;
/**
* Same as {@link sortMethod}, but throws if either version is not valid.
* 1 if versionA is higher precedence than versionB
* -1 if versionA is lower precedence than versionB
* 0 if they have equal precedence
*/
export declare const compare: (versionA: Version | string, versionB: Version | string) => 0 | 1 | -1;
/**
* Inverse of {@link compare}
*
* Same as {@link rsortMethod}, but throws if either version is not valid.
*
* -1 if versionA is higher precedence than versionB
* 1 if versionA is lower precedence than versionB
* 0 if they have equal precedence
*/
export declare const rcompare: (versionA: Version | string, versionB: Version | string) => 0 | 1 | -1;
/** true if versionA is > versionB. throws on invalid values */
export declare const gt: (versionA: Version | string, versionB: Version | string) => boolean;
/** true if versionA is >= versionB. throws on invalid values */
export declare const gte: (versionA: Version | string, versionB: Version | string) => boolean;
/** true if versionA is < versionB. throws on invalid values */
export declare const lt: (versionA: Version | string, versionB: Version | string) => boolean;
/** true if versionA is &lt;= versionB. throws on invalid values */
export declare const lte: (versionA: Version | string, versionB: Version | string) => boolean;
/** true if versionA is not equal to versionB. throws on invalid values */
export declare const neq: (versionA: Version | string, versionB: Version | string) => boolean;
/** true if versionA is equal to versionB. throws on invalid values */
export declare const eq: (versionA: Version | string, versionB: Version | string) => boolean;
/** extract the major version number, or undefined if invalid */
export declare const major: (version: Version | string) => number | undefined;
/** extract the minor version number, or undefined if invalid */
export declare const minor: (version: Version | string) => number | undefined;
/** extract the patch version number, or undefined if invalid */
export declare const patch: (version: Version | string) => number | undefined;
/**
* extract the list of prerelease identifiers, or undefined if the version
* is invalid. If no prerelease identifiers are present, returns `[]`.
*/
export declare const prerelease: (version: Version | string) => (string | number)[] | undefined;
/**
* extract the list of build identifiers, or undefined if the version
* is invalid. If no build identifiers are present, returns `[]`.
*/
export declare const build: (version: Version | string) => string[] | undefined;
/** return all versions that do not have any prerelease identifiers */
export declare const stable: <T extends Version | string = string | Version>(versions: T[]) => T[];
/**
* Return true if the range r1 intersects any of the ranges r2
* r1 and r2 are either Range objects or range strings.
* Returns true if any version would satisfy both ranges.
*/
export declare const intersects: (r1: Range | string, r2: Range | string, includePrerelease?: boolean) => boolean;
//# sourceMappingURL=index.d.ts.map
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAGjD,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;;;;;GAKG;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;;;;;;;;;;GA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YAAa,OAAO,GAAG,MAAM,yBAI9C,CAAA;AAED,sEAAsE;AACtE,eAAO,MAAM,MAAM,GAAI,CAAC,SAAS,OAAO,GAAG,MAAM,+BACrC,CAAC,EAAE,KACZ,CAAC,EAKA,CAAA;AAEJ;;;;GAIG;AACH,eAAO,MAAM,UAAU,OACjB,KAAK,GAAG,MAAM,MACd,KAAK,GAAG,MAAM,sBACE,OAAO,YAgB5B,CAAA"}
import { Range } from "./range.js";
import { Version } from "./version.js";
import { syntaxError } from '@vltpkg/error-cause';
export * from "./comparator.js";
export * from "./range.js";
export * from "./version.js";
/** Return the parsed version string, or `undefined` if invalid */
export const parse = (version) => {
if (!(typeof version === 'string'))
return version;
try {
return Version.parse(version);
}
catch {
return undefined;
}
};
/** Return the parsed version range, or `undefined` if invalid */
export const parseRange = (range, includePrerelease = false) => {
if (typeof range === 'object') {
if (range.includePrerelease === includePrerelease)
return range;
range = range.raw;
}
try {
return new Range(range, includePrerelease);
}
catch {
return undefined;
}
};
/**
* return true if the version is valid
*
* Note: do not use this if you intend to immediately parse the version if it's
* valid. Just use {@link parse}, and guard the possible undefined value, or
* use `Version.parse(..)` to throw on invalid values.
*/
export const valid = (version) => !!parse(version);
/**
* return true if the range is valid
*
* Note: do not use this if you intend to immediately parse the range if it's
* valid. Just use {@link parseRange}, and guard the possible undefined value,
* or use `new Range(..)` to throw on invalid values.
*/
export const validRange = (range) => !!parseRange(range);
/**
* Return true if the version satisfies the range.
*/
export const satisfies = (version, range, includePrerelease = false) => {
if (typeof version === 'string') {
const parsed = parse(version);
if (!parsed)
return false;
version = parsed;
}
if (typeof range === 'string') {
const parsed = parseRange(range, includePrerelease);
if (!parsed)
return false;
range = parsed;
}
return version.satisfies(range);
};
/**
* Increment the specified part of the version, and return the resulting
* object. If a Version object is provided, it will be modified in-place.
*
* See {@link Version.inc} for full description.
*/
export const inc = (version, part, prereleaseIdentifier) => (typeof version === 'string' ?
Version.parse(version)
: version).inc(part, prereleaseIdentifier);
/**
* The method used by {@link sort}, exported for passing directly to
* `Array.sort`.
*
* Usage:
*
* ```ts
* import { sortMethod } from '@vltpkg/semver'
* const versions = ['1.2.3', '5.2.3', '2.3.4']
* console.log(versions.sort(sortMethod))
* // ['1.2.3', '2.3.4', '5.2.3']
* ```
*/
export const sortMethod = (a, b) => {
const pa = parse(a);
const pb = parse(b);
/* c8 ignore start - nondeterministic */
if (!pa && !pb)
return String(a).localeCompare(String(b), 'en');
if (!pa)
return 1;
if (!pb)
return -1;
/* c8 ignore stop */
return pa.compare(pb);
};
/**
* Sort an array of version strings or objects in ascending SemVer precedence
* order (ie, lowest versions first).
*
* Invalid version strings are sorted to the end of the array in ascending
* alphabetical order.
*
* Note: when using this method, the list is cloned prior to sorting, to
* prevent surprising mutation. To sort the list in place, see
* {@link sortMethod}.
*/
export const sort = (list) => list.slice().sort(sortMethod);
/**
* Sort an array of version strings or objects in descending SemVer
* precedence order (ie, highest versions first).
*
* Invalid version strings are sorted to the end of the array in ascending
* alphabetical order.
*
* Note: when using this method, the list is cloned prior to sorting, to
* prevent surprising mutation. To sort the list in place, see
* {@link rsortMethod}.
*/
export const rsort = (list) => list.slice().sort(rsortMethod);
/**
* The method used by {@link rsort}, exported for passing directly to
* `Array.sort`.
*
* Usage:
*
* ```ts
* import { rsortMethod } from '@vltpkg/semver'
* const versions = ['1.2.3', '5.2.3', '2.3.4']
* console.log(versions.sort(rsortMethod))
* // ['5.2.3', '2.3.4', '1.2.3']
* ```
*/
export const rsortMethod = (a, b) => {
const pa = parse(a);
const pb = parse(b);
/* c8 ignore start - nondeterministic */
if (!pa && !pb)
return String(a).localeCompare(String(b), 'en');
if (!pa)
return 1;
if (!pb)
return -1;
/* c8 ignore stop */
return pa.rcompare(pb);
};
/**
* Method used by {@link filter}, for use in `Array.filter` directly.
*
* Usage:
*
* ```ts
* import { filterMethod } from '@vltpkg/semver'
* const versions = ['1.2.3', '5.2.3', '2.3.4']
* console.log(versions.filter(filterMethod('>=2.x')))
* // ['5.2.3', '2.3.4']
* ```
*/
export const filterMethod = (range, includePrerelease = false) => {
const r = parseRange(range, includePrerelease);
return !r ?
() => false
: version => satisfies(version, r, r.includePrerelease);
};
/**
* Filter a list of versions to find all that match a given range.
*/
export const filter = (list, range, includePrerelease = false) => list.filter(filterMethod(range, includePrerelease));
/**
* Find the highest-precedence match for a range within a list of versions
*
* Returns `undefined` if no match was found.
*/
export const highest = (list, range, includePrerelease = false) => {
const r = parseRange(range, includePrerelease);
if (!r)
return undefined;
let max = undefined;
for (const v of list) {
const version = parse(v);
if (!version)
continue;
if (!version.satisfies(r))
continue;
if (!max)
max = version;
else if (version.greaterThan(max))
max = version;
}
return max;
};
/**
* Faster form of {@link highest}, for use when the list is sorted
* in precedence order (lower-precedence versions first).
*
* Note: This stops at the first match, and will produce incorrect results
* when the list is not properly sorted!
*/
export const sortedHighest = (list, range, includePrerelease = false) => {
const r = parseRange(range, includePrerelease);
if (!r)
return undefined;
for (let i = list.length - 1; i >= 0; i--) {
const v = list[i];
/* c8 ignore next */
if (!v)
continue;
const version = parse(v);
if (!version)
continue;
if (!version.satisfies(r))
continue;
return version;
}
};
/**
* Faster form of {@link highest}, for use when the list is sorted
* in reverse precedence order (higher-precedence versions first).
*
* Note: This stops at the first match, and will produce incorrect results
* when the list is not properly sorted!
*/
export const rsortedHighest = (list, range, includePrerelease = false) => {
const r = parseRange(range, includePrerelease);
if (!r)
return undefined;
for (const v of list) {
const version = parse(v);
if (!version)
continue;
if (!version.satisfies(r))
continue;
return version;
}
};
/**
* Find the lowest-precedence match for a range within a list of versions
*
* Returns `undefined` if no match was found.
*/
export const lowest = (list, range, includePrerelease = false) => {
const r = parseRange(range, includePrerelease);
if (!r)
return undefined;
let min = undefined;
for (const v of list) {
const version = parse(v);
if (!version)
continue;
if (!version.satisfies(r))
continue;
if (!min)
min = version;
else if (version.lessThan(min))
min = version;
}
return min;
};
/**
* Faster form of {@link lowest}, for use when the list is sorted
* in precedence order (lower-precedence versions first).
*
* Note: This stops at the first match, and will produce incorrect results
* when the list is not properly sorted!
*/
export const sortedLowest = (list, range, includePrerelease = false) => rsortedHighest(list, range, includePrerelease);
/**
* Faster form of {@link lowest}, for use when the list is sorted
* in reverse precedence order (higher-precedence versions first).
*
* Note: This stops at the first match, and will produce incorrect results
* when the list is not properly sorted!
*/
export const rsortedLowest = (list, range, includePrerelease = false) => sortedHighest(list, range, includePrerelease);
/**
* Same as {@link sortMethod}, but throws if either version is not valid.
* 1 if versionA is higher precedence than versionB
* -1 if versionA is lower precedence than versionB
* 0 if they have equal precedence
*/
export const compare = (versionA, versionB) => {
const a = parse(versionA);
if (!a) {
throw syntaxError('invalid version', { found: versionA });
}
const b = parse(versionB);
if (!b) {
throw syntaxError('invalid version', { found: versionB });
}
return a.compare(b);
};
/**
* Inverse of {@link compare}
*
* Same as {@link rsortMethod}, but throws if either version is not valid.
*
* -1 if versionA is higher precedence than versionB
* 1 if versionA is lower precedence than versionB
* 0 if they have equal precedence
*/
export const rcompare = (versionA, versionB) => compare(versionB, versionA);
/** true if versionA is > versionB. throws on invalid values */
export const gt = (versionA, versionB) => compare(versionA, versionB) > 0;
/** true if versionA is >= versionB. throws on invalid values */
export const gte = (versionA, versionB) => compare(versionA, versionB) >= 0;
/** true if versionA is < versionB. throws on invalid values */
export const lt = (versionA, versionB) => compare(versionA, versionB) < 0;
/** true if versionA is &lt;= versionB. throws on invalid values */
export const lte = (versionA, versionB) => compare(versionA, versionB) <= 0;
/** true if versionA is not equal to versionB. throws on invalid values */
export const neq = (versionA, versionB) => compare(versionA, versionB) !== 0;
/** true if versionA is equal to versionB. throws on invalid values */
export const eq = (versionA, versionB) => compare(versionA, versionB) === 0;
/** extract the major version number, or undefined if invalid */
export const major = (version) => parse(version)?.major;
/** extract the minor version number, or undefined if invalid */
export const minor = (version) => parse(version)?.minor;
/** extract the patch version number, or undefined if invalid */
export const patch = (version) => parse(version)?.patch;
/**
* extract the list of prerelease identifiers, or undefined if the version
* is invalid. If no prerelease identifiers are present, returns `[]`.
*/
export const prerelease = (version) => {
const p = parse(version);
if (!p)
return undefined;
return p.prerelease ?? [];
};
/**
* extract the list of build identifiers, or undefined if the version
* is invalid. If no build identifiers are present, returns `[]`.
*/
export const build = (version) => {
const p = parse(version);
if (!p)
return undefined;
return p.build ?? [];
};
/** return all versions that do not have any prerelease identifiers */
export const stable = (versions) => versions.filter(v => {
const p = parse(v);
if (!p)
return false;
return !p.prerelease?.length;
});
/**
* Return true if the range r1 intersects any of the ranges r2
* r1 and r2 are either Range objects or range strings.
* Returns true if any version would satisfy both ranges.
*/
export const intersects = (r1, r2, includePrerelease) => {
const range1 = typeof r1 === 'string' ? parseRange(r1, includePrerelease) : r1;
const range2 = typeof r2 === 'string' ? parseRange(r2, includePrerelease) : r2;
if (!range1 || !range2)
return false;
// If either range is 'any', they intersect
if (range1.isAny || range2.isAny)
return true;
// Check if any set from range1 intersects with any set from range2
return range1.set.some(set1 => range2.set.some(set2 => intersectComparators(set1, set2)));
};
/**
* Check if two comparators can be satisfied simultaneously
*/
const intersectComparators = (comp1, comp2) => {
// Collect all tuples from both comparators
const tuples1 = comp1.tuples.filter((t) => Array.isArray(t));
const tuples2 = comp2.tuples.filter((t) => Array.isArray(t));
// Check if there's a satisfiable combination
return satisfiableRange(tuples1.concat(tuples2));
};
/**
* Check if a set of operator-version tuples represents a satisfiable range
* This is a simplified implementation that handles the most common cases
*/
const satisfiableRange = (tuples) => {
// Find bounds
let lowerBound = null;
let lowerInclusive = false;
let upperBound = null;
let upperInclusive = false;
let hasExact = null;
for (const [op, ver] of tuples) {
switch (op) {
case '':
// Exact match - if we already have a different exact match, no intersection
if (hasExact && !eq(hasExact, ver))
return false;
hasExact = ver;
break;
case '>=':
/* c8 ignore start */
if (!lowerBound ||
gt(ver, lowerBound) ||
(eq(ver, lowerBound) && !lowerInclusive)) {
lowerBound = ver;
lowerInclusive = true;
}
/* c8 ignore stop */
break;
case '>':
if (!lowerBound || gt(ver, lowerBound)) {
lowerBound = ver;
lowerInclusive = false;
}
break;
case '<=':
if (!upperBound || lt(ver, upperBound)) {
upperBound = ver;
upperInclusive = true;
}
break;
case '<':
/* c8 ignore start */
if (!upperBound ||
lt(ver, upperBound) ||
eq(ver, upperBound)) {
upperBound = ver;
upperInclusive = false;
}
/* c8 ignore stop */
break;
}
}
// If we have an exact match, check if it's within bounds
if (hasExact) {
if (lowerBound) {
if (lowerInclusive ?
lt(hasExact, lowerBound)
: lte(hasExact, lowerBound)) {
return false;
}
}
if (upperBound) {
if (upperInclusive ?
gt(hasExact, upperBound)
: gte(hasExact, upperBound)) {
return false;
}
}
return true;
}
// Check if lower bound is less than or equal to upper bound
if (lowerBound && upperBound) {
if (gt(lowerBound, upperBound))
return false;
if (eq(lowerBound, upperBound) &&
!(lowerInclusive && upperInclusive))
return false;
}
return true;
};
//# sourceMappingURL=index.js.map
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAGtC,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAEjD,cAAc,iBAAiB,CAAA;AAC/B,cAAc,YAAY,CAAA;AAC1B,cAAc,cAAc,CAAA;AAE5B,kEAAkE;AAClE,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,OAAyB,EAAE,EAAE;IACjD,IAAI,CAAC,CAAC,OAAO,OAAO,KAAK,QAAQ,CAAC;QAAE,OAAO,OAAO,CAAA;IAClD,IAAI,CAAC;QACH,OAAO,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IAC/B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAA;IAClB,CAAC;AACH,CAAC,CAAA;AAED,iEAAiE;AACjE,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,KAAqB,EACrB,iBAAiB,GAAG,KAAK,EACzB,EAAE;IACF,IAAI,OAAO,KAA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IAAI,EAAE,CAAC,UAAU,EAAE,UAAU,CAAC;YAAE,OAAO,KAAK,CAAA;QAC5C,IACE,EAAE,CAAC,UAAU,EAAE,UAAU,CAAC;YAC1B,CAAC,CAAC,cAAc,IAAI,cAAc,CAAC;YAEnC,OAAO,KAAK,CAAA;IAChB,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC,CAAA","sourcesContent":["import { Range } from './range.ts'\nimport { Version } from './version.ts'\nimport type { Comparator, OVTuple } from './comparator.ts'\nimport type { IncrementType } from './version.ts'\nimport { syntaxError } from '@vltpkg/error-cause'\n\nexport * from './comparator.ts'\nexport * from './range.ts'\nexport * from './version.ts'\n\n/** Return the parsed version string, or `undefined` if invalid */\nexport const parse = (version: Version | string) => {\n if (!(typeof version === 'string')) return version\n try {\n return Version.parse(version)\n } catch {\n return undefined\n }\n}\n\n/** Return the parsed version range, or `undefined` if invalid */\nexport const parseRange = (\n range: Range | string,\n includePrerelease = false,\n) => {\n if (typeof range === 'object') {\n if (range.includePrerelease === includePrerelease) return range\n range = range.raw\n }\n try {\n return new Range(range, includePrerelease)\n } catch {\n return undefined\n }\n}\n\n/**\n * return true if the version is valid\n *\n * Note: do not use this if you intend to immediately parse the version if it's\n * valid. Just use {@link parse}, and guard the possible undefined value, or\n * use `Version.parse(..)` to throw on invalid values.\n */\nexport const valid = (version: Version | string) => !!parse(version)\n\n/**\n * return true if the range is valid\n *\n * Note: do not use this if you intend to immediately parse the range if it's\n * valid. Just use {@link parseRange}, and guard the possible undefined value,\n * or use `new Range(..)` to throw on invalid values.\n */\nexport const validRange = (range: Range | string) =>\n !!parseRange(range)\n\n/**\n * Return true if the version satisfies the range.\n */\nexport const satisfies = (\n version: Version | string,\n range: Range | string,\n includePrerelease = false,\n) => {\n if (typeof version === 'string') {\n const parsed = parse(version)\n if (!parsed) return false\n version = parsed\n }\n if (typeof range === 'string') {\n const parsed = parseRange(range, includePrerelease)\n if (!parsed) return false\n range = parsed\n }\n return version.satisfies(range)\n}\n\n/**\n * Increment the specified part of the version, and return the resulting\n * object. If a Version object is provided, it will be modified in-place.\n *\n * See {@link Version.inc} for full description.\n */\nexport const inc = (\n version: Version | string,\n part: IncrementType,\n prereleaseIdentifier?: string,\n) =>\n (typeof version === 'string' ?\n Version.parse(version)\n : version\n ).inc(part, prereleaseIdentifier)\n\n/**\n * The method used by {@link sort}, exported for passing directly to\n * `Array.sort`.\n *\n * Usage:\n *\n * ```ts\n * import { sortMethod } from '@vltpkg/semver'\n * const versions = ['1.2.3', '5.2.3', '2.3.4']\n * console.log(versions.sort(sortMethod))\n * // ['1.2.3', '2.3.4', '5.2.3']\n * ```\n */\nexport const sortMethod = (\n a: Version | string,\n b: Version | string,\n) => {\n const pa = parse(a)\n const pb = parse(b)\n /* c8 ignore start - nondeterministic */\n if (!pa && !pb) return String(a).localeCompare(String(b), 'en')\n if (!pa) return 1\n if (!pb) return -1\n /* c8 ignore stop */\n return pa.compare(pb)\n}\n\n/**\n * Sort an array of version strings or objects in ascending SemVer precedence\n * order (ie, lowest versions first).\n *\n * Invalid version strings are sorted to the end of the array in ascending\n * alphabetical order.\n *\n * Note: when using this method, the list is cloned prior to sorting, to\n * prevent surprising mutation. To sort the list in place, see\n * {@link sortMethod}.\n */\nexport const sort = <T extends Version | string = Version | string>(\n list: T[],\n): T[] => list.slice().sort(sortMethod)\n\n/**\n * Sort an array of version strings or objects in descending SemVer\n * precedence order (ie, highest versions first).\n *\n * Invalid version strings are sorted to the end of the array in ascending\n * alphabetical order.\n *\n * Note: when using this method, the list is cloned prior to sorting, to\n * prevent surprising mutation. To sort the list in place, see\n * {@link rsortMethod}.\n */\nexport const rsort = <T extends Version | string = Version | string>(\n list: T[],\n): T[] => list.slice().sort(rsortMethod)\n\n/**\n * The method used by {@link rsort}, exported for passing directly to\n * `Array.sort`.\n *\n * Usage:\n *\n * ```ts\n * import { rsortMethod } from '@vltpkg/semver'\n * const versions = ['1.2.3', '5.2.3', '2.3.4']\n * console.log(versions.sort(rsortMethod))\n * // ['5.2.3', '2.3.4', '1.2.3']\n * ```\n */\nexport const rsortMethod = (\n a: Version | string,\n b: Version | string,\n) => {\n const pa = parse(a)\n const pb = parse(b)\n /* c8 ignore start - nondeterministic */\n if (!pa && !pb) return String(a).localeCompare(String(b), 'en')\n if (!pa) return 1\n if (!pb) return -1\n /* c8 ignore stop */\n return pa.rcompare(pb)\n}\n\n/**\n * Method used by {@link filter}, for use in `Array.filter` directly.\n *\n * Usage:\n *\n * ```ts\n * import { filterMethod } from '@vltpkg/semver'\n * const versions = ['1.2.3', '5.2.3', '2.3.4']\n * console.log(versions.filter(filterMethod('>=2.x')))\n * // ['5.2.3', '2.3.4']\n * ```\n */\nexport const filterMethod = (\n range: Range | string,\n includePrerelease = false,\n): ((version: Version | string) => boolean) => {\n const r = parseRange(range, includePrerelease)\n return !r ?\n () => false\n : version => satisfies(version, r, r.includePrerelease)\n}\n\n/**\n * Filter a list of versions to find all that match a given range.\n */\nexport const filter = <T extends Version | string = Version | string>(\n list: T[],\n range: Range | string,\n includePrerelease = false,\n): T[] => list.filter(filterMethod(range, includePrerelease))\n\n/**\n * Find the highest-precedence match for a range within a list of versions\n *\n * Returns `undefined` if no match was found.\n */\nexport const highest = (\n list: (Version | string)[],\n range: Range | string,\n includePrerelease = false,\n): Version | undefined => {\n const r = parseRange(range, includePrerelease)\n if (!r) return undefined\n let max: Version | undefined = undefined\n for (const v of list) {\n const version = parse(v)\n if (!version) continue\n if (!version.satisfies(r)) continue\n if (!max) max = version\n else if (version.greaterThan(max)) max = version\n }\n return max\n}\n\n/**\n * Faster form of {@link highest}, for use when the list is sorted\n * in precedence order (lower-precedence versions first).\n *\n * Note: This stops at the first match, and will produce incorrect results\n * when the list is not properly sorted!\n */\nexport const sortedHighest = (\n list: (Version | string)[],\n range: Range | string,\n includePrerelease = false,\n): Version | undefined => {\n const r = parseRange(range, includePrerelease)\n if (!r) return undefined\n for (let i = list.length - 1; i >= 0; i--) {\n const v = list[i]\n /* c8 ignore next */\n if (!v) continue\n const version = parse(v)\n if (!version) continue\n if (!version.satisfies(r)) continue\n return version\n }\n}\n\n/**\n * Faster form of {@link highest}, for use when the list is sorted\n * in reverse precedence order (higher-precedence versions first).\n *\n * Note: This stops at the first match, and will produce incorrect results\n * when the list is not properly sorted!\n */\nexport const rsortedHighest = (\n list: (Version | string)[],\n range: Range | string,\n includePrerelease = false,\n): Version | undefined => {\n const r = parseRange(range, includePrerelease)\n if (!r) return undefined\n for (const v of list) {\n const version = parse(v)\n if (!version) continue\n if (!version.satisfies(r)) continue\n return version\n }\n}\n\n/**\n * Find the lowest-precedence match for a range within a list of versions\n *\n * Returns `undefined` if no match was found.\n */\nexport const lowest = (\n list: (Version | string)[],\n range: Range | string,\n includePrerelease = false,\n): Version | undefined => {\n const r = parseRange(range, includePrerelease)\n if (!r) return undefined\n let min: Version | undefined = undefined\n for (const v of list) {\n const version = parse(v)\n if (!version) continue\n if (!version.satisfies(r)) continue\n if (!min) min = version\n else if (version.lessThan(min)) min = version\n }\n return min\n}\n\n/**\n * Faster form of {@link lowest}, for use when the list is sorted\n * in precedence order (lower-precedence versions first).\n *\n * Note: This stops at the first match, and will produce incorrect results\n * when the list is not properly sorted!\n */\nexport const sortedLowest = (\n list: (Version | string)[],\n range: Range | string,\n includePrerelease = false,\n): Version | undefined =>\n rsortedHighest(list, range, includePrerelease)\n\n/**\n * Faster form of {@link lowest}, for use when the list is sorted\n * in reverse precedence order (higher-precedence versions first).\n *\n * Note: This stops at the first match, and will produce incorrect results\n * when the list is not properly sorted!\n */\nexport const rsortedLowest = (\n list: (Version | string)[],\n range: Range | string,\n includePrerelease = false,\n): Version | undefined =>\n sortedHighest(list, range, includePrerelease)\n\n/**\n * Same as {@link sortMethod}, but throws if either version is not valid.\n * 1 if versionA is higher precedence than versionB\n * -1 if versionA is lower precedence than versionB\n * 0 if they have equal precedence\n */\nexport const compare = (\n versionA: Version | string,\n versionB: Version | string,\n) => {\n const a = parse(versionA)\n if (!a) {\n throw syntaxError('invalid version', { found: versionA })\n }\n const b = parse(versionB)\n if (!b) {\n throw syntaxError('invalid version', { found: versionB })\n }\n return a.compare(b)\n}\n\n/**\n * Inverse of {@link compare}\n *\n * Same as {@link rsortMethod}, but throws if either version is not valid.\n *\n * -1 if versionA is higher precedence than versionB\n * 1 if versionA is lower precedence than versionB\n * 0 if they have equal precedence\n */\nexport const rcompare = (\n versionA: Version | string,\n versionB: Version | string,\n) => compare(versionB, versionA)\n\n/** true if versionA is > versionB. throws on invalid values */\nexport const gt = (\n versionA: Version | string,\n versionB: Version | string,\n) => compare(versionA, versionB) > 0\n/** true if versionA is >= versionB. throws on invalid values */\nexport const gte = (\n versionA: Version | string,\n versionB: Version | string,\n) => compare(versionA, versionB) >= 0\n/** true if versionA is < versionB. throws on invalid values */\nexport const lt = (\n versionA: Version | string,\n versionB: Version | string,\n) => compare(versionA, versionB) < 0\n/** true if versionA is &lt;= versionB. throws on invalid values */\nexport const lte = (\n versionA: Version | string,\n versionB: Version | string,\n) => compare(versionA, versionB) <= 0\n/** true if versionA is not equal to versionB. throws on invalid values */\nexport const neq = (\n versionA: Version | string,\n versionB: Version | string,\n) => compare(versionA, versionB) !== 0\n/** true if versionA is equal to versionB. throws on invalid values */\nexport const eq = (\n versionA: Version | string,\n versionB: Version | string,\n) => compare(versionA, versionB) === 0\n\n/** extract the major version number, or undefined if invalid */\nexport const major = (version: Version | string) =>\n parse(version)?.major\n/** extract the minor version number, or undefined if invalid */\nexport const minor = (version: Version | string) =>\n parse(version)?.minor\n/** extract the patch version number, or undefined if invalid */\nexport const patch = (version: Version | string) =>\n parse(version)?.patch\n/**\n * extract the list of prerelease identifiers, or undefined if the version\n * is invalid. If no prerelease identifiers are present, returns `[]`.\n */\nexport const prerelease = (version: Version | string) => {\n const p = parse(version)\n if (!p) return undefined\n return p.prerelease ?? []\n}\n/**\n * extract the list of build identifiers, or undefined if the version\n * is invalid. If no build identifiers are present, returns `[]`.\n */\nexport const build = (version: Version | string) => {\n const p = parse(version)\n if (!p) return undefined\n return p.build ?? []\n}\n\n/** return all versions that do not have any prerelease identifiers */\nexport const stable = <T extends Version | string = Version | string>(\n versions: T[],\n): T[] =>\n versions.filter(v => {\n const p = parse(v)\n if (!p) return false\n return !p.prerelease?.length\n })\n\n/**\n * Return true if the range r1 intersects any of the ranges r2\n * r1 and r2 are either Range objects or range strings.\n * Returns true if any version would satisfy both ranges.\n */\nexport const intersects = (\n r1: Range | string,\n r2: Range | string,\n includePrerelease?: boolean,\n) => {\n const range1 =\n typeof r1 === 'string' ? parseRange(r1, includePrerelease) : r1\n const range2 =\n typeof r2 === 'string' ? parseRange(r2, includePrerelease) : r2\n\n if (!range1 || !range2) return false\n\n // If either range is 'any', they intersect\n if (range1.isAny || range2.isAny) return true\n\n // Check if any set from range1 intersects with any set from range2\n return range1.set.some(set1 =>\n range2.set.some(set2 => intersectComparators(set1, set2)),\n )\n}\n\n/**\n * Check if two comparators can be satisfied simultaneously\n */\nconst intersectComparators = (\n comp1: Comparator,\n comp2: Comparator,\n): boolean => {\n // Collect all tuples from both comparators\n const tuples1 = comp1.tuples.filter((t): t is OVTuple =>\n Array.isArray(t),\n )\n const tuples2 = comp2.tuples.filter((t): t is OVTuple =>\n Array.isArray(t),\n )\n\n // Check if there's a satisfiable combination\n return satisfiableRange(tuples1.concat(tuples2))\n}\n\n/**\n * Check if a set of operator-version tuples represents a satisfiable range\n * This is a simplified implementation that handles the most common cases\n */\nconst satisfiableRange = (tuples: OVTuple[]): boolean => {\n // Find bounds\n let lowerBound: Version | null = null\n let lowerInclusive = false\n let upperBound: Version | null = null\n let upperInclusive = false\n let hasExact: Version | null = null\n\n for (const [op, ver] of tuples) {\n switch (op) {\n case '':\n // Exact match - if we already have a different exact match, no intersection\n if (hasExact && !eq(hasExact, ver)) return false\n hasExact = ver\n break\n\n case '>=':\n /* c8 ignore start */\n if (\n !lowerBound ||\n gt(ver, lowerBound) ||\n (eq(ver, lowerBound) && !lowerInclusive)\n ) {\n lowerBound = ver\n lowerInclusive = true\n }\n /* c8 ignore stop */\n break\n\n case '>':\n if (!lowerBound || gt(ver, lowerBound)) {\n lowerBound = ver\n lowerInclusive = false\n }\n break\n\n case '<=':\n if (!upperBound || lt(ver, upperBound)) {\n upperBound = ver\n upperInclusive = true\n }\n break\n\n case '<':\n /* c8 ignore start */\n if (\n !upperBound ||\n lt(ver, upperBound) ||\n eq(ver, upperBound)\n ) {\n upperBound = ver\n upperInclusive = false\n }\n /* c8 ignore stop */\n break\n }\n }\n\n // If we have an exact match, check if it's within bounds\n if (hasExact) {\n if (lowerBound) {\n if (\n lowerInclusive ?\n lt(hasExact, lowerBound)\n : lte(hasExact, lowerBound)\n ) {\n return false\n }\n }\n if (upperBound) {\n if (\n upperInclusive ?\n gt(hasExact, upperBound)\n : gte(hasExact, upperBound)\n ) {\n return false\n }\n }\n return true\n }\n\n // Check if lower bound is less than or equal to upper bound\n if (lowerBound && upperBound) {\n if (gt(lowerBound, upperBound)) return false\n if (\n eq(lowerBound, upperBound) &&\n !(lowerInclusive && upperInclusive)\n )\n return false\n }\n\n return true\n}\n"]}
import { Comparator } from './comparator.ts';
import type { Version } from './version.ts';
export declare const isRange: (range: unknown) => range is Range;
/**
* A representation of a semver range, used to test versions.
*
* Includes a set of comparators representing the `||`-separated
* sections of the range string
*/
export declare class Range {
#private;
/** raw string used to create this Range */
raw: string;
/** true if the range is `*` */
isAny: boolean;
/** true if the range is a single semver version */
isSingle: boolean;
/** true if the range cannot match anything */
/**
* set of {@link Comparator} objects representing the `||`-separated sections
* of the range. If at least one of these matches, then the version is a
* match.
*/
set: Comparator[];
/** true if all prerelease versions should be included */
includePrerelease: boolean;
constructor(range: string, includePrerelease?: boolean);
/**
* test a {@link Version} against the range
*/
test(v: Version): boolean;
/** return the simplified canonical form of this range */
toString(): string;
}
//# sourceMappingURL=range.d.ts.map
{"version":3,"file":"range.d.ts","sourceRoot":"","sources":["../src/range.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAG3C,eAAO,MAAM,OAAO,UAAW,OAAO,KAAG,KAAK,IAAI,KAWjD,CAAA;AAED;;;;;GAKG;AACH,qBAAa,KAAK;;IAChB,2CAA2C;IAC3C,GAAG,EAAE,MAAM,CAAA;IAEX,+BAA+B;IAC/B,KAAK,EAAE,OAAO,CAAA;IAEd,mDAAmD;IACnD,QAAQ,EAAE,OAAO,CAAA;IAEjB,8CAA8C;IAE9C;;;;OAIG;IACH,GAAG,EAAE,UAAU,EAAE,CAAK;IAEtB,yDAAyD;IACzD,iBAAiB,EAAE,OAAO,CAAA;gBAKd,KAAK,EAAE,MAAM,EAAE,iBAAiB,UAAQ;IA+CpD;;OAEG;IACH,IAAI,CAAC,CAAC,EAAE,OAAO;IAIf,yDAAyD;IACzD,QAAQ;CAST"}
import { fastSplit } from '@vltpkg/fast-split';
import { Comparator } from "./comparator.js";
import { asError } from '@vltpkg/types';
export const isRange = (range) => {
return (range instanceof Range ||
(typeof range === 'object' &&
range !== null &&
'raw' in range &&
typeof range.raw === 'string' &&
'set' in range &&
Array.isArray(range.set) &&
range.set.every(c => c instanceof Comparator)));
};
/**
* A representation of a semver range, used to test versions.
*
* Includes a set of comparators representing the `||`-separated
* sections of the range string
*/
export class Range {
/** raw string used to create this Range */
raw;
/** true if the range is `*` */
isAny;
/** true if the range is a single semver version */
isSingle;
/** true if the range cannot match anything */
/**
* set of {@link Comparator} objects representing the `||`-separated sections
* of the range. If at least one of these matches, then the version is a
* match.
*/
set = [];
/** true if all prerelease versions should be included */
includePrerelease;
/** cached toString */
#toString;
constructor(range, includePrerelease = false) {
this.raw = range;
this.includePrerelease = includePrerelease;
this.isAny = false;
let isFirst = true;
this.isSingle = false;
const comparatorErrors = [];
fastSplit(range, '||', -1, part => {
if (this.isAny)
return;
const cmp = this.#maybeComparator(part, this.includePrerelease);
if (cmp instanceof Error) {
comparatorErrors.push(cmp);
return;
}
if (cmp.isAny) {
this.set = [cmp];
this.isAny = true;
return;
}
this.set.push(cmp);
if (!isFirst)
this.isSingle = false;
else if (Array.isArray(cmp.tuples) &&
cmp.tuples.length === 1 &&
Array.isArray(cmp.tuples[0]) &&
cmp.tuples[0][0] === '') {
this.isSingle = true;
}
isFirst = false;
});
if (!this.set.length && comparatorErrors.length) {
if (comparatorErrors.length === 1 && comparatorErrors[0]) {
throw comparatorErrors[0];
}
throw new AggregateError(comparatorErrors);
}
}
#maybeComparator(part, includePrerelease) {
try {
return new Comparator(part, includePrerelease);
}
catch (er) {
return asError(er);
}
}
/**
* test a {@link Version} against the range
*/
test(v) {
return this.set.some(c => c.test(v));
}
/** return the simplified canonical form of this range */
toString() {
if (this.#toString)
return this.#toString;
if (this.isSingle) {
this.#toString = String(this.set[0]);
return this.#toString;
}
this.#toString = this.set.map(c => String(c)).join(' || ');
return this.#toString;
}
}
//# sourceMappingURL=range.js.map
{"version":3,"file":"range.js","sourceRoot":"","sources":["../src/range.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAE5C,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAEvC,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,KAAc,EAAkB,EAAE;IACxD,OAAO,CACL,KAAK,YAAY,KAAK;QACtB,CAAC,OAAO,KAAK,KAAK,QAAQ;YACxB,KAAK,KAAK,IAAI;YACd,KAAK,IAAI,KAAK;YACd,OAAO,KAAK,CAAC,GAAG,KAAK,QAAQ;YAC7B,KAAK,IAAI,KAAK;YACd,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC;YACxB,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,YAAY,UAAU,CAAC,CAAC,CACjD,CAAA;AACH,CAAC,CAAA;AAED;;;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C,CAAC,CAAC,CAAC,CAAA;YACpC,OAAO,IAAI,CAAC,SAAS,CAAA;QACvB,CAAC;QACD,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QAC1D,OAAO,IAAI,CAAC,SAAS,CAAA;IACvB,CAAC;CACF","sourcesContent":["import { fastSplit } from '@vltpkg/fast-split'\nimport { Comparator } from './comparator.ts'\nimport type { Version } from './version.ts'\nimport { asError } from '@vltpkg/types'\n\nexport const isRange = (range: unknown): range is Range => {\n return (\n range instanceof Range ||\n (typeof range === 'object' &&\n range !== null &&\n 'raw' in range &&\n typeof range.raw === 'string' &&\n 'set' in range &&\n Array.isArray(range.set) &&\n range.set.every(c => c instanceof Comparator))\n )\n}\n\n/**\n * A representation of a semver range, used to test versions.\n *\n * Includes a set of comparators representing the `||`-separated\n * sections of the range string\n */\nexport class Range {\n /** raw string used to create this Range */\n raw: string\n\n /** true if the range is `*` */\n isAny: boolean\n\n /** true if the range is a single semver version */\n isSingle: boolean\n\n /** true if the range cannot match anything */\n\n /**\n * set of {@link Comparator} objects representing the `||`-separated sections\n * of the range. If at least one of these matches, then the version is a\n * match.\n */\n set: Comparator[] = []\n\n /** true if all prerelease versions should be included */\n includePrerelease: boolean\n\n /** cached toString */\n #toString?: string\n\n constructor(range: string, includePrerelease = false) {\n this.raw = range\n this.includePrerelease = includePrerelease\n this.isAny = false\n let isFirst = true\n this.isSingle = false\n const comparatorErrors: Error[] = []\n fastSplit(range, '||', -1, part => {\n if (this.isAny) return\n const cmp = this.#maybeComparator(part, this.includePrerelease)\n if (cmp instanceof Error) {\n comparatorErrors.push(cmp)\n return\n }\n if (cmp.isAny) {\n this.set = [cmp]\n this.isAny = true\n return\n }\n this.set.push(cmp)\n if (!isFirst) this.isSingle = false\n else if (\n Array.isArray(cmp.tuples) &&\n cmp.tuples.length === 1 &&\n Array.isArray(cmp.tuples[0]) &&\n cmp.tuples[0][0] === ''\n ) {\n this.isSingle = true\n }\n isFirst = false\n })\n if (!this.set.length && comparatorErrors.length) {\n if (comparatorErrors.length === 1 && comparatorErrors[0]) {\n throw comparatorErrors[0]\n }\n throw new AggregateError(comparatorErrors)\n }\n }\n\n #maybeComparator(part: string, includePrerelease: boolean) {\n try {\n return new Comparator(part, includePrerelease)\n } catch (er) {\n return asError(er)\n }\n }\n\n /**\n * test a {@link Version} against the range\n */\n test(v: Version) {\n return this.set.some(c => c.test(v))\n }\n\n /** return the simplified canonical form of this range */\n toString() {\n if (this.#toString) return this.#toString\n if (this.isSingle) {\n this.#toString = String(this.set[0])\n return this.#toString\n }\n this.#toString = this.set.map(c => String(c)).join(' || ')\n return this.#toString\n }\n}\n"]}
import type { Range } from './range.ts';
/**
* Values of valid increment types.
*/
export declare const versionIncrements: readonly ["major", "minor", "patch", "pre", "premajor", "preminor", "prepatch", "prerelease"];
/**
* Types of incrementing supported by {@link Version#inc}
*/
export type IncrementType = (typeof versionIncrements)[number];
/**
* A parsed object representation of a SemVer version string
*
* This is a bit less forgiving than node-semver, in that prerelease versions
* MUST start with '-'. Otherwise, the allowed syntax is identical.
*/
export declare class Version {
/** raw string provided to create this Version */
raw: string;
/** major version number */
major: number;
/** minor version number */
minor: number;
/** patch version number */
patch: number;
/**
* List of `'.'`-separated strings and numbers indicating that this
* version is a prerelease.
*
* This is undefined if the version does not have a prerelease section.
*/
prerelease?: (number | string)[];
/**
* List of `'.'`-separated strings in the `build` section.
*
* This is undefined if the version does not have a build.
*/
build?: string[];
/** Canonical strict form of this version */
toString(): string;
/** Generate a `Version` object from a SemVer string */
static parse(version: string): Version;
constructor(version: string, major: number, minor: number, patch: number, prerelease: string | undefined, build: string | undefined);
/**
* Return 1 if this is > the provided version, -1 if we're less, or 0 if
* they are equal.
*
* No special handling for prerelease versions, this is just a precedence
* comparison.
*
* This can be used to sort a list of versions by precedence:
*
* ```ts
* const versions: Version[] = getVersionsSomehow()
* const sorted = versions.sort((a, b) => a.compare(b))
* ```
*/
compare(v: Version): -1 | 0 | 1;
/**
* The inverse of compare, for sorting version lists in reverse order
*/
rcompare(v: Version): number;
/** true if this version is > the argument */
greaterThan(v: Version): boolean;
/** true if this version is >= the argument */
greaterThanEqual(v: Version): boolean;
/** true if this version is < the argument */
lessThan(v: Version): boolean;
/** true if this version is &lt;= the argument */
lessThanEqual(v: Version): boolean;
/** true if these two versions have equal SemVer precedence */
equals(v: Version): boolean;
/** just compare the M.m.p parts of the version */
tupleEquals(v: Version): boolean;
/** true if this version satisfies the range */
satisfies(r: Range): boolean;
/**
* Increment the version in place, in the manner specified.
*
* Part behaviors:
*
* - `'major'` If the version is a `M.0.0-...` version with a prerelease, then
* simply drop the prerelease. Otherwise, set the minor and patch to 0, and
* increment the major. So `1.0.0-beta` becomes `1.0.0`, and `1.2.3` becomes
* `2.0.0`
*
* - `'minor'` If the version is a `M.m.0-...` version with a prerelease, then
* simply drop the prerelease. Otherwise, set the patch to 0, and increment the
* minor. So `1.2.0-beta` becomes `1.2.0`, and `1.2.3` becomes `1.3.0`.
*
* - `'patch'` If the version has a prerelease, then simply drop the
* prerelease. Otherwise, increment the patch value. So `1.2.3-beta` becomes
* `1.2.3` and `1.2.3` becomes `1.2.4`.
*
* - `'premajor'` Set the patch and minor versions to `0`, increment the major
* version, and add a prerelease, using the optional identifier.
*
* - `'preminor'` Set the patch version to `0`, increment the minor version,
* and add a prerelease, using the optional identifier.
*
* - `'prepatch'` If a prerelease is already present, increment the patch
* version, otherwise leave it untouched, and add a prerelease, using the
* optional identifier.
*
* - `'prerelease'` If a prerelease version is present, then behave the same as
* `'prepatch'`. Otherwise, add a prerelease, using the optional identifier.
*
* - `'pre'` This is mostly for use by the other prerelease incrementers.
*
* - If a prerelease identifier is provided:
*
* Update that named portion of the prerelease. For example,
* `inc('1.2.3-beta.4', 'pre', 'beta')` would result in `1.2.3-beta.5`.
*
* If there is no prerelease identifier by that name, then replace the
* prerelease with `[name]`. So `inc('1.2.3-alpha.4', 'pre', 'beta')`
* would result in `1.2.3-beta`.
*
* If the prerelease identifer is present, but has no numeric value
* following it, then add `0`. So `inc('1.2.3-beta', 'pre', 'beta')`
* would result in `1.2.3-beta.0`.
*
* - If no prerelease identifier is provided:
*
* If there is no current prerelease, then set the prerelease to `0`. So,
* `inc('1.2.3', 'pre')` becomes `1.2.3-0`.
*
* If the last item in the prerelease is numeric, then increment it. So,
* `inc('1.2.3-beta.3', 'pre')` becomes `1.2.3-beta.4`.
*/
inc(part: IncrementType, prereleaseIdentifier?: string): this;
}
//# sourceMappingURL=version.d.ts.map
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AA2CvC;;GAEG;AACH,eAAO,MAAM,iBAAiB,+FASpB,CAAA;AAEV;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAA;AAE9D;;;;;GAKG;AACH,qBAAa,OAAO;IAClB,iDAAiD;IACjD,GAAG,EAAE,MAAM,CAAA;IAEX,4BAA4B;IAC5B,KAAK,EAAE,MAAM,CAAA;IACb,2BAA2B;IAC3B,KAAK,EAAE,MAAM,CAAA;IACb,2BAA2B;IAC3B,KAAK,EAAE,MAAM,CAAA;IACb;;;;;OAKG;IACH,UAAU,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAA;IAChC;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;IAEhB,4CAA4C;IAC5C,QAAQ;IAMR,uDAAuD;IACvD,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,MAAM;gBA2C1B,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,MAAM,GAAG,SAAS,EAC9B,KAAK,EAAE,MAAM,GAAG,SAAS;IA+B3B;;;;;;;;;;;;;OAaG;IACH,OAAO,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC;IAiC/B;;OAEG;IACH,QAAQ,CAAC,CAAC,EAAE,OAAO;IAInB,6CAA6C;IAC7C,WAAW,CAAC,CAAC,EAAE,OAAO;IAItB,8CAA8C;IAC9C,gBAAgB,CAAC,CAAC,EAAE,OAAO;IAI3B,6CAA6C;IAC7C,QAAQ,CAAC,CAAC,EAAE,OAAO;IAInB,iDAAiD;IACjD,aAAa,CAAC,CAAC,EAAE,OAAO;IAIxB,8DAA8D;IAC9D,MAAM,CAAC,CAAC,EAAE,OAAO;IAIjB,kDAAkD;IAClD,WAAW,CAAC,CAAC,EAAE,OAAO;IAQtB,+CAA+C;IAC/C,SAAS,CAAC,CAAC,EAAE,KAAK;IAIlB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAqDG;IACH,GAAG,CAAC,IAAI,EAAE,aAAa,EAAE,oBAAoB,CAAC,EAAE,MAAM;CAiHvD"}
import { syntaxError, typeError } from '@vltpkg/error-cause';
import { fastSplit } from '@vltpkg/fast-split';
const maybeNumber = (s) => {
if (!/^[0-9]+$/.test(s))
return s;
const n = Number(s);
return n <= Number.MAX_SAFE_INTEGER ? n : s;
};
const safeNumber = (s, version, field) => {
const n = Number(s);
if (n > Number.MAX_SAFE_INTEGER) {
throw invalidVersion(version, `invalid ${field}, must be <= ${Number.MAX_SAFE_INTEGER}`);
}
return n;
};
const re = {
prefix: /^[ v=]+/,
main: /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)/,
prerelease: /-([0-9a-zA-Z_.-]+)(?:$|\+)/,
build: /\+([0-9a-zA-Z_.-]+)$/,
full: /^[ v=]*(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9a-zA-Z_.-]+))?(?:\+([0-9a-zA-Z_.-]+))?$/,
};
const invalidVersion = (version, message) => {
const er = syntaxError(`invalid version: ${message}`, { version }, Version);
return er;
};
/**
* Values of valid increment types.
*/
export const versionIncrements = [
'major',
'minor',
'patch',
'pre',
'premajor',
'preminor',
'prepatch',
'prerelease',
];
/**
* A parsed object representation of a SemVer version string
*
* This is a bit less forgiving than node-semver, in that prerelease versions
* MUST start with '-'. Otherwise, the allowed syntax is identical.
*/
export class Version {
/** raw string provided to create this Version */
raw;
/** major version number */
major;
/** minor version number */
minor;
/** patch version number */
patch;
/**
* List of `'.'`-separated strings and numbers indicating that this
* version is a prerelease.
*
* This is undefined if the version does not have a prerelease section.
*/
prerelease;
/**
* List of `'.'`-separated strings in the `build` section.
*
* This is undefined if the version does not have a build.
*/
build;
/** Canonical strict form of this version */
toString() {
return `${this.major}.${this.minor}.${this.patch}${this.prerelease ? '-' + this.prerelease.join('.') : ''}${this.build ? '+' + this.build.join('.') : ''}`;
}
/** Generate a `Version` object from a SemVer string */
static parse(version) {
version = version.replace(re.prefix, '').trim();
if (version.length > 256) {
throw invalidVersion(version, 'must be less than 256 characters');
}
const parsed = re.full.exec(version);
if (!parsed) {
const main = re.main.exec(version);
if (!main) {
throw invalidVersion(version, 'no Major.minor.patch tuple present');
}
else {
throw invalidVersion(version, 'invalid build or patch section');
}
}
const [_, major_, minor_, patch_, prerelease, build] = parsed;
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const major = safeNumber(major_, version, 'major');
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const minor = safeNumber(minor_, version, 'minor');
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const patch = safeNumber(patch_, version, 'patch');
return new Version(version, major, minor, patch, prerelease, build);
}
constructor(version, major, minor, patch, prerelease, build) {
this.raw = version;
this.major = major;
this.minor = minor;
this.patch = patch;
// has prerelease and/or build
if (prerelease) {
this.prerelease = fastSplit(prerelease, '.', -1, c => {
if (!c) {
throw invalidVersion(version, 'invalid prerelease, empty identifiers not allowed');
}
return maybeNumber(c);
});
}
if (build) {
this.build = fastSplit(build, '.', -1, c => {
if (!c) {
throw invalidVersion(version, 'invalid build metadata, empty identifiers not allowed');
}
});
}
}
/**
* Return 1 if this is > the provided version, -1 if we're less, or 0 if
* they are equal.
*
* No special handling for prerelease versions, this is just a precedence
* comparison.
*
* This can be used to sort a list of versions by precedence:
*
* ```ts
* const versions: Version[] = getVersionsSomehow()
* const sorted = versions.sort((a, b) => a.compare(b))
* ```
*/
compare(v) {
if (this.major > v.major)
return 1;
if (this.major < v.major)
return -1;
if (this.minor > v.minor)
return 1;
if (this.minor < v.minor)
return -1;
if (this.patch > v.patch)
return 1;
if (this.patch < v.patch)
return -1;
// main tuple is equal now
// if the version has no pr, we're definitely less than or equal to
if (!v.prerelease?.length)
return !this.prerelease?.length ? 0 : -1;
// v has a pr. if we don't, we're > it
if (!this.prerelease?.length)
return 1;
// we both have prereleases
const len = Math.max(this.prerelease.length, v.prerelease.length);
const me = this.prerelease;
const thee = v.prerelease;
for (let i = 0; i < len; i++) {
const m = me[i];
const t = thee[i];
if (m === t)
continue;
// having a field is > not having it
if (t === undefined)
return 1;
if (m === undefined)
return -1;
// string parts are higher precedence than
if (typeof m !== typeof t) {
return typeof m === 'string' ? 1 : -1;
}
return m > t ? 1 : -1;
}
return 0;
}
/**
* The inverse of compare, for sorting version lists in reverse order
*/
rcompare(v) {
return -1 * this.compare(v);
}
/** true if this version is > the argument */
greaterThan(v) {
return this.compare(v) === 1;
}
/** true if this version is >= the argument */
greaterThanEqual(v) {
return this.compare(v) > -1;
}
/** true if this version is < the argument */
lessThan(v) {
return this.compare(v) === -1;
}
/** true if this version is &lt;= the argument */
lessThanEqual(v) {
return this.compare(v) < 1;
}
/** true if these two versions have equal SemVer precedence */
equals(v) {
return this.compare(v) === 0;
}
/** just compare the M.m.p parts of the version */
tupleEquals(v) {
return (this.major === v.major &&
this.minor === v.minor &&
this.patch === v.patch);
}
/** true if this version satisfies the range */
satisfies(r) {
return r.test(this);
}
/**
* Increment the version in place, in the manner specified.
*
* Part behaviors:
*
* - `'major'` If the version is a `M.0.0-...` version with a prerelease, then
* simply drop the prerelease. Otherwise, set the minor and patch to 0, and
* increment the major. So `1.0.0-beta` becomes `1.0.0`, and `1.2.3` becomes
* `2.0.0`
*
* - `'minor'` If the version is a `M.m.0-...` version with a prerelease, then
* simply drop the prerelease. Otherwise, set the patch to 0, and increment the
* minor. So `1.2.0-beta` becomes `1.2.0`, and `1.2.3` becomes `1.3.0`.
*
* - `'patch'` If the version has a prerelease, then simply drop the
* prerelease. Otherwise, increment the patch value. So `1.2.3-beta` becomes
* `1.2.3` and `1.2.3` becomes `1.2.4`.
*
* - `'premajor'` Set the patch and minor versions to `0`, increment the major
* version, and add a prerelease, using the optional identifier.
*
* - `'preminor'` Set the patch version to `0`, increment the minor version,
* and add a prerelease, using the optional identifier.
*
* - `'prepatch'` If a prerelease is already present, increment the patch
* version, otherwise leave it untouched, and add a prerelease, using the
* optional identifier.
*
* - `'prerelease'` If a prerelease version is present, then behave the same as
* `'prepatch'`. Otherwise, add a prerelease, using the optional identifier.
*
* - `'pre'` This is mostly for use by the other prerelease incrementers.
*
* - If a prerelease identifier is provided:
*
* Update that named portion of the prerelease. For example,
* `inc('1.2.3-beta.4', 'pre', 'beta')` would result in `1.2.3-beta.5`.
*
* If there is no prerelease identifier by that name, then replace the
* prerelease with `[name]`. So `inc('1.2.3-alpha.4', 'pre', 'beta')`
* would result in `1.2.3-beta`.
*
* If the prerelease identifer is present, but has no numeric value
* following it, then add `0`. So `inc('1.2.3-beta', 'pre', 'beta')`
* would result in `1.2.3-beta.0`.
*
* - If no prerelease identifier is provided:
*
* If there is no current prerelease, then set the prerelease to `0`. So,
* `inc('1.2.3', 'pre')` becomes `1.2.3-0`.
*
* If the last item in the prerelease is numeric, then increment it. So,
* `inc('1.2.3-beta.3', 'pre')` becomes `1.2.3-beta.4`.
*/
inc(part, prereleaseIdentifier) {
switch (part) {
case 'premajor':
this.prerelease = undefined;
this.patch = 0;
this.minor = 0;
this.major++;
this.inc('pre', prereleaseIdentifier);
break;
case 'preminor':
this.prerelease = undefined;
this.patch = 0;
this.minor++;
this.inc('pre', prereleaseIdentifier);
break;
case 'prepatch':
this.prerelease = undefined;
this.inc('patch');
this.inc('pre', prereleaseIdentifier);
break;
case 'prerelease':
if (!this.prerelease?.length)
this.inc('patch', prereleaseIdentifier);
this.inc('pre', prereleaseIdentifier);
break;
case 'pre': {
// this is a bit different than node-semver's logic, but simpler
// always do zero-based incrementing, and either bump the existing
// numeric pr value, or add a `.0` after the identifier.
if (!prereleaseIdentifier) {
if (!this.prerelease?.length) {
this.prerelease = [0];
break;
}
const last = this.prerelease[this.prerelease.length - 1];
if (typeof last === 'number') {
this.prerelease[this.prerelease.length - 1] = last + 1;
}
else {
this.prerelease.push(0);
}
break;
}
if (!this.prerelease?.length) {
this.prerelease = [prereleaseIdentifier];
break;
}
const i = this.prerelease.indexOf(maybeNumber(prereleaseIdentifier));
if (i === -1) {
this.prerelease = [prereleaseIdentifier];
break;
}
const baseValue = this.prerelease[i + 1];
if (typeof baseValue === 'number') {
this.prerelease[i + 1] = baseValue + 1;
break;
}
if (i === this.prerelease.length - 1) {
this.prerelease.push(0);
break;
}
this.prerelease.splice(i + 1, 0, 0);
break;
}
case 'major':
if (!this.prerelease?.length || this.minor || this.patch)
this.major++;
this.prerelease = undefined;
this.patch = 0;
this.minor = 0;
break;
case 'minor':
if (!this.prerelease?.length || this.patch)
this.minor++;
this.prerelease = undefined;
this.patch = 0;
break;
case 'patch':
if (!this.prerelease?.length)
this.patch++;
this.prerelease = undefined;
break;
default:
throw typeError('Invalid increment identifier', {
version: this,
found: part,
validOptions: [
'major',
'minor',
'patch',
'premajor',
'preminor',
'prepatch',
'prerelease',
'pre',
],
}, this.inc);
}
this.raw = this.toString();
return this;
}
}
//# sourceMappingURL=version.js.map
{"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version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M;oBAAE,IAAI,CAAC,KAAK,EAAE,CAAA;gBAC1C,IAAI,CAAC,UAAU,GAAG,SAAS,CAAA;gBAC3B,MAAK;YAEP;gBACE,MAAM,SAAS,CACb,8BAA8B,EAC9B;oBACE,OAAO,EAAE,IAAI;oBACb,KAAK,EAAE,IAAI;oBACX,YAAY,EAAE;wBACZ,OAAO;wBACP,OAAO;wBACP,OAAO;wBACP,UAAU;wBACV,UAAU;wBACV,UAAU;wBACV,YAAY;wBACZ,KAAK;qBACN;iBACF,EACD,IAAI,CAAC,GAAG,CACT,CAAA;QACL,CAAC;QAED,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAA;QAC1B,OAAO,IAAI,CAAA;IACb,CAAC;CACF","sourcesContent":["import { syntaxError, typeError } from '@vltpkg/error-cause'\nimport { fastSplit } from '@vltpkg/fast-split'\nimport type { Range } from './range.ts'\n\nconst maybeNumber = (s: string): number | string => {\n if (!/^[0-9]+$/.test(s)) return s\n const n = Number(s)\n return n <= Number.MAX_SAFE_INTEGER ? n : s\n}\n\nconst safeNumber = (\n s: string,\n version: string,\n field: string,\n): number => {\n const n = Number(s)\n if (n > Number.MAX_SAFE_INTEGER) {\n throw invalidVersion(\n version,\n `invalid ${field}, must be <= ${Number.MAX_SAFE_INTEGER}`,\n )\n }\n return n\n}\n\nconst re = {\n prefix: /^[ v=]+/,\n main: /^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)/,\n prerelease: /-([0-9a-zA-Z_.-]+)(?:$|\\+)/,\n build: /\\+([0-9a-zA-Z_.-]+)$/,\n full: /^[ v=]*(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-([0-9a-zA-Z_.-]+))?(?:\\+([0-9a-zA-Z_.-]+))?$/,\n} as const\n\nconst invalidVersion = (\n version: string,\n message: string,\n): SyntaxError => {\n const er = syntaxError(\n `invalid version: ${message}`,\n { version },\n Version,\n )\n return er\n}\n\n/**\n * Values of valid increment types.\n */\nexport const versionIncrements = [\n 'major',\n 'minor',\n 'patch',\n 'pre',\n 'premajor',\n 'preminor',\n 'prepatch',\n 'prerelease',\n] as const\n\n/**\n * Types of incrementing supported by {@link Version#inc}\n */\nexport type IncrementType = (typeof versionIncrements)[number]\n\n/**\n * A parsed object representation of a SemVer version string\n *\n * This is a bit less forgiving than node-semver, in that prerelease versions\n * MUST start with '-'. Otherwise, the allowed syntax is identical.\n */\nexport class Version {\n /** raw string provided to create this Version */\n raw: string\n\n /** major version number */\n major: number\n /** minor version number */\n minor: number\n /** patch version number */\n patch: number\n /**\n * List of `'.'`-separated strings and numbers indicating that this\n * version is a prerelease.\n *\n * This is undefined if the version does not have a prerelease section.\n */\n prerelease?: (number | string)[]\n /**\n * List of `'.'`-separated strings in the `build` section.\n *\n * This is undefined if the version does not have a build.\n */\n build?: string[]\n\n /** Canonical strict form of this version */\n toString() {\n return `${this.major}.${this.minor}.${this.patch}${\n this.prerelease ? '-' + this.prerelease.join('.') : ''\n }${this.build ? '+' + this.build.join('.') : ''}`\n }\n\n /** Generate a `Version` object from a SemVer string */\n static parse(version: string) {\n version = version.replace(re.prefix, '').trim()\n if (version.length > 256) {\n throw invalidVersion(\n version,\n 'must be less than 256 characters',\n )\n }\n\n const parsed = re.full.exec(version)\n if (!parsed) {\n const main = re.main.exec(version)\n if (!main) {\n throw invalidVersion(\n version,\n 'no Major.minor.patch tuple present',\n )\n } else {\n throw invalidVersion(\n version,\n 'invalid build or patch section',\n )\n }\n }\n const [_, major_, minor_, patch_, prerelease, build] = parsed\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const major = safeNumber(major_!, version, 'major')\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const minor = safeNumber(minor_!, version, 'minor')\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const patch = safeNumber(patch_!, version, 'patch')\n\n return new Version(\n version,\n major,\n minor,\n patch,\n prerelease,\n build,\n )\n }\n\n constructor(\n version: string,\n major: number,\n minor: number,\n patch: number,\n prerelease: string | undefined,\n build: string | undefined,\n ) {\n this.raw = version\n this.major = major\n this.minor = minor\n this.patch = patch\n\n // has prerelease and/or build\n if (prerelease) {\n this.prerelease = fastSplit(prerelease, '.', -1, c => {\n if (!c) {\n throw invalidVersion(\n version,\n 'invalid prerelease, empty identifiers not allowed',\n )\n }\n return maybeNumber(c)\n })\n }\n if (build) {\n this.build = fastSplit(build, '.', -1, c => {\n if (!c) {\n throw invalidVersion(\n version,\n 'invalid build metadata, empty identifiers not allowed',\n )\n }\n })\n }\n }\n\n /**\n * Return 1 if this is > the provided version, -1 if we're less, or 0 if\n * they are equal.\n *\n * No special handling for prerelease versions, this is just a precedence\n * comparison.\n *\n * This can be used to sort a list of versions by precedence:\n *\n * ```ts\n * const versions: Version[] = getVersionsSomehow()\n * const sorted = versions.sort((a, b) => a.compare(b))\n * ```\n */\n compare(v: Version): -1 | 0 | 1 {\n if (this.major > v.major) return 1\n if (this.major < v.major) return -1\n if (this.minor > v.minor) return 1\n if (this.minor < v.minor) return -1\n if (this.patch > v.patch) return 1\n if (this.patch < v.patch) return -1\n // main tuple is equal now\n // if the version has no pr, we're definitely less than or equal to\n if (!v.prerelease?.length)\n return !this.prerelease?.length ? 0 : -1\n // v has a pr. if we don't, we're > it\n if (!this.prerelease?.length) return 1\n // we both have prereleases\n const len = Math.max(this.prerelease.length, v.prerelease.length)\n const me = this.prerelease\n const thee = v.prerelease\n for (let i = 0; i < len; i++) {\n const m = me[i]\n const t = thee[i]\n if (m === t) continue\n // having a field is > not having it\n if (t === undefined) return 1\n if (m === undefined) return -1\n // string parts are higher precedence than\n if (typeof m !== typeof t) {\n return typeof m === 'string' ? 1 : -1\n }\n return m > t ? 1 : -1\n }\n return 0\n }\n\n /**\n * The inverse of compare, for sorting version lists in reverse order\n */\n rcompare(v: Version) {\n return -1 * this.compare(v)\n }\n\n /** true if this version is > the argument */\n greaterThan(v: Version) {\n return this.compare(v) === 1\n }\n\n /** true if this version is >= the argument */\n greaterThanEqual(v: Version) {\n return this.compare(v) > -1\n }\n\n /** true if this version is < the argument */\n lessThan(v: Version) {\n return this.compare(v) === -1\n }\n\n /** true if this version is &lt;= the argument */\n lessThanEqual(v: Version) {\n return this.compare(v) < 1\n }\n\n /** true if these two versions have equal SemVer precedence */\n equals(v: Version) {\n return this.compare(v) === 0\n }\n\n /** just compare the M.m.p parts of the version */\n tupleEquals(v: Version) {\n return (\n this.major === v.major &&\n this.minor === v.minor &&\n this.patch === v.patch\n )\n }\n\n /** true if this version satisfies the range */\n satisfies(r: Range) {\n return r.test(this)\n }\n\n /**\n * Increment the version in place, in the manner specified.\n *\n * Part behaviors:\n *\n * - `'major'` If the version is a `M.0.0-...` version with a prerelease, then\n * simply drop the prerelease. Otherwise, set the minor and patch to 0, and\n * increment the major. So `1.0.0-beta` becomes `1.0.0`, and `1.2.3` becomes\n * `2.0.0`\n *\n * - `'minor'` If the version is a `M.m.0-...` version with a prerelease, then\n * simply drop the prerelease. Otherwise, set the patch to 0, and increment the\n * minor. So `1.2.0-beta` becomes `1.2.0`, and `1.2.3` becomes `1.3.0`.\n *\n * - `'patch'` If the version has a prerelease, then simply drop the\n * prerelease. Otherwise, increment the patch value. So `1.2.3-beta` becomes\n * `1.2.3` and `1.2.3` becomes `1.2.4`.\n *\n * - `'premajor'` Set the patch and minor versions to `0`, increment the major\n * version, and add a prerelease, using the optional identifier.\n *\n * - `'preminor'` Set the patch version to `0`, increment the minor version,\n * and add a prerelease, using the optional identifier.\n *\n * - `'prepatch'` If a prerelease is already present, increment the patch\n * version, otherwise leave it untouched, and add a prerelease, using the\n * optional identifier.\n *\n * - `'prerelease'` If a prerelease version is present, then behave the same as\n * `'prepatch'`. Otherwise, add a prerelease, using the optional identifier.\n *\n * - `'pre'` This is mostly for use by the other prerelease incrementers.\n *\n * - If a prerelease identifier is provided:\n *\n * Update that named portion of the prerelease. For example,\n * `inc('1.2.3-beta.4', 'pre', 'beta')` would result in `1.2.3-beta.5`.\n *\n * If there is no prerelease identifier by that name, then replace the\n * prerelease with `[name]`. So `inc('1.2.3-alpha.4', 'pre', 'beta')`\n * would result in `1.2.3-beta`.\n *\n * If the prerelease identifer is present, but has no numeric value\n * following it, then add `0`. So `inc('1.2.3-beta', 'pre', 'beta')`\n * would result in `1.2.3-beta.0`.\n *\n * - If no prerelease identifier is provided:\n *\n * If there is no current prerelease, then set the prerelease to `0`. So,\n * `inc('1.2.3', 'pre')` becomes `1.2.3-0`.\n *\n * If the last item in the prerelease is numeric, then increment it. So,\n * `inc('1.2.3-beta.3', 'pre')` becomes `1.2.3-beta.4`.\n */\n inc(part: IncrementType, prereleaseIdentifier?: string) {\n switch (part) {\n case 'premajor':\n this.prerelease = undefined\n this.patch = 0\n this.minor = 0\n this.major++\n this.inc('pre', prereleaseIdentifier)\n break\n\n case 'preminor':\n this.prerelease = undefined\n this.patch = 0\n this.minor++\n this.inc('pre', prereleaseIdentifier)\n break\n\n case 'prepatch':\n this.prerelease = undefined\n this.inc('patch')\n this.inc('pre', prereleaseIdentifier)\n break\n\n case 'prerelease':\n if (!this.prerelease?.length)\n this.inc('patch', prereleaseIdentifier)\n this.inc('pre', prereleaseIdentifier)\n break\n\n case 'pre': {\n // this is a bit different than node-semver's logic, but simpler\n // always do zero-based incrementing, and either bump the existing\n // numeric pr value, or add a `.0` after the identifier.\n if (!prereleaseIdentifier) {\n if (!this.prerelease?.length) {\n this.prerelease = [0]\n break\n }\n const last = this.prerelease[this.prerelease.length - 1]\n if (typeof last === 'number') {\n this.prerelease[this.prerelease.length - 1] = last + 1\n } else {\n this.prerelease.push(0)\n }\n break\n }\n if (!this.prerelease?.length) {\n this.prerelease = [prereleaseIdentifier]\n break\n }\n const i = this.prerelease.indexOf(\n maybeNumber(prereleaseIdentifier),\n )\n if (i === -1) {\n this.prerelease = [prereleaseIdentifier]\n break\n }\n const baseValue = this.prerelease[i + 1]\n if (typeof baseValue === 'number') {\n this.prerelease[i + 1] = baseValue + 1\n break\n }\n if (i === this.prerelease.length - 1) {\n this.prerelease.push(0)\n break\n }\n this.prerelease.splice(i + 1, 0, 0)\n break\n }\n\n case 'major':\n if (!this.prerelease?.length || this.minor || this.patch)\n this.major++\n this.prerelease = undefined\n this.patch = 0\n this.minor = 0\n break\n\n case 'minor':\n if (!this.prerelease?.length || this.patch) this.minor++\n this.prerelease = undefined\n this.patch = 0\n break\n\n case 'patch':\n if (!this.prerelease?.length) this.patch++\n this.prerelease = undefined\n break\n\n default:\n throw typeError(\n 'Invalid increment identifier',\n {\n version: this,\n found: part,\n validOptions: [\n 'major',\n 'minor',\n 'patch',\n 'premajor',\n 'preminor',\n 'prepatch',\n 'prerelease',\n 'pre',\n ],\n },\n this.inc,\n )\n }\n\n this.raw = this.toString()\n return this\n }\n}\n"]}
+6
-20
{
"name": "@vltpkg/semver",
"description": "The semantic version parser used by vlt",
"version": "1.0.0-rc.10",
"version": "1.0.0-rc.11",
"repository": {

@@ -11,17 +11,6 @@ "type": "git",

"author": "vlt technology inc. <support@vlt.sh> (http://vlt.sh)",
"tshy": {
"selfLink": false,
"liveDev": true,
"dialects": [
"esm"
],
"exports": {
"./package.json": "./package.json",
".": "./src/index.ts"
}
},
"dependencies": {
"@vltpkg/fast-split": "1.0.0-rc.10",
"@vltpkg/error-cause": "1.0.0-rc.10",
"@vltpkg/types": "1.0.0-rc.10"
"@vltpkg/types": "1.0.0-rc.11",
"@vltpkg/fast-split": "1.0.0-rc.11",
"@vltpkg/error-cause": "1.0.0-rc.11"
},

@@ -37,3 +26,2 @@ "devDependencies": {

"tap": "^21.5.0",
"tshy": "^3.1.0",
"typedoc": "~0.27.9",

@@ -51,3 +39,3 @@ "typescript": "5.7.3",

"prettier": "../../.prettierrc.js",
"module": "./dist/esm/index.js",
"module": "./dist/index.js",
"type": "module",

@@ -58,4 +46,3 @@ "exports": {

"import": {
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.js"
"default": "./dist/index.js"
}

@@ -79,5 +66,4 @@ }

"posttest": "tsc --noEmit",
"tshy": "tshy",
"typecheck": "tsc --noEmit"
}
}
import { Version } from './version.ts';
/** all comparators are expressed in terms of these operators */
export type SimpleOperator = '' | '<' | '<=' | '>' | '>=';
/** operators that are expanded to simpler forms */
export type ComplexOperator = '^' | '~' | '~>';
/** comparator expressed as a [operator,version] tuple */
export type OVTuple = [SimpleOperator, Version];
/**
* The result of parsing a version value that might be either a full
* version like `1.2.3` or an X-Range like `1.2.x`
*/
export type ParsedXRange = ParsedXMajor | ParsedXMinor | ParsedXPatch | ParsedXVersion;
/**
* a {@link ParsedXRange} that is just a `*`
*/
export type ParsedXMajor = [];
/**
* a {@link ParsedXRange} that is just a major version
*/
export type ParsedXMinor = [number];
/**
* a {@link ParsedXRange} that is just a major and minor version
*/
export type ParsedXPatch = [number, number];
/**
* a {@link ParsedXRange} that is a full version
*/
export type ParsedXVersion = [
M: number,
m: number,
p: number,
pr?: string | undefined,
b?: string | undefined
];
/**
* Class used to parse the `||` separated portions
* of a range, and evaluate versions against it.
*
* This does most of the heavy lifting of range testing, and provides
* little affordance for improperly formatted strings. It should be
* considered an internal class, and usually not accessed directly.
*/
export declare class Comparator {
#private;
/**
* does this range include prereleases, even when they do not
* match the tuple in the comparator?
*/
includePrerelease: boolean;
/** raw string used to create this comparator */
raw: string;
/** tokens extracted from the raw string input */
tokens: string[];
/**
* Either the `any` comparator, the `none` comparator, or an operator
* and a {@link ParsedXRange}
*/
tuples: (Comparator | OVTuple)[];
/** true if this comparator can not match anything */
isNone: boolean;
/**
* true if this comparator is a `'*'` type of range.
*
* Note that it still will not match versions with a prerelease value,
* unless the tuple in the version matches the tuple provided to the
* comparator, and the comparator version also has a prerelease value,
* unless `includePrerelease` is set.
*/
isAny: boolean;
/** the canonical strict simplified parsed form of this constructor */
toString(): string;
constructor(comp: string, includePrerelease?: boolean);
/** return true if the version is a match for this comparator */
test(v: Version): boolean;
}
//# sourceMappingURL=comparator.d.ts.map
{"version":3,"file":"comparator.d.ts","sour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M,EAAE,iBAAiB,UAAQ;IAwdnD,gEAAgE;IAChE,IAAI,CAAC,CAAC,EAAE,OAAO;CAqChB"}
// TODO: it might be faster to not have Version objects in the
// comparator tuples, and instead just keep the parsed number arrays?
import { syntaxError } from '@vltpkg/error-cause';
import { fastSplit } from '@vltpkg/fast-split';
import { Version } from "./version.js";
const isOperator = (o) => !!o &&
(o === '>' ||
o === '<' ||
o === '>=' ||
o === '<=' ||
o === '' ||
o === '~' ||
o === '^' ||
o === '~>');
const preJunk = new Set('=v \t');
const invalidComp = (c, message) => syntaxError(`invalid comparator: '${c}' ${message}`, { found: c }, Comparator);
const assertNumber = (value, c, field) => {
const n = Number(value);
if (n !== n) {
throw invalidComp(c, `${field} must be numeric or 'x', got: '${value}'`);
}
return n;
};
const assertVersion = (v, comp) => {
if (!v) {
throw invalidComp(comp, 'no value provided for operator');
}
};
const assertMissing = (value, c, field) => {
if (value && !isX(value)) {
throw invalidComp(c, `cannot omit '${field}' and include subsequent fields`);
}
};
const MAJOR = 0;
const MINOR = 1;
const PATCH = 2;
const isX = (c) => !c || c === 'X' || c === 'x' || c === '*';
const isFullVersion = (parsed) => undefined !== parsed[PATCH];
const isXPatch = (parsed) => undefined !== parsed[MINOR] && undefined === parsed[PATCH];
const isXMinor = (parsed) => undefined !== parsed[MAJOR] && undefined === parsed[MINOR];
const isXMajor = (parsed) => undefined === parsed[MAJOR];
/**
* Class used to parse the `||` separated portions
* of a range, and evaluate versions against it.
*
* This does most of the heavy lifting of range testing, and provides
* little affordance for improperly formatted strings. It should be
* considered an internal class, and usually not accessed directly.
*/
export class Comparator {
/**
* does this range include prereleases, even when they do not
* match the tuple in the comparator?
*/
includePrerelease;
/** raw string used to create this comparator */
raw;
/** tokens extracted from the raw string input */
tokens;
/**
* Either the `any` comparator, the `none` comparator, or an operator
* and a {@link ParsedXRange}
*/
tuples = [];
/** true if this comparator can not match anything */
isNone = false;
/**
* true if this comparator is a `'*'` type of range.
*
* Note that it still will not match versions with a prerelease value,
* unless the tuple in the version matches the tuple provided to the
* comparator, and the comparator version also has a prerelease value,
* unless `includePrerelease` is set.
*/
isAny = false;
/** the canonical strict simplified parsed form of this constructor */
toString() {
return (this.isNone ? '<0.0.0-0'
: this.isAny ? '*'
: /* c8 ignore next */
this.tuples.map(c => (isAny(c) ? '*' : c.join(''))).join(' '));
}
constructor(comp, includePrerelease = false) {
this.includePrerelease = includePrerelease;
comp = comp.trim();
this.raw = comp;
let hyphen = false;
const rawComps = fastSplit(comp, ' ', -1, (part, parts, i) => {
if (part === '-') {
if (hyphen) {
throw invalidComp(comp, 'multiple hyphen ranges not allowed');
}
if (parts.length !== 1 || i === -1) {
throw invalidComp(comp, 'hyphen must be between two versions');
}
hyphen = true;
}
else if (hyphen && parts.length !== 2) {
throw invalidComp(comp, 'hyphen range must be alone');
}
});
// remove excess spaces, `> 1 2` => `>1 2`
const comps = [];
let followingOperator = false;
let l = 0;
for (const c of rawComps) {
if (c === '')
continue;
if (!followingOperator) {
followingOperator = isOperator(c);
comps.push(c);
l++;
continue;
}
// we know this is not undefined since followingOperator guards that
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
comps[l - 1] += c;
followingOperator = false;
}
// TS mistakenly thinks hyphen is always false here
if (hyphen) {
const [min, _, max] = comps;
/* c8 ignore start - defense in depth for TS, already guaranteed */
if (!min || !max) {
throw invalidComp(comp, 'hyphen must be between two versions');
}
/* c8 ignore stop */
this.#parseHyphenRange(min, max);
}
else if (!comps.length ||
(comps.length === 1 && isX(comps[0]))) {
this.tuples.push(this.#getComparatorAny());
}
else {
for (const c of comps) {
this.#parse(c);
if (this.isNone)
break;
}
}
this.tokens = comps;
this.isAny = true;
for (const c of this.tuples) {
if (Array.isArray(c) || !c.isAny) {
this.isAny = false;
break;
}
}
}
// inclusive min
#xInclusiveMin(raw) {
const z = this.includePrerelease ? '0' : undefined;
const [M, m = 0, p = 0, pr = z, build] = this.#parseX(raw);
return M === undefined ?
this.#getComparatorAny()
: ['>=', new Version(raw, M, m, p, pr, build)];
}
// exclusive min
#xExclusiveMin(raw) {
const parsed = this.#parseX(raw);
if (isFullVersion(parsed)) {
return ['>', new Version(raw, ...parsed)];
}
const z = this.includePrerelease ? '0' : undefined;
if (isXPatch(parsed)) {
// >1.2 => >=1.3.0
return [
'>=',
new Version(raw, parsed[MAJOR], parsed[MINOR] + 1, 0, z, undefined),
];
}
if (isXMinor(parsed)) {
// >1 => >=2.0.0
return [
'>=',
new Version(raw, parsed[MAJOR] + 1, 0, 0, z, undefined),
];
}
this.isNone = true;
this.tuples.length = 0;
return comparatorNone;
}
#xInclusiveMax(raw) {
const parsed = this.#parseX(raw);
return (isFullVersion(parsed) ? ['<=', new Version(raw, ...parsed)]
: isXPatch(parsed) ?
[
'<',
new Version(raw, parsed[MAJOR], parsed[MINOR] + 1, 0, '0', undefined),
]
: isXMinor(parsed) ?
[
'<',
new Version(raw, parsed[MAJOR] + 1, 0, 0, '0', undefined),
]
: this.#getComparatorAny());
}
#xExclusiveMax(raw) {
const z = this.includePrerelease ? '0' : undefined;
const [M = 0, m = 0, p = 0, pr = z, build] = this.#parseX(raw);
if (M === 0 && m === 0 && p === 0 && pr === '0') {
this.isNone = true;
this.tuples.length = 0;
return comparatorNone;
}
return ['<', new Version(raw, M, m, p, pr, build)];
}
#validXM(raw, m, p) {
assertMissing(m, raw, 'major');
assertMissing(p, raw, 'major');
if (m === '' || p === '') {
throw invalidComp(raw, `(Did you mean '*'?)`);
}
return [];
}
#validXm(raw, M, m, p) {
assertMissing(p, raw, 'major');
if (m === '' || p === '') {
throw invalidComp(raw, `(Did you mean '${M}'?)`);
}
return [assertNumber(M, raw, 'major')];
}
#validXp(raw, M, m, p) {
if (p === '') {
throw invalidComp(raw, `(Did you mean '${M}.${m}'?)`);
}
return [
assertNumber(M, raw, 'major'),
assertNumber(m, raw, 'minor'),
];
}
#validTuple(raw, M, m, p) {
return [
assertNumber(M, raw, 'major'),
assertNumber(m, raw, 'minor'),
assertNumber(p, raw, 'patch'),
];
}
#validXbuild(raw, M, m, p, pl) {
// build, no prerelease
const patch = p.substring(0, pl);
const build = p.substring(pl + 1);
if (!patch) {
throw invalidComp(raw, 'cannot specify build without patch');
}
if (!build) {
throw invalidComp(raw, `encountered '+', but no build value`);
}
return [
assertNumber(M, raw, 'major'),
assertNumber(m, raw, 'minor'),
assertNumber(patch, raw, 'patch'),
undefined,
build,
];
}
#validXpr(raw, M, m, p, hy) {
{
// prerelease, no build
const patch = p.substring(0, hy);
const pr = p.substring(hy + 1);
if (!patch) {
throw invalidComp(raw, 'cannot specify prerelease without patch');
}
if (!pr) {
throw invalidComp(raw, `encountered '-', but no prerelease value`);
}
return [
assertNumber(M, raw, 'major'),
assertNumber(m, raw, 'minor'),
assertNumber(patch, raw, 'patch'),
pr,
undefined,
];
}
}
#validXprbuild(raw, M, m, p, hy, pl) {
// both prerelease and build
const patch = p.substring(0, hy);
const pr = p.substring(hy + 1, pl);
const build = p.substring(pl + 1);
if (!patch) {
throw invalidComp(raw, 'cannot specify prerelease without patch');
}
if (!pr) {
throw invalidComp(raw, `encountered '-', but no prerelease value`);
}
if (!build) {
throw invalidComp(raw, `encountered '+', but no build value`);
}
return [
assertNumber(M, raw, 'major'),
assertNumber(m, raw, 'minor'),
assertNumber(patch, raw, 'patch'),
pr,
build,
];
}
// pull the relevant values out of an X-range or version
// return the fields for creating a Version object.
// only call once operator is stripped off
#parseX(raw) {
let [M, m, p] = fastSplit(raw, '.', 3);
let prune = 0;
while (M && preJunk.has(M.charAt(prune)))
prune++;
if (M !== undefined && prune !== 0)
M = M.substring(prune);
// the `|| !M` is so TS knows we've handled undefined
if (!M || isX(M))
return this.#validXM(raw, m, p);
if (!m || isX(m))
return this.#validXm(raw, M, m, p);
if (!p || isX(p))
return this.#validXp(raw, M, m, p);
const hy = p.indexOf('-');
const pl = p.indexOf('+');
if (pl === -1 && hy === -1)
return this.#validTuple(raw, M, m, p);
if (pl === -1)
return this.#validXpr(raw, M, m, p, hy);
if (hy === -1)
return this.#validXbuild(raw, M, m, p, pl);
return this.#validXprbuild(raw, M, m, p, hy, pl);
}
#parseHyphenRange(min, max) {
const minv = this.#xInclusiveMin(min);
const maxv = this.#xInclusiveMax(max);
const minAny = isAny(minv);
const maxAny = isAny(maxv);
if (minAny && maxAny)
this.tuples.push(this.#getComparatorAny());
else if (minAny)
this.tuples.push(maxv);
else if (maxAny)
this.tuples.push(minv);
else
this.tuples.push(minv, maxv);
}
#parse(comp) {
const first = comp.charAt(0);
const first2 = comp.substring(0, 2);
const v1 = comp.substring(1);
const v2 = comp.substring(2);
switch (first2) {
case '~>':
assertVersion(v2, comp);
return this.#parseTilde(v2);
case '>=':
assertVersion(v2, comp);
return this.tuples.push(this.#xInclusiveMin(v2));
case '<=':
assertVersion(v2, comp);
return this.tuples.push(this.#xInclusiveMax(v2));
}
switch (first) {
case '~':
assertVersion(v1, comp);
return this.#parseTilde(v1);
case '^':
assertVersion(v1, comp);
return this.#parseCaret(v1);
case '>':
assertVersion(v1, comp);
return this.tuples.push(this.#xExclusiveMin(v1));
case '<':
assertVersion(v1, comp);
return this.tuples.push(this.#xExclusiveMax(v1));
}
return this.#parseEq(comp);
}
#parseTilde(comp) {
const parsed = this.#parseX(comp);
if (isXMajor(parsed)) {
this.tuples.push(this.#getComparatorAny());
return;
}
const z = this.includePrerelease ? '0' : undefined;
if (isXMinor(parsed)) {
const [M] = parsed;
this.tuples.push(['>=', new Version(comp, M, 0, 0, z, undefined)], ['<', new Version(comp, M + 1, 0, 0, '0', undefined)]);
return;
}
if (isXPatch(parsed)) {
const [M, m] = parsed;
const z = this.includePrerelease ? '0' : undefined;
this.tuples.push(['>=', new Version(comp, M, m, 0, z, undefined)], ['<', new Version(comp, M, m + 1, 0, '0', undefined)]);
return;
}
const [M, m, p, pr = z, build] = parsed;
this.tuples.push(['>=', new Version(comp, M, m, p, pr, build)], ['<', new Version(comp, M, m + 1, 0, '0', build)]);
}
#parseCaret(comp) {
const min = this.#xInclusiveMin(comp);
if (isAny(min)) {
this.tuples.push(min);
return;
}
const minv = min[1];
if (minv.major !== 0) {
this.tuples.push(min, [
'<',
new Version(comp, minv.major + 1, 0, 0, '0', undefined),
]);
}
else if (minv.minor !== 0) {
this.tuples.push(min, [
'<',
new Version(comp, minv.major, minv.minor + 1, 0, '0', undefined),
]);
}
else if (!minv.prerelease?.length) {
this.tuples.push(['', minv]);
}
else {
this.tuples.push(min, [
'<',
new Version(comp, minv.major, minv.minor, minv.patch + 1, '0', undefined),
]);
}
}
#parseEq(comp) {
const parsed = this.#parseX(comp);
const z = this.includePrerelease ? '0' : undefined;
if (isFullVersion(parsed)) {
this.tuples.push(['', new Version(comp, ...parsed)]);
}
else if (isXMajor(parsed)) {
this.tuples.push(this.#getComparatorAny());
}
else if (isXMinor(parsed)) {
this.tuples.push([
'>=',
new Version(comp, parsed[MAJOR], 0, 0, z, undefined),
]);
this.tuples.push([
'<',
new Version(comp, parsed[MAJOR] + 1, 0, 0, '0', undefined),
]);
}
else if (isXPatch(parsed)) {
this.tuples.push([
'>=',
new Version(comp, parsed[MAJOR], parsed[MINOR], 0, z, undefined),
], [
'<',
new Version(comp, parsed[MAJOR], parsed[MINOR] + 1, 0, '0', undefined),
]);
}
}
/** return true if the version is a match for this comparator */
test(v) {
if (this.isNone)
return false;
const ip = this.includePrerelease;
const hasPR = !!v.prerelease?.length;
let prOK = ip || !hasPR;
for (const c of this.tuples) {
if (isAny(c)) {
continue;
}
const [op, cv] = c;
prOK ||= !!cv.prerelease?.length && v.tupleEquals(cv);
switch (op) {
case '':
if (!v.equals(cv))
return false;
continue;
case '>':
if (!v.greaterThan(cv))
return false;
continue;
case '>=':
if (!v.greaterThanEqual(cv))
return false;
continue;
case '<':
if (!v.lessThan(cv))
return false;
continue;
case '<=':
if (!v.lessThanEqual(cv))
return false;
continue;
}
}
// they all passed, so it can only fail for having a prerelease
// if we allow prereleases, or saw a matching tuple, that's ok.
return prOK;
}
#getComparatorAny() {
return this.includePrerelease ? comparatorAnyPR : comparatorAny;
}
}
const isAny = (c) => c === comparatorAny || c === comparatorAnyPR;
const comparatorAny = {
isAny: true,
toString: () => '*',
includePrerelease: false,
test: (v) => !v.prerelease?.length,
};
const comparatorAnyPR = {
isAny: true,
toString: () => '*',
includePrerelease: true,
test: (_) => true,
};
const comparatorNone = {
isNone: true,
toString: () => '<0.0.0-0',
includePrerelease: false,
test: (_) => false,
};
//# sourceMappingURL=comparator.js.map
{"version":3,"file":"comparator.js","sourceRoot":"","sources":["../../src/comparator.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,qEAAqE;AACrE,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAOtC,MAAM,UAAU,GAAG,CACjB,CAAU,EAC6B,EAAE,CACzC,CAAC,CAAC,CAAC;IACH,CAAC,CAAC,KAAK,GAAG;QACR,CAAC,KAAK,GAAG;QACT,CAAC,KAAK,IAAI;QACV,CAAC,KAAK,IAAI;QACV,CAAC,KAAK,EAAE;QACR,CAAC,KAAK,GAAG;QACT,CAAC,KAAK,GAAG;QACT,CAAC,KAAK,IAAI,CAAC,CAAA;AAKf,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAA;AAEhC,MAAM,WAAW,GAAG,CAAC,CAAS,EAAE,OAAe,EAAe,EAAE,CAC9D,WAAW,CACT,wBAAwB,CAAC,KAAK,OAAO,EAAE,EACvC,EAAE,KAAK,EAAE,CAAC,EAAE,EACZ,UAAU,CACX,CAAA;AAEH,MAAM,YAAY,GAAG,CAAC,KAAa,EAAE,CAAS,EAAE,KAAa,EAAE,EAAE;IAC/D,MAAM,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAA;IACvB,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QACZ,MAAM,WAAW,CACf,CAAC,EACD,GAAG,KAAK,kCAAkC,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A;oBACzC,SAAQ;gBACV,KAAK,GAAG;oBACN,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC;wBAAE,OAAO,KAAK,CAAA;oBACjC,SAAQ;gBACV,KAAK,IAAI;oBACP,IAAI,CAAC,CAAC,CAAC,aAAa,CAAC,EAAE,CAAC;wBAAE,OAAO,KAAK,CAAA;oBACtC,SAAQ;YACZ,CAAC;QACH,CAAC;QACD,+DAA+D;QAC/D,+DAA+D;QAC/D,OAAO,IAAI,CAAA;IACb,CAAC;IAED,iBAAiB;QACf,OAAO,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,aAAa,CAAA;IACjE,CAAC;CACF;AAED,MAAM,KAAK,GAAG,CAAC,CAAuB,EAAmB,EAAE,CACzD,CAAC,KAAK,aAAa,IAAI,CAAC,KAAK,eAAe,CAAA;AAC9C,MAAM,aAAa,GAAG;IACpB,KAAK,EAAE,IAAI;IACX,QAAQ,EAAE,GAAG,EAAE,CAAC,GAAG;IACnB,iBAAiB,EAAE,KAAK;IACxB,IAAI,EAAE,CAAC,CAAU,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,UAAU,EAAE,MAAM;CAC9B,CAAA;AACf,MAAM,eAAe,GAAG;IACtB,KAAK,EAAE,IAAI;IACX,QAAQ,EAAE,GAAG,EAAE,CAAC,GAAG;IACnB,iBAAiB,EAAE,IAAI;IACvB,IAAI,EAAE,CAAC,CAAU,EAAE,EAAE,CAAC,IAAI;CACb,CAAA;AACf,MAAM,cAAc,GAAG;IACrB,MAAM,EAAE,IAAI;IACZ,QAAQ,EAAE,GAAG,EAAE,CAAC,UAAU;IAC1B,iBAAiB,EAAE,KAAK;IACxB,IAAI,EAAE,CAAC,CAAU,EAAE,EAAE,CAAC,KAAK;CACH,CAAA","sourcesContent":["// TODO: it might be faster to not have Version objects in the\n// comparator tuples, and instead just keep the parsed number arrays?\nimport { syntaxError } from '@vltpkg/error-cause'\nimport { fastSplit } from '@vltpkg/fast-split'\nimport { Version } from './version.ts'\n\n/** all comparators are expressed in terms of these operators */\nexport type SimpleOperator = '' | '<' | '<=' | '>' | '>='\n/** operators that are expanded to simpler forms */\nexport type ComplexOperator = '^' | '~' | '~>'\n\nconst isOperator = (\n o?: string,\n): o is ComplexOperator | SimpleOperator =>\n !!o &&\n (o === '>' ||\n o === '<' ||\n o === '>=' ||\n o === '<=' ||\n o === '' ||\n o === '~' ||\n o === '^' ||\n o === '~>')\n\n/** comparator expressed as a [operator,version] tuple */\nexport type OVTuple = [SimpleOperator, Version]\n\nconst preJunk = new Set('=v \\t')\n\nconst invalidComp = (c: string, message: string): SyntaxError =>\n syntaxError(\n `invalid comparator: '${c}' ${message}`,\n { found: c },\n Comparator,\n )\n\nconst assertNumber = (value: string, c: string, field: string) => {\n const n = Number(value)\n if (n !== n) {\n throw invalidComp(\n c,\n `${field} must be numeric or 'x', got: '${value}'`,\n )\n }\n return n\n}\n\nconst assertVersion = (v: string, comp: string) => {\n if (!v) {\n throw invalidComp(comp, 'no value provided for operator')\n }\n}\n\nconst assertMissing = (\n value: string | undefined,\n c: string,\n field: string,\n) => {\n if (value && !isX(value)) {\n throw invalidComp(\n c,\n `cannot omit '${field}' and include subsequent fields`,\n )\n }\n}\n\nconst MAJOR = 0\nconst MINOR = 1\nconst PATCH = 2\n\nconst isX = (c?: string) => !c || c === 'X' || c === 'x' || c === '*'\n\n/**\n * The result of parsing a version value that might be either a full\n * version like `1.2.3` or an X-Range like `1.2.x`\n */\nexport type ParsedXRange =\n | ParsedXMajor\n | ParsedXMinor\n | ParsedXPatch\n | ParsedXVersion\n/**\n * a {@link ParsedXRange} that is just a `*`\n */\nexport type ParsedXMajor = []\n/**\n * a {@link ParsedXRange} that is just a major version\n */\nexport type ParsedXMinor = [number]\n/**\n * a {@link ParsedXRange} that is just a major and minor version\n */\nexport type ParsedXPatch = [number, number]\n/**\n * a {@link ParsedXRange} that is a full version\n */\nexport type ParsedXVersion = [\n M: number,\n m: number,\n p: number,\n pr?: string | undefined,\n b?: string | undefined,\n]\n\nconst isFullVersion = (\n parsed: ParsedXRange,\n): parsed is ParsedXVersion => undefined !== parsed[PATCH]\nconst isXPatch = (parsed: ParsedXRange): parsed is ParsedXPatch =>\n undefined !== parsed[MINOR] && undefined === parsed[PATCH]\nconst isXMinor = (parsed: ParsedXRange): parsed is ParsedXMinor =>\n undefined !== parsed[MAJOR] && undefined === parsed[MINOR]\nconst isXMajor = (parsed: ParsedXRange): parsed is ParsedXMajor =>\n undefined === parsed[MAJOR]\n\n/**\n * Class used to parse the `||` separated portions\n * of a range, and evaluate versions against it.\n *\n * This does most of the heavy lifting of range testing, and provides\n * little affordance for improperly formatted strings. It should be\n * considered an internal class, and usually not accessed directly.\n */\nexport class Comparator {\n /**\n * does this range include prereleases, even when they do not\n * match the tuple in the comparator?\n */\n includePrerelease: boolean\n /** raw string used to create this comparator */\n raw: string\n /** tokens extracted from the raw string input */\n tokens: string[]\n /**\n * Either the `any` comparator, the `none` comparator, or an operator\n * and a {@link ParsedXRange}\n */\n tuples: (Comparator | OVTuple)[] = []\n /** true if this comparator can not match anything */\n isNone = false\n /**\n * true if this comparator is a `'*'` type of range.\n *\n * Note that it still will not match versions with a prerelease value,\n * unless the tuple in the version matches the tuple provided to the\n * comparator, and the comparator version also has a prerelease value,\n * unless `includePrerelease` is set.\n */\n isAny = false\n\n /** the canonical strict simplified parsed form of this constructor */\n toString() {\n return (\n this.isNone ? '<0.0.0-0'\n : this.isAny ? '*'\n : /* c8 ignore next */\n this.tuples.map(c => (isAny(c) ? '*' : c.join(''))).join(' ')\n )\n }\n\n constructor(comp: string, includePrerelease = false) {\n this.includePrerelease = includePrerelease\n comp = comp.trim()\n this.raw = comp\n let hyphen = false as boolean\n const rawComps = fastSplit(comp, ' ', -1, (part, parts, i) => {\n if (part === '-') {\n if (hyphen) {\n throw invalidComp(\n comp,\n 'multiple hyphen ranges not allowed',\n )\n }\n if (parts.length !== 1 || i === -1) {\n throw invalidComp(\n comp,\n 'hyphen must be between two versions',\n )\n }\n hyphen = true\n } else if (hyphen && parts.length !== 2) {\n throw invalidComp(comp, 'hyphen range must be alone')\n }\n })\n\n // remove excess spaces, `> 1 2` => `>1 2`\n const comps: string[] = []\n let followingOperator = false\n\n let l = 0\n for (const c of rawComps) {\n if (c === '') continue\n if (!followingOperator) {\n followingOperator = isOperator(c)\n comps.push(c)\n l++\n continue\n }\n // we know this is not undefined since followingOperator guards that\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n comps[l - 1]! += c\n followingOperator = false\n }\n\n // TS mistakenly thinks hyphen is always false here\n if (hyphen) {\n const [min, _, max] = comps\n /* c8 ignore start - defense in depth for TS, already guaranteed */\n if (!min || !max) {\n throw invalidComp(comp, 'hyphen must be between two versions')\n }\n /* c8 ignore stop */\n this.#parseHyphenRange(min, max)\n } else if (\n !comps.length ||\n (comps.length === 1 && isX(comps[0]))\n ) {\n this.tuples.push(this.#getComparatorAny())\n } else {\n for (const c of comps) {\n this.#parse(c)\n if (this.isNone) break\n }\n }\n this.tokens = comps\n this.isAny = true\n for (const c of this.tuples) {\n if (Array.isArray(c) || !c.isAny) {\n this.isAny = false\n break\n }\n }\n }\n\n // inclusive min\n #xInclusiveMin(raw: string): Comparator | OVTuple {\n const z = this.includePrerelease ? '0' : undefined\n const [M, m = 0, p = 0, pr = z, build] = this.#parseX(raw)\n return M === undefined ?\n this.#getComparatorAny()\n : ['>=', new Version(raw, M, m, p, pr, build)]\n }\n\n // exclusive min\n #xExclusiveMin(raw: string): Comparator | OVTuple {\n const parsed = this.#parseX(raw)\n if (isFullVersion(parsed)) {\n return ['>', new Version(raw, ...parsed)]\n }\n const z = this.includePrerelease ? '0' : undefined\n if (isXPatch(parsed)) {\n // >1.2 => >=1.3.0\n return [\n '>=',\n new Version(\n raw,\n parsed[MAJOR],\n parsed[MINOR] + 1,\n 0,\n z,\n undefined,\n ),\n ]\n }\n if (isXMinor(parsed)) {\n // >1 => >=2.0.0\n return [\n '>=',\n new Version(raw, parsed[MAJOR] + 1, 0, 0, z, undefined),\n ]\n }\n this.isNone = true\n this.tuples.length = 0\n return comparatorNone\n }\n\n #xInclusiveMax(raw: string): Comparator | OVTuple {\n const parsed = this.#parseX(raw)\n return (\n isFullVersion(parsed) ? ['<=', new Version(raw, ...parsed)]\n : isXPatch(parsed) ?\n [\n '<',\n new Version(\n raw,\n parsed[MAJOR],\n parsed[MINOR] + 1,\n 0,\n '0',\n undefined,\n ),\n ]\n : isXMinor(parsed) ?\n [\n '<',\n new Version(raw, parsed[MAJOR] + 1, 0, 0, '0', undefined),\n ]\n : this.#getComparatorAny()\n )\n }\n\n #xExclusiveMax(raw: string): Comparator | OVTuple {\n const z = this.includePrerelease ? '0' : undefined\n const [M = 0, m = 0, p = 0, pr = z, build] = this.#parseX(raw)\n if (M === 0 && m === 0 && p === 0 && pr === '0') {\n this.isNone = true\n this.tuples.length = 0\n return comparatorNone\n }\n return ['<', new Version(raw, M, m, p, pr, build)]\n }\n\n #validXM(raw: string, m?: string, p?: string): ParsedXMajor {\n assertMissing(m, raw, 'major')\n assertMissing(p, raw, 'major')\n if (m === '' || p === '') {\n throw invalidComp(raw, `(Did you mean '*'?)`)\n }\n return []\n }\n #validXm(\n raw: string,\n M: string,\n m?: string,\n p?: string,\n ): ParsedXMinor {\n assertMissing(p, raw, 'major')\n if (m === '' || p === '') {\n throw invalidComp(raw, `(Did you mean '${M}'?)`)\n }\n return [assertNumber(M, raw, 'major')]\n }\n #validXp(\n raw: string,\n M: string,\n m: string,\n p?: string,\n ): ParsedXPatch {\n if (p === '') {\n throw invalidComp(raw, `(Did you mean '${M}.${m}'?)`)\n }\n return [\n assertNumber(M, raw, 'major'),\n assertNumber(m, raw, 'minor'),\n ]\n }\n #validTuple(\n raw: string,\n M: string,\n m: string,\n p: string,\n ): ParsedXVersion {\n return [\n assertNumber(M, raw, 'major'),\n assertNumber(m, raw, 'minor'),\n assertNumber(p, raw, 'patch'),\n ]\n }\n #validXbuild(\n raw: string,\n M: string,\n m: string,\n p: string,\n pl: number,\n ): ParsedXVersion {\n // build, no prerelease\n const patch = p.substring(0, pl)\n const build = p.substring(pl + 1)\n if (!patch) {\n throw invalidComp(raw, 'cannot specify build without patch')\n }\n if (!build) {\n throw invalidComp(raw, `encountered '+', but no build value`)\n }\n return [\n assertNumber(M, raw, 'major'),\n assertNumber(m, raw, 'minor'),\n assertNumber(patch, raw, 'patch'),\n undefined,\n build,\n ]\n }\n\n #validXpr(\n raw: string,\n M: string,\n m: string,\n p: string,\n hy: number,\n ): ParsedXVersion {\n {\n // prerelease, no build\n const patch = p.substring(0, hy)\n const pr = p.substring(hy + 1)\n if (!patch) {\n throw invalidComp(\n raw,\n 'cannot specify prerelease without patch',\n )\n }\n if (!pr) {\n throw invalidComp(\n raw,\n `encountered '-', but no prerelease value`,\n )\n }\n return [\n assertNumber(M, raw, 'major'),\n assertNumber(m, raw, 'minor'),\n assertNumber(patch, raw, 'patch'),\n pr,\n undefined,\n ]\n }\n }\n #validXprbuild(\n raw: string,\n M: string,\n m: string,\n p: string,\n hy: number,\n pl: number,\n ): ParsedXVersion {\n // both prerelease and build\n const patch = p.substring(0, hy)\n const pr = p.substring(hy + 1, pl)\n const build = p.substring(pl + 1)\n if (!patch) {\n throw invalidComp(\n raw,\n 'cannot specify prerelease without patch',\n )\n }\n if (!pr) {\n throw invalidComp(\n raw,\n `encountered '-', but no prerelease value`,\n )\n }\n if (!build) {\n throw invalidComp(raw, `encountered '+', but no build value`)\n }\n return [\n assertNumber(M, raw, 'major'),\n assertNumber(m, raw, 'minor'),\n assertNumber(patch, raw, 'patch'),\n pr,\n build,\n ]\n }\n\n // pull the relevant values out of an X-range or version\n // return the fields for creating a Version object.\n // only call once operator is stripped off\n #parseX(raw: string): ParsedXRange {\n let [M, m, p] = fastSplit(raw, '.', 3)\n let prune = 0\n while (M && preJunk.has(M.charAt(prune))) prune++\n if (M !== undefined && prune !== 0) M = M.substring(prune)\n // the `|| !M` is so TS knows we've handled undefined\n if (!M || isX(M)) return this.#validXM(raw, m, p)\n if (!m || isX(m)) return this.#validXm(raw, M, m, p)\n if (!p || isX(p)) return this.#validXp(raw, M, m, p)\n\n const hy = p.indexOf('-')\n const pl = p.indexOf('+')\n if (pl === -1 && hy === -1) return this.#validTuple(raw, M, m, p)\n if (pl === -1) return this.#validXpr(raw, M, m, p, hy)\n if (hy === -1) return this.#validXbuild(raw, M, m, p, pl)\n return this.#validXprbuild(raw, M, m, p, hy, pl)\n }\n\n #parseHyphenRange(min: string, max: string) {\n const minv = this.#xInclusiveMin(min)\n const maxv = this.#xInclusiveMax(max)\n const minAny = isAny(minv)\n const maxAny = isAny(maxv)\n if (minAny && maxAny) this.tuples.push(this.#getComparatorAny())\n else if (minAny) this.tuples.push(maxv)\n else if (maxAny) this.tuples.push(minv)\n else this.tuples.push(minv, maxv)\n }\n\n #parse(comp: string) {\n const first = comp.charAt(0)\n const first2 = comp.substring(0, 2)\n const v1 = comp.substring(1)\n const v2 = comp.substring(2)\n switch (first2) {\n case '~>':\n assertVersion(v2, comp)\n return this.#parseTilde(v2)\n case '>=':\n assertVersion(v2, comp)\n return this.tuples.push(this.#xInclusiveMin(v2))\n case '<=':\n assertVersion(v2, comp)\n return this.tuples.push(this.#xInclusiveMax(v2))\n }\n switch (first) {\n case '~':\n assertVersion(v1, comp)\n return this.#parseTilde(v1)\n case '^':\n assertVersion(v1, comp)\n return this.#parseCaret(v1)\n case '>':\n assertVersion(v1, comp)\n return this.tuples.push(this.#xExclusiveMin(v1))\n case '<':\n assertVersion(v1, comp)\n return this.tuples.push(this.#xExclusiveMax(v1))\n }\n return this.#parseEq(comp)\n }\n\n #parseTilde(comp: string) {\n const parsed = this.#parseX(comp)\n if (isXMajor(parsed)) {\n this.tuples.push(this.#getComparatorAny())\n return\n }\n const z = this.includePrerelease ? '0' : undefined\n if (isXMinor(parsed)) {\n const [M] = parsed\n this.tuples.push(\n ['>=', new Version(comp, M, 0, 0, z, undefined)],\n ['<', new Version(comp, M + 1, 0, 0, '0', undefined)],\n )\n return\n }\n if (isXPatch(parsed)) {\n const [M, m] = parsed\n const z = this.includePrerelease ? '0' : undefined\n this.tuples.push(\n ['>=', new Version(comp, M, m, 0, z, undefined)],\n ['<', new Version(comp, M, m + 1, 0, '0', undefined)],\n )\n return\n }\n const [M, m, p, pr = z, build] = parsed\n this.tuples.push(\n ['>=', new Version(comp, M, m, p, pr, build)],\n ['<', new Version(comp, M, m + 1, 0, '0', build)],\n )\n }\n\n #parseCaret(comp: string) {\n const min = this.#xInclusiveMin(comp)\n if (isAny(min)) {\n this.tuples.push(min)\n return\n }\n const minv = min[1]\n if (minv.major !== 0) {\n this.tuples.push(min, [\n '<',\n new Version(comp, minv.major + 1, 0, 0, '0', undefined),\n ])\n } else if (minv.minor !== 0) {\n this.tuples.push(min, [\n '<',\n new Version(\n comp,\n minv.major,\n minv.minor + 1,\n 0,\n '0',\n undefined,\n ),\n ])\n } else if (!minv.prerelease?.length) {\n this.tuples.push(['', minv])\n } else {\n this.tuples.push(min, [\n '<',\n new Version(\n comp,\n minv.major,\n minv.minor,\n minv.patch + 1,\n '0',\n undefined,\n ),\n ])\n }\n }\n\n #parseEq(comp: string) {\n const parsed = this.#parseX(comp)\n const z = this.includePrerelease ? '0' : undefined\n if (isFullVersion(parsed)) {\n this.tuples.push(['', new Version(comp, ...parsed)])\n } else if (isXMajor(parsed)) {\n this.tuples.push(this.#getComparatorAny())\n } else if (isXMinor(parsed)) {\n this.tuples.push([\n '>=',\n new Version(comp, parsed[MAJOR], 0, 0, z, undefined),\n ])\n this.tuples.push([\n '<',\n new Version(comp, parsed[MAJOR] + 1, 0, 0, '0', undefined),\n ])\n } else if (isXPatch(parsed)) {\n this.tuples.push(\n [\n '>=',\n new Version(\n comp,\n parsed[MAJOR],\n parsed[MINOR],\n 0,\n z,\n undefined,\n ),\n ],\n [\n '<',\n new Version(\n comp,\n parsed[MAJOR],\n parsed[MINOR] + 1,\n 0,\n '0',\n undefined,\n ),\n ],\n )\n }\n }\n\n /** return true if the version is a match for this comparator */\n test(v: Version) {\n if (this.isNone) return false\n const ip = this.includePrerelease\n const hasPR = !!v.prerelease?.length\n let prOK = ip || !hasPR\n for (const c of this.tuples) {\n if (isAny(c)) {\n continue\n }\n const [op, cv] = c\n prOK ||= !!cv.prerelease?.length && v.tupleEquals(cv)\n switch (op) {\n case '':\n if (!v.equals(cv)) return false\n continue\n case '>':\n if (!v.greaterThan(cv)) return false\n continue\n case '>=':\n if (!v.greaterThanEqual(cv)) return false\n continue\n case '<':\n if (!v.lessThan(cv)) return false\n continue\n case '<=':\n if (!v.lessThanEqual(cv)) return false\n continue\n }\n }\n // they all passed, so it can only fail for having a prerelease\n // if we allow prereleases, or saw a matching tuple, that's ok.\n return prOK\n }\n\n #getComparatorAny() {\n return this.includePrerelease ? comparatorAnyPR : comparatorAny\n }\n}\n\nconst isAny = (c: Comparator | OVTuple): c is Comparator =>\n c === comparatorAny || c === comparatorAnyPR\nconst comparatorAny = {\n isAny: true,\n toString: () => '*',\n includePrerelease: false,\n test: (v: Version) => !v.prerelease?.length,\n} as Comparator\nconst comparatorAnyPR = {\n isAny: true,\n toString: () => '*',\n includePrerelease: true,\n test: (_: Version) => true,\n} as Comparator\nconst comparatorNone = {\n isNone: true,\n toString: () => '<0.0.0-0',\n includePrerelease: false,\n test: (_: Version) => false,\n} as unknown as Comparator\n"]}
import { Range } from './range.ts';
import { Version } from './version.ts';
import type { IncrementType } from './version.ts';
export * from './comparator.ts';
export * from './range.ts';
export * from './version.ts';
/** Return the parsed version string, or `undefined` if invalid */
export declare const parse: (version: Version | string) => Version | undefined;
/** Return the parsed version range, or `undefined` if invalid */
export declare const parseRange: (range: Range | string, includePrerelease?: boolean) => Range | undefined;
/**
* return true if the version is valid
*
* Note: do not use this if you intend to immediately parse the version if it's
* valid. Just use {@link parse}, and guard the possible undefined value, or
* use `Version.parse(..)` to throw on invalid values.
*/
export declare const valid: (version: Version | string) => boolean;
/**
* return true if the range is valid
*
* Note: do not use this if you intend to immediately parse the range if it's
* valid. Just use {@link parseRange}, and guard the possible undefined value,
* or use `new Range(..)` to throw on invalid values.
*/
export declare const validRange: (range: Range | string) => boolean;
/**
* Return true if the version satisfies the range.
*/
export declare const satisfies: (version: Version | string, range: Range | string, includePrerelease?: boolean) => boolean;
/**
* Increment the specified part of the version, and return the resulting
* object. If a Version object is provided, it will be modified in-place.
*
* See {@link Version.inc} for full description.
*/
export declare const inc: (version: Version | string, part: IncrementType, prereleaseIdentifier?: string) => Version;
/**
* The method used by {@link sort}, exported for passing directly to
* `Array.sort`.
*
* Usage:
*
* ```ts
* import { sortMethod } from '@vltpkg/semver'
* const versions = ['1.2.3', '5.2.3', '2.3.4']
* console.log(versions.sort(sortMethod))
* // ['1.2.3', '2.3.4', '5.2.3']
* ```
*/
export declare const sortMethod: (a: Version | string, b: Version | string) => number;
/**
* Sort an array of version strings or objects in ascending SemVer precedence
* order (ie, lowest versions first).
*
* Invalid version strings are sorted to the end of the array in ascending
* alphabetical order.
*
* Note: when using this method, the list is cloned prior to sorting, to
* prevent surprising mutation. To sort the list in place, see
* {@link sortMethod}.
*/
export declare const sort: <T extends Version | string = string | Version>(list: T[]) => T[];
/**
* Sort an array of version strings or objects in descending SemVer
* precedence order (ie, highest versions first).
*
* Invalid version strings are sorted to the end of the array in ascending
* alphabetical order.
*
* Note: when using this method, the list is cloned prior to sorting, to
* prevent surprising mutation. To sort the list in place, see
* {@link rsortMethod}.
*/
export declare const rsort: <T extends Version | string = string | Version>(list: T[]) => T[];
/**
* The method used by {@link rsort}, exported for passing directly to
* `Array.sort`.
*
* Usage:
*
* ```ts
* import { rsortMethod } from '@vltpkg/semver'
* const versions = ['1.2.3', '5.2.3', '2.3.4']
* console.log(versions.sort(rsortMethod))
* // ['5.2.3', '2.3.4', '1.2.3']
* ```
*/
export declare const rsortMethod: (a: Version | string, b: Version | string) => number;
/**
* Method used by {@link filter}, for use in `Array.filter` directly.
*
* Usage:
*
* ```ts
* import { filterMethod } from '@vltpkg/semver'
* const versions = ['1.2.3', '5.2.3', '2.3.4']
* console.log(versions.filter(filterMethod('>=2.x')))
* // ['5.2.3', '2.3.4']
* ```
*/
export declare const filterMethod: (range: Range | string, includePrerelease?: boolean) => ((version: Version | string) => boolean);
/**
* Filter a list of versions to find all that match a given range.
*/
export declare const filter: <T extends Version | string = string | Version>(list: T[], range: Range | string, includePrerelease?: boolean) => T[];
/**
* Find the highest-precedence match for a range within a list of versions
*
* Returns `undefined` if no match was found.
*/
export declare const highest: (list: (Version | string)[], range: Range | string, includePrerelease?: boolean) => Version | undefined;
/**
* Faster form of {@link highest}, for use when the list is sorted
* in precedence order (lower-precedence versions first).
*
* Note: This stops at the first match, and will produce incorrect results
* when the list is not properly sorted!
*/
export declare const sortedHighest: (list: (Version | string)[], range: Range | string, includePrerelease?: boolean) => Version | undefined;
/**
* Faster form of {@link highest}, for use when the list is sorted
* in reverse precedence order (higher-precedence versions first).
*
* Note: This stops at the first match, and will produce incorrect results
* when the list is not properly sorted!
*/
export declare const rsortedHighest: (list: (Version | string)[], range: Range | string, includePrerelease?: boolean) => Version | undefined;
/**
* Find the lowest-precedence match for a range within a list of versions
*
* Returns `undefined` if no match was found.
*/
export declare const lowest: (list: (Version | string)[], range: Range | string, includePrerelease?: boolean) => Version | undefined;
/**
* Faster form of {@link lowest}, for use when the list is sorted
* in precedence order (lower-precedence versions first).
*
* Note: This stops at the first match, and will produce incorrect results
* when the list is not properly sorted!
*/
export declare const sortedLowest: (list: (Version | string)[], range: Range | string, includePrerelease?: boolean) => Version | undefined;
/**
* Faster form of {@link lowest}, for use when the list is sorted
* in reverse precedence order (higher-precedence versions first).
*
* Note: This stops at the first match, and will produce incorrect results
* when the list is not properly sorted!
*/
export declare const rsortedLowest: (list: (Version | string)[], range: Range | string, includePrerelease?: boolean) => Version | undefined;
/**
* Same as {@link sortMethod}, but throws if either version is not valid.
* 1 if versionA is higher precedence than versionB
* -1 if versionA is lower precedence than versionB
* 0 if they have equal precedence
*/
export declare const compare: (versionA: Version | string, versionB: Version | string) => 0 | 1 | -1;
/**
* Inverse of {@link compare}
*
* Same as {@link rsortMethod}, but throws if either version is not valid.
*
* -1 if versionA is higher precedence than versionB
* 1 if versionA is lower precedence than versionB
* 0 if they have equal precedence
*/
export declare const rcompare: (versionA: Version | string, versionB: Version | string) => 0 | 1 | -1;
/** true if versionA is > versionB. throws on invalid values */
export declare const gt: (versionA: Version | string, versionB: Version | string) => boolean;
/** true if versionA is >= versionB. throws on invalid values */
export declare const gte: (versionA: Version | string, versionB: Version | string) => boolean;
/** true if versionA is < versionB. throws on invalid values */
export declare const lt: (versionA: Version | string, versionB: Version | string) => boolean;
/** true if versionA is &lt;= versionB. throws on invalid values */
export declare const lte: (versionA: Version | string, versionB: Version | string) => boolean;
/** true if versionA is not equal to versionB. throws on invalid values */
export declare const neq: (versionA: Version | string, versionB: Version | string) => boolean;
/** true if versionA is equal to versionB. throws on invalid values */
export declare const eq: (versionA: Version | string, versionB: Version | string) => boolean;
/** extract the major version number, or undefined if invalid */
export declare const major: (version: Version | string) => number | undefined;
/** extract the minor version number, or undefined if invalid */
export declare const minor: (version: Version | string) => number | undefined;
/** extract the patch version number, or undefined if invalid */
export declare const patch: (version: Version | string) => number | undefined;
/**
* extract the list of prerelease identifiers, or undefined if the version
* is invalid. If no prerelease identifiers are present, returns `[]`.
*/
export declare const prerelease: (version: Version | string) => (string | number)[] | undefined;
/**
* extract the list of build identifiers, or undefined if the version
* is invalid. If no build identifiers are present, returns `[]`.
*/
export declare const build: (version: Version | string) => string[] | undefined;
/** return all versions that do not have any prerelease identifiers */
export declare const stable: <T extends Version | string = string | Version>(versions: T[]) => T[];
/**
* Return true if the range r1 intersects any of the ranges r2
* r1 and r2 are either Range objects or range strings.
* Returns true if any version would satisfy both ranges.
*/
export declare const intersects: (r1: Range | string, r2: Range | string, includePrerelease?: boolean) => boolean;
//# sourceMappingURL=index.d.ts.map
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":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MACd,KAAK,GAAG,MAAM,sBACE,OAAO,YAgB5B,CAAA"}
import { Range } from "./range.js";
import { Version } from "./version.js";
import { syntaxError } from '@vltpkg/error-cause';
export * from "./comparator.js";
export * from "./range.js";
export * from "./version.js";
/** Return the parsed version string, or `undefined` if invalid */
export const parse = (version) => {
if (!(typeof version === 'string'))
return version;
try {
return Version.parse(version);
}
catch {
return undefined;
}
};
/** Return the parsed version range, or `undefined` if invalid */
export const parseRange = (range, includePrerelease = false) => {
if (typeof range === 'object') {
if (range.includePrerelease === includePrerelease)
return range;
range = range.raw;
}
try {
return new Range(range, includePrerelease);
}
catch {
return undefined;
}
};
/**
* return true if the version is valid
*
* Note: do not use this if you intend to immediately parse the version if it's
* valid. Just use {@link parse}, and guard the possible undefined value, or
* use `Version.parse(..)` to throw on invalid values.
*/
export const valid = (version) => !!parse(version);
/**
* return true if the range is valid
*
* Note: do not use this if you intend to immediately parse the range if it's
* valid. Just use {@link parseRange}, and guard the possible undefined value,
* or use `new Range(..)` to throw on invalid values.
*/
export const validRange = (range) => !!parseRange(range);
/**
* Return true if the version satisfies the range.
*/
export const satisfies = (version, range, includePrerelease = false) => {
if (typeof version === 'string') {
const parsed = parse(version);
if (!parsed)
return false;
version = parsed;
}
if (typeof range === 'string') {
const parsed = parseRange(range, includePrerelease);
if (!parsed)
return false;
range = parsed;
}
return version.satisfies(range);
};
/**
* Increment the specified part of the version, and return the resulting
* object. If a Version object is provided, it will be modified in-place.
*
* See {@link Version.inc} for full description.
*/
export const inc = (version, part, prereleaseIdentifier) => (typeof version === 'string' ?
Version.parse(version)
: version).inc(part, prereleaseIdentifier);
/**
* The method used by {@link sort}, exported for passing directly to
* `Array.sort`.
*
* Usage:
*
* ```ts
* import { sortMethod } from '@vltpkg/semver'
* const versions = ['1.2.3', '5.2.3', '2.3.4']
* console.log(versions.sort(sortMethod))
* // ['1.2.3', '2.3.4', '5.2.3']
* ```
*/
export const sortMethod = (a, b) => {
const pa = parse(a);
const pb = parse(b);
/* c8 ignore start - nondeterministic */
if (!pa && !pb)
return String(a).localeCompare(String(b), 'en');
if (!pa)
return 1;
if (!pb)
return -1;
/* c8 ignore stop */
return pa.compare(pb);
};
/**
* Sort an array of version strings or objects in ascending SemVer precedence
* order (ie, lowest versions first).
*
* Invalid version strings are sorted to the end of the array in ascending
* alphabetical order.
*
* Note: when using this method, the list is cloned prior to sorting, to
* prevent surprising mutation. To sort the list in place, see
* {@link sortMethod}.
*/
export const sort = (list) => list.slice().sort(sortMethod);
/**
* Sort an array of version strings or objects in descending SemVer
* precedence order (ie, highest versions first).
*
* Invalid version strings are sorted to the end of the array in ascending
* alphabetical order.
*
* Note: when using this method, the list is cloned prior to sorting, to
* prevent surprising mutation. To sort the list in place, see
* {@link rsortMethod}.
*/
export const rsort = (list) => list.slice().sort(rsortMethod);
/**
* The method used by {@link rsort}, exported for passing directly to
* `Array.sort`.
*
* Usage:
*
* ```ts
* import { rsortMethod } from '@vltpkg/semver'
* const versions = ['1.2.3', '5.2.3', '2.3.4']
* console.log(versions.sort(rsortMethod))
* // ['5.2.3', '2.3.4', '1.2.3']
* ```
*/
export const rsortMethod = (a, b) => {
const pa = parse(a);
const pb = parse(b);
/* c8 ignore start - nondeterministic */
if (!pa && !pb)
return String(a).localeCompare(String(b), 'en');
if (!pa)
return 1;
if (!pb)
return -1;
/* c8 ignore stop */
return pa.rcompare(pb);
};
/**
* Method used by {@link filter}, for use in `Array.filter` directly.
*
* Usage:
*
* ```ts
* import { filterMethod } from '@vltpkg/semver'
* const versions = ['1.2.3', '5.2.3', '2.3.4']
* console.log(versions.filter(filterMethod('>=2.x')))
* // ['5.2.3', '2.3.4']
* ```
*/
export const filterMethod = (range, includePrerelease = false) => {
const r = parseRange(range, includePrerelease);
return !r ?
() => false
: version => satisfies(version, r, r.includePrerelease);
};
/**
* Filter a list of versions to find all that match a given range.
*/
export const filter = (list, range, includePrerelease = false) => list.filter(filterMethod(range, includePrerelease));
/**
* Find the highest-precedence match for a range within a list of versions
*
* Returns `undefined` if no match was found.
*/
export const highest = (list, range, includePrerelease = false) => {
const r = parseRange(range, includePrerelease);
if (!r)
return undefined;
let max = undefined;
for (const v of list) {
const version = parse(v);
if (!version)
continue;
if (!version.satisfies(r))
continue;
if (!max)
max = version;
else if (version.greaterThan(max))
max = version;
}
return max;
};
/**
* Faster form of {@link highest}, for use when the list is sorted
* in precedence order (lower-precedence versions first).
*
* Note: This stops at the first match, and will produce incorrect results
* when the list is not properly sorted!
*/
export const sortedHighest = (list, range, includePrerelease = false) => {
const r = parseRange(range, includePrerelease);
if (!r)
return undefined;
for (let i = list.length - 1; i >= 0; i--) {
const v = list[i];
/* c8 ignore next */
if (!v)
continue;
const version = parse(v);
if (!version)
continue;
if (!version.satisfies(r))
continue;
return version;
}
};
/**
* Faster form of {@link highest}, for use when the list is sorted
* in reverse precedence order (higher-precedence versions first).
*
* Note: This stops at the first match, and will produce incorrect results
* when the list is not properly sorted!
*/
export const rsortedHighest = (list, range, includePrerelease = false) => {
const r = parseRange(range, includePrerelease);
if (!r)
return undefined;
for (const v of list) {
const version = parse(v);
if (!version)
continue;
if (!version.satisfies(r))
continue;
return version;
}
};
/**
* Find the lowest-precedence match for a range within a list of versions
*
* Returns `undefined` if no match was found.
*/
export const lowest = (list, range, includePrerelease = false) => {
const r = parseRange(range, includePrerelease);
if (!r)
return undefined;
let min = undefined;
for (const v of list) {
const version = parse(v);
if (!version)
continue;
if (!version.satisfies(r))
continue;
if (!min)
min = version;
else if (version.lessThan(min))
min = version;
}
return min;
};
/**
* Faster form of {@link lowest}, for use when the list is sorted
* in precedence order (lower-precedence versions first).
*
* Note: This stops at the first match, and will produce incorrect results
* when the list is not properly sorted!
*/
export const sortedLowest = (list, range, includePrerelease = false) => rsortedHighest(list, range, includePrerelease);
/**
* Faster form of {@link lowest}, for use when the list is sorted
* in reverse precedence order (higher-precedence versions first).
*
* Note: This stops at the first match, and will produce incorrect results
* when the list is not properly sorted!
*/
export const rsortedLowest = (list, range, includePrerelease = false) => sortedHighest(list, range, includePrerelease);
/**
* Same as {@link sortMethod}, but throws if either version is not valid.
* 1 if versionA is higher precedence than versionB
* -1 if versionA is lower precedence than versionB
* 0 if they have equal precedence
*/
export const compare = (versionA, versionB) => {
const a = parse(versionA);
if (!a) {
throw syntaxError('invalid version', { found: versionA });
}
const b = parse(versionB);
if (!b) {
throw syntaxError('invalid version', { found: versionB });
}
return a.compare(b);
};
/**
* Inverse of {@link compare}
*
* Same as {@link rsortMethod}, but throws if either version is not valid.
*
* -1 if versionA is higher precedence than versionB
* 1 if versionA is lower precedence than versionB
* 0 if they have equal precedence
*/
export const rcompare = (versionA, versionB) => compare(versionB, versionA);
/** true if versionA is > versionB. throws on invalid values */
export const gt = (versionA, versionB) => compare(versionA, versionB) > 0;
/** true if versionA is >= versionB. throws on invalid values */
export const gte = (versionA, versionB) => compare(versionA, versionB) >= 0;
/** true if versionA is < versionB. throws on invalid values */
export const lt = (versionA, versionB) => compare(versionA, versionB) < 0;
/** true if versionA is &lt;= versionB. throws on invalid values */
export const lte = (versionA, versionB) => compare(versionA, versionB) <= 0;
/** true if versionA is not equal to versionB. throws on invalid values */
export const neq = (versionA, versionB) => compare(versionA, versionB) !== 0;
/** true if versionA is equal to versionB. throws on invalid values */
export const eq = (versionA, versionB) => compare(versionA, versionB) === 0;
/** extract the major version number, or undefined if invalid */
export const major = (version) => parse(version)?.major;
/** extract the minor version number, or undefined if invalid */
export const minor = (version) => parse(version)?.minor;
/** extract the patch version number, or undefined if invalid */
export const patch = (version) => parse(version)?.patch;
/**
* extract the list of prerelease identifiers, or undefined if the version
* is invalid. If no prerelease identifiers are present, returns `[]`.
*/
export const prerelease = (version) => {
const p = parse(version);
if (!p)
return undefined;
return p.prerelease ?? [];
};
/**
* extract the list of build identifiers, or undefined if the version
* is invalid. If no build identifiers are present, returns `[]`.
*/
export const build = (version) => {
const p = parse(version);
if (!p)
return undefined;
return p.build ?? [];
};
/** return all versions that do not have any prerelease identifiers */
export const stable = (versions) => versions.filter(v => {
const p = parse(v);
if (!p)
return false;
return !p.prerelease?.length;
});
/**
* Return true if the range r1 intersects any of the ranges r2
* r1 and r2 are either Range objects or range strings.
* Returns true if any version would satisfy both ranges.
*/
export const intersects = (r1, r2, includePrerelease) => {
const range1 = typeof r1 === 'string' ? parseRange(r1, includePrerelease) : r1;
const range2 = typeof r2 === 'string' ? parseRange(r2, includePrerelease) : r2;
if (!range1 || !range2)
return false;
// If either range is 'any', they intersect
if (range1.isAny || range2.isAny)
return true;
// Check if any set from range1 intersects with any set from range2
return range1.set.some(set1 => range2.set.some(set2 => intersectComparators(set1, set2)));
};
/**
* Check if two comparators can be satisfied simultaneously
*/
const intersectComparators = (comp1, comp2) => {
// Collect all tuples from both comparators
const tuples1 = comp1.tuples.filter((t) => Array.isArray(t));
const tuples2 = comp2.tuples.filter((t) => Array.isArray(t));
// Check if there's a satisfiable combination
return satisfiableRange(tuples1.concat(tuples2));
};
/**
* Check if a set of operator-version tuples represents a satisfiable range
* This is a simplified implementation that handles the most common cases
*/
const satisfiableRange = (tuples) => {
// Find bounds
let lowerBound = null;
let lowerInclusive = false;
let upperBound = null;
let upperInclusive = false;
let hasExact = null;
for (const [op, ver] of tuples) {
switch (op) {
case '':
// Exact match - if we already have a different exact match, no intersection
if (hasExact && !eq(hasExact, ver))
return false;
hasExact = ver;
break;
case '>=':
/* c8 ignore start */
if (!lowerBound ||
gt(ver, lowerBound) ||
(eq(ver, lowerBound) && !lowerInclusive)) {
lowerBound = ver;
lowerInclusive = true;
}
/* c8 ignore stop */
break;
case '>':
if (!lowerBound || gt(ver, lowerBound)) {
lowerBound = ver;
lowerInclusive = false;
}
break;
case '<=':
if (!upperBound || lt(ver, upperBound)) {
upperBound = ver;
upperInclusive = true;
}
break;
case '<':
/* c8 ignore start */
if (!upperBound ||
lt(ver, upperBound) ||
eq(ver, upperBound)) {
upperBound = ver;
upperInclusive = false;
}
/* c8 ignore stop */
break;
}
}
// If we have an exact match, check if it's within bounds
if (hasExact) {
if (lowerBound) {
if (lowerInclusive ?
lt(hasExact, lowerBound)
: lte(hasExact, lowerBound)) {
return false;
}
}
if (upperBound) {
if (upperInclusive ?
gt(hasExact, upperBound)
: gte(hasExact, upperBound)) {
return false;
}
}
return true;
}
// Check if lower bound is less than or equal to upper bound
if (lowerBound && upperBound) {
if (gt(lowerBound, upperBound))
return false;
if (eq(lowerBound, upperBound) &&
!(lowerInclusive && upperInclusive))
return false;
}
return true;
};
//# sourceMappingURL=index.js.map
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAGtC,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAEjD,cAAc,iBAAiB,CAAA;AAC/B,cAAc,YAAY,CAAA;AAC1B,cAAc,cAAc,CAAA;AAE5B,kEAAkE;AAClE,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,OAAyB,EAAE,EAAE;IACjD,IAAI,CAAC,CAAC,OAAO,OAAO,KAAK,QAAQ,CAAC;QAAE,OAAO,OAAO,CAAA;IAClD,IAAI,CAAC;QACH,OAAO,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IAC/B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAA;IAClB,CAAC;AACH,CAAC,CAAA;AAED,iEAAiE;AACjE,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,KAAqB,EACrB,iBAAiB,GAAG,KAAK,EACzB,EAAE;IACF,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,IAAI,KAAK,CAAC,iBAAiB,KAAK,iBAAiB;YAAE,OAAO,KAAK,CAAA;QAC/D,KAAK,GAAG,KAAK,CAAC,GAAG,CAAA;IACnB,CAAC;IACD,IAAI,CAAC;QACH,OAAO,IAAI,KAAK,CAAC,KAAK,EAAE,iBAA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AACb,CAAC,CAAA","sourcesContent":["import { Range } from './range.ts'\nimport { Version } from './version.ts'\nimport type { Comparator, OVTuple } from './comparator.ts'\nimport type { IncrementType } from './version.ts'\nimport { syntaxError } from '@vltpkg/error-cause'\n\nexport * from './comparator.ts'\nexport * from './range.ts'\nexport * from './version.ts'\n\n/** Return the parsed version string, or `undefined` if invalid */\nexport const parse = (version: Version | string) => {\n if (!(typeof version === 'string')) return version\n try {\n return Version.parse(version)\n } catch {\n return undefined\n }\n}\n\n/** Return the parsed version range, or `undefined` if invalid */\nexport const parseRange = (\n range: Range | string,\n includePrerelease = false,\n) => {\n if (typeof range === 'object') {\n if (range.includePrerelease === includePrerelease) return range\n range = range.raw\n }\n try {\n return new Range(range, includePrerelease)\n } catch {\n return undefined\n }\n}\n\n/**\n * return true if the version is valid\n *\n * Note: do not use this if you intend to immediately parse the version if it's\n * valid. Just use {@link parse}, and guard the possible undefined value, or\n * use `Version.parse(..)` to throw on invalid values.\n */\nexport const valid = (version: Version | string) => !!parse(version)\n\n/**\n * return true if the range is valid\n *\n * Note: do not use this if you intend to immediately parse the range if it's\n * valid. Just use {@link parseRange}, and guard the possible undefined value,\n * or use `new Range(..)` to throw on invalid values.\n */\nexport const validRange = (range: Range | string) =>\n !!parseRange(range)\n\n/**\n * Return true if the version satisfies the range.\n */\nexport const satisfies = (\n version: Version | string,\n range: Range | string,\n includePrerelease = false,\n) => {\n if (typeof version === 'string') {\n const parsed = parse(version)\n if (!parsed) return false\n version = parsed\n }\n if (typeof range === 'string') {\n const parsed = parseRange(range, includePrerelease)\n if (!parsed) return false\n range = parsed\n }\n return version.satisfies(range)\n}\n\n/**\n * Increment the specified part of the version, and return the resulting\n * object. If a Version object is provided, it will be modified in-place.\n *\n * See {@link Version.inc} for full description.\n */\nexport const inc = (\n version: Version | string,\n part: IncrementType,\n prereleaseIdentifier?: string,\n) =>\n (typeof version === 'string' ?\n Version.parse(version)\n : version\n ).inc(part, prereleaseIdentifier)\n\n/**\n * The method used by {@link sort}, exported for passing directly to\n * `Array.sort`.\n *\n * Usage:\n *\n * ```ts\n * import { sortMethod } from '@vltpkg/semver'\n * const versions = ['1.2.3', '5.2.3', '2.3.4']\n * console.log(versions.sort(sortMethod))\n * // ['1.2.3', '2.3.4', '5.2.3']\n * ```\n */\nexport const sortMethod = (\n a: Version | string,\n b: Version | string,\n) => {\n const pa = parse(a)\n const pb = parse(b)\n /* c8 ignore start - nondeterministic */\n if (!pa && !pb) return String(a).localeCompare(String(b), 'en')\n if (!pa) return 1\n if (!pb) return -1\n /* c8 ignore stop */\n return pa.compare(pb)\n}\n\n/**\n * Sort an array of version strings or objects in ascending SemVer precedence\n * order (ie, lowest versions first).\n *\n * Invalid version strings are sorted to the end of the array in ascending\n * alphabetical order.\n *\n * Note: when using this method, the list is cloned prior to sorting, to\n * prevent surprising mutation. To sort the list in place, see\n * {@link sortMethod}.\n */\nexport const sort = <T extends Version | string = Version | string>(\n list: T[],\n): T[] => list.slice().sort(sortMethod)\n\n/**\n * Sort an array of version strings or objects in descending SemVer\n * precedence order (ie, highest versions first).\n *\n * Invalid version strings are sorted to the end of the array in ascending\n * alphabetical order.\n *\n * Note: when using this method, the list is cloned prior to sorting, to\n * prevent surprising mutation. To sort the list in place, see\n * {@link rsortMethod}.\n */\nexport const rsort = <T extends Version | string = Version | string>(\n list: T[],\n): T[] => list.slice().sort(rsortMethod)\n\n/**\n * The method used by {@link rsort}, exported for passing directly to\n * `Array.sort`.\n *\n * Usage:\n *\n * ```ts\n * import { rsortMethod } from '@vltpkg/semver'\n * const versions = ['1.2.3', '5.2.3', '2.3.4']\n * console.log(versions.sort(rsortMethod))\n * // ['5.2.3', '2.3.4', '1.2.3']\n * ```\n */\nexport const rsortMethod = (\n a: Version | string,\n b: Version | string,\n) => {\n const pa = parse(a)\n const pb = parse(b)\n /* c8 ignore start - nondeterministic */\n if (!pa && !pb) return String(a).localeCompare(String(b), 'en')\n if (!pa) return 1\n if (!pb) return -1\n /* c8 ignore stop */\n return pa.rcompare(pb)\n}\n\n/**\n * Method used by {@link filter}, for use in `Array.filter` directly.\n *\n * Usage:\n *\n * ```ts\n * import { filterMethod } from '@vltpkg/semver'\n * const versions = ['1.2.3', '5.2.3', '2.3.4']\n * console.log(versions.filter(filterMethod('>=2.x')))\n * // ['5.2.3', '2.3.4']\n * ```\n */\nexport const filterMethod = (\n range: Range | string,\n includePrerelease = false,\n): ((version: Version | string) => boolean) => {\n const r = parseRange(range, includePrerelease)\n return !r ?\n () => false\n : version => satisfies(version, r, r.includePrerelease)\n}\n\n/**\n * Filter a list of versions to find all that match a given range.\n */\nexport const filter = <T extends Version | string = Version | string>(\n list: T[],\n range: Range | string,\n includePrerelease = false,\n): T[] => list.filter(filterMethod(range, includePrerelease))\n\n/**\n * Find the highest-precedence match for a range within a list of versions\n *\n * Returns `undefined` if no match was found.\n */\nexport const highest = (\n list: (Version | string)[],\n range: Range | string,\n includePrerelease = false,\n): Version | undefined => {\n const r = parseRange(range, includePrerelease)\n if (!r) return undefined\n let max: Version | undefined = undefined\n for (const v of list) {\n const version = parse(v)\n if (!version) continue\n if (!version.satisfies(r)) continue\n if (!max) max = version\n else if (version.greaterThan(max)) max = version\n }\n return max\n}\n\n/**\n * Faster form of {@link highest}, for use when the list is sorted\n * in precedence order (lower-precedence versions first).\n *\n * Note: This stops at the first match, and will produce incorrect results\n * when the list is not properly sorted!\n */\nexport const sortedHighest = (\n list: (Version | string)[],\n range: Range | string,\n includePrerelease = false,\n): Version | undefined => {\n const r = parseRange(range, includePrerelease)\n if (!r) return undefined\n for (let i = list.length - 1; i >= 0; i--) {\n const v = list[i]\n /* c8 ignore next */\n if (!v) continue\n const version = parse(v)\n if (!version) continue\n if (!version.satisfies(r)) continue\n return version\n }\n}\n\n/**\n * Faster form of {@link highest}, for use when the list is sorted\n * in reverse precedence order (higher-precedence versions first).\n *\n * Note: This stops at the first match, and will produce incorrect results\n * when the list is not properly sorted!\n */\nexport const rsortedHighest = (\n list: (Version | string)[],\n range: Range | string,\n includePrerelease = false,\n): Version | undefined => {\n const r = parseRange(range, includePrerelease)\n if (!r) return undefined\n for (const v of list) {\n const version = parse(v)\n if (!version) continue\n if (!version.satisfies(r)) continue\n return version\n }\n}\n\n/**\n * Find the lowest-precedence match for a range within a list of versions\n *\n * Returns `undefined` if no match was found.\n */\nexport const lowest = (\n list: (Version | string)[],\n range: Range | string,\n includePrerelease = false,\n): Version | undefined => {\n const r = parseRange(range, includePrerelease)\n if (!r) return undefined\n let min: Version | undefined = undefined\n for (const v of list) {\n const version = parse(v)\n if (!version) continue\n if (!version.satisfies(r)) continue\n if (!min) min = version\n else if (version.lessThan(min)) min = version\n }\n return min\n}\n\n/**\n * Faster form of {@link lowest}, for use when the list is sorted\n * in precedence order (lower-precedence versions first).\n *\n * Note: This stops at the first match, and will produce incorrect results\n * when the list is not properly sorted!\n */\nexport const sortedLowest = (\n list: (Version | string)[],\n range: Range | string,\n includePrerelease = false,\n): Version | undefined =>\n rsortedHighest(list, range, includePrerelease)\n\n/**\n * Faster form of {@link lowest}, for use when the list is sorted\n * in reverse precedence order (higher-precedence versions first).\n *\n * Note: This stops at the first match, and will produce incorrect results\n * when the list is not properly sorted!\n */\nexport const rsortedLowest = (\n list: (Version | string)[],\n range: Range | string,\n includePrerelease = false,\n): Version | undefined =>\n sortedHighest(list, range, includePrerelease)\n\n/**\n * Same as {@link sortMethod}, but throws if either version is not valid.\n * 1 if versionA is higher precedence than versionB\n * -1 if versionA is lower precedence than versionB\n * 0 if they have equal precedence\n */\nexport const compare = (\n versionA: Version | string,\n versionB: Version | string,\n) => {\n const a = parse(versionA)\n if (!a) {\n throw syntaxError('invalid version', { found: versionA })\n }\n const b = parse(versionB)\n if (!b) {\n throw syntaxError('invalid version', { found: versionB })\n }\n return a.compare(b)\n}\n\n/**\n * Inverse of {@link compare}\n *\n * Same as {@link rsortMethod}, but throws if either version is not valid.\n *\n * -1 if versionA is higher precedence than versionB\n * 1 if versionA is lower precedence than versionB\n * 0 if they have equal precedence\n */\nexport const rcompare = (\n versionA: Version | string,\n versionB: Version | string,\n) => compare(versionB, versionA)\n\n/** true if versionA is > versionB. throws on invalid values */\nexport const gt = (\n versionA: Version | string,\n versionB: Version | string,\n) => compare(versionA, versionB) > 0\n/** true if versionA is >= versionB. throws on invalid values */\nexport const gte = (\n versionA: Version | string,\n versionB: Version | string,\n) => compare(versionA, versionB) >= 0\n/** true if versionA is < versionB. throws on invalid values */\nexport const lt = (\n versionA: Version | string,\n versionB: Version | string,\n) => compare(versionA, versionB) < 0\n/** true if versionA is &lt;= versionB. throws on invalid values */\nexport const lte = (\n versionA: Version | string,\n versionB: Version | string,\n) => compare(versionA, versionB) <= 0\n/** true if versionA is not equal to versionB. throws on invalid values */\nexport const neq = (\n versionA: Version | string,\n versionB: Version | string,\n) => compare(versionA, versionB) !== 0\n/** true if versionA is equal to versionB. throws on invalid values */\nexport const eq = (\n versionA: Version | string,\n versionB: Version | string,\n) => compare(versionA, versionB) === 0\n\n/** extract the major version number, or undefined if invalid */\nexport const major = (version: Version | string) =>\n parse(version)?.major\n/** extract the minor version number, or undefined if invalid */\nexport const minor = (version: Version | string) =>\n parse(version)?.minor\n/** extract the patch version number, or undefined if invalid */\nexport const patch = (version: Version | string) =>\n parse(version)?.patch\n/**\n * extract the list of prerelease identifiers, or undefined if the version\n * is invalid. If no prerelease identifiers are present, returns `[]`.\n */\nexport const prerelease = (version: Version | string) => {\n const p = parse(version)\n if (!p) return undefined\n return p.prerelease ?? []\n}\n/**\n * extract the list of build identifiers, or undefined if the version\n * is invalid. If no build identifiers are present, returns `[]`.\n */\nexport const build = (version: Version | string) => {\n const p = parse(version)\n if (!p) return undefined\n return p.build ?? []\n}\n\n/** return all versions that do not have any prerelease identifiers */\nexport const stable = <T extends Version | string = Version | string>(\n versions: T[],\n): T[] =>\n versions.filter(v => {\n const p = parse(v)\n if (!p) return false\n return !p.prerelease?.length\n })\n\n/**\n * Return true if the range r1 intersects any of the ranges r2\n * r1 and r2 are either Range objects or range strings.\n * Returns true if any version would satisfy both ranges.\n */\nexport const intersects = (\n r1: Range | string,\n r2: Range | string,\n includePrerelease?: boolean,\n) => {\n const range1 =\n typeof r1 === 'string' ? parseRange(r1, includePrerelease) : r1\n const range2 =\n typeof r2 === 'string' ? parseRange(r2, includePrerelease) : r2\n\n if (!range1 || !range2) return false\n\n // If either range is 'any', they intersect\n if (range1.isAny || range2.isAny) return true\n\n // Check if any set from range1 intersects with any set from range2\n return range1.set.some(set1 =>\n range2.set.some(set2 => intersectComparators(set1, set2)),\n )\n}\n\n/**\n * Check if two comparators can be satisfied simultaneously\n */\nconst intersectComparators = (\n comp1: Comparator,\n comp2: Comparator,\n): boolean => {\n // Collect all tuples from both comparators\n const tuples1 = comp1.tuples.filter((t): t is OVTuple =>\n Array.isArray(t),\n )\n const tuples2 = comp2.tuples.filter((t): t is OVTuple =>\n Array.isArray(t),\n )\n\n // Check if there's a satisfiable combination\n return satisfiableRange(tuples1.concat(tuples2))\n}\n\n/**\n * Check if a set of operator-version tuples represents a satisfiable range\n * This is a simplified implementation that handles the most common cases\n */\nconst satisfiableRange = (tuples: OVTuple[]): boolean => {\n // Find bounds\n let lowerBound: Version | null = null\n let lowerInclusive = false\n let upperBound: Version | null = null\n let upperInclusive = false\n let hasExact: Version | null = null\n\n for (const [op, ver] of tuples) {\n switch (op) {\n case '':\n // Exact match - if we already have a different exact match, no intersection\n if (hasExact && !eq(hasExact, ver)) return false\n hasExact = ver\n break\n\n case '>=':\n /* c8 ignore start */\n if (\n !lowerBound ||\n gt(ver, lowerBound) ||\n (eq(ver, lowerBound) && !lowerInclusive)\n ) {\n lowerBound = ver\n lowerInclusive = true\n }\n /* c8 ignore stop */\n break\n\n case '>':\n if (!lowerBound || gt(ver, lowerBound)) {\n lowerBound = ver\n lowerInclusive = false\n }\n break\n\n case '<=':\n if (!upperBound || lt(ver, upperBound)) {\n upperBound = ver\n upperInclusive = true\n }\n break\n\n case '<':\n /* c8 ignore start */\n if (\n !upperBound ||\n lt(ver, upperBound) ||\n eq(ver, upperBound)\n ) {\n upperBound = ver\n upperInclusive = false\n }\n /* c8 ignore stop */\n break\n }\n }\n\n // If we have an exact match, check if it's within bounds\n if (hasExact) {\n if (lowerBound) {\n if (\n lowerInclusive ?\n lt(hasExact, lowerBound)\n : lte(hasExact, lowerBound)\n ) {\n return false\n }\n }\n if (upperBound) {\n if (\n upperInclusive ?\n gt(hasExact, upperBound)\n : gte(hasExact, upperBound)\n ) {\n return false\n }\n }\n return true\n }\n\n // Check if lower bound is less than or equal to upper bound\n if (lowerBound && upperBound) {\n if (gt(lowerBound, upperBound)) return false\n if (\n eq(lowerBound, upperBound) &&\n !(lowerInclusive && upperInclusive)\n )\n return false\n }\n\n return true\n}\n"]}
{
"type": "module"
}
import { Comparator } from './comparator.ts';
import type { Version } from './version.ts';
export declare const isRange: (range: unknown) => range is Range;
/**
* A representation of a semver range, used to test versions.
*
* Includes a set of comparators representing the `||`-separated
* sections of the range string
*/
export declare class Range {
#private;
/** raw string used to create this Range */
raw: string;
/** true if the range is `*` */
isAny: boolean;
/** true if the range is a single semver version */
isSingle: boolean;
/** true if the range cannot match anything */
/**
* set of {@link Comparator} objects representing the `||`-separated sections
* of the range. If at least one of these matches, then the version is a
* match.
*/
set: Comparator[];
/** true if all prerelease versions should be included */
includePrerelease: boolean;
constructor(range: string, includePrerelease?: boolean);
/**
* test a {@link Version} against the range
*/
test(v: Version): boolean;
/** return the simplified canonical form of this range */
toString(): string;
}
//# sourceMappingURL=range.d.ts.map
{"version":3,"file":"range.d.ts","sourceRoot":"","sources":["../../src/range.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAG3C,eAAO,MAAM,OAAO,UAAW,OAAO,KAAG,KAAK,IAAI,KAWjD,CAAA;AAED;;;;;GAKG;AACH,qBAAa,KAAK;;IAChB,2CAA2C;IAC3C,GAAG,EAAE,MAAM,CAAA;IAEX,+BAA+B;IAC/B,KAAK,EAAE,OAAO,CAAA;IAEd,mDAAmD;IACnD,QAAQ,EAAE,OAAO,CAAA;IAEjB,8CAA8C;IAE9C;;;;OAIG;IACH,GAAG,EAAE,UAAU,EAAE,CAAK;IAEtB,yDAAyD;IACzD,iBAAiB,EAAE,OAAO,CAAA;gBAKd,KAAK,EAAE,MAAM,EAAE,iBAAiB,UAAQ;IA+CpD;;OAEG;IACH,IAAI,CAAC,CAAC,EAAE,OAAO;IAIf,yDAAyD;IACzD,QAAQ;CAST"}
import { fastSplit } from '@vltpkg/fast-split';
import { Comparator } from "./comparator.js";
import { asError } from '@vltpkg/types';
export const isRange = (range) => {
return (range instanceof Range ||
(typeof range === 'object' &&
range !== null &&
'raw' in range &&
typeof range.raw === 'string' &&
'set' in range &&
Array.isArray(range.set) &&
range.set.every(c => c instanceof Comparator)));
};
/**
* A representation of a semver range, used to test versions.
*
* Includes a set of comparators representing the `||`-separated
* sections of the range string
*/
export class Range {
/** raw string used to create this Range */
raw;
/** true if the range is `*` */
isAny;
/** true if the range is a single semver version */
isSingle;
/** true if the range cannot match anything */
/**
* set of {@link Comparator} objects representing the `||`-separated sections
* of the range. If at least one of these matches, then the version is a
* match.
*/
set = [];
/** true if all prerelease versions should be included */
includePrerelease;
/** cached toString */
#toString;
constructor(range, includePrerelease = false) {
this.raw = range;
this.includePrerelease = includePrerelease;
this.isAny = false;
let isFirst = true;
this.isSingle = false;
const comparatorErrors = [];
fastSplit(range, '||', -1, part => {
if (this.isAny)
return;
const cmp = this.#maybeComparator(part, this.includePrerelease);
if (cmp instanceof Error) {
comparatorErrors.push(cmp);
return;
}
if (cmp.isAny) {
this.set = [cmp];
this.isAny = true;
return;
}
this.set.push(cmp);
if (!isFirst)
this.isSingle = false;
else if (Array.isArray(cmp.tuples) &&
cmp.tuples.length === 1 &&
Array.isArray(cmp.tuples[0]) &&
cmp.tuples[0][0] === '') {
this.isSingle = true;
}
isFirst = false;
});
if (!this.set.length && comparatorErrors.length) {
if (comparatorErrors.length === 1 && comparatorErrors[0]) {
throw comparatorErrors[0];
}
throw new AggregateError(comparatorErrors);
}
}
#maybeComparator(part, includePrerelease) {
try {
return new Comparator(part, includePrerelease);
}
catch (er) {
return asError(er);
}
}
/**
* test a {@link Version} against the range
*/
test(v) {
return this.set.some(c => c.test(v));
}
/** return the simplified canonical form of this range */
toString() {
if (this.#toString)
return this.#toString;
if (this.isSingle) {
this.#toString = String(this.set[0]);
return this.#toString;
}
this.#toString = this.set.map(c => String(c)).join(' || ');
return this.#toString;
}
}
//# sourceMappingURL=range.js.map
{"version":3,"file":"range.js","sourceRoot":"","sources":["../../src/range.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAE5C,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAEvC,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,KAAc,EAAkB,EAAE;IACxD,OAAO,CACL,KAAK,YAAY,KAAK;QACtB,CAAC,OAAO,KAAK,KAAK,QAAQ;YACxB,KAAK,KAAK,IAAI;YACd,KAAK,IAAI,KAAK;YACd,OAAO,KAAK,CAAC,GAAG,KAAK,QAAQ;YAC7B,KAAK,IAAI,KAAK;YACd,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC;YACxB,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,YAAY,UAAU,CAAC,CAAC,CACjD,CAAA;AACH,CAAC,CAAA;AAED;;;;;GAKG;AACH,MAAM,OAAO,KAAK;IAChB,2CAA2C;IAC3C,GAAG,CAAQ;IAEX,+BAA+B;IAC/B,KAAK,CAAS;IAEd,mDAAmD;IACnD,QAAQ,CAAS;IAEjB,8CAA8C;IAE9C;;;;OAIG;IACH,GAAG,GAAiB,EAAE,CAAA;IAEtB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AI,CAAC,MAAM,CAAC,CAAA;QAC1D,OAAO,IAAI,CAAC,SAAS,CAAA;IACvB,CAAC;CACF","sourcesContent":["import { fastSplit } from '@vltpkg/fast-split'\nimport { Comparator } from './comparator.ts'\nimport type { Version } from './version.ts'\nimport { asError } from '@vltpkg/types'\n\nexport const isRange = (range: unknown): range is Range => {\n return (\n range instanceof Range ||\n (typeof range === 'object' &&\n range !== null &&\n 'raw' in range &&\n typeof range.raw === 'string' &&\n 'set' in range &&\n Array.isArray(range.set) &&\n range.set.every(c => c instanceof Comparator))\n )\n}\n\n/**\n * A representation of a semver range, used to test versions.\n *\n * Includes a set of comparators representing the `||`-separated\n * sections of the range string\n */\nexport class Range {\n /** raw string used to create this Range */\n raw: string\n\n /** true if the range is `*` */\n isAny: boolean\n\n /** true if the range is a single semver version */\n isSingle: boolean\n\n /** true if the range cannot match anything */\n\n /**\n * set of {@link Comparator} objects representing the `||`-separated sections\n * of the range. If at least one of these matches, then the version is a\n * match.\n */\n set: Comparator[] = []\n\n /** true if all prerelease versions should be included */\n includePrerelease: boolean\n\n /** cached toString */\n #toString?: string\n\n constructor(range: string, includePrerelease = false) {\n this.raw = range\n this.includePrerelease = includePrerelease\n this.isAny = false\n let isFirst = true\n this.isSingle = false\n const comparatorErrors: Error[] = []\n fastSplit(range, '||', -1, part => {\n if (this.isAny) return\n const cmp = this.#maybeComparator(part, this.includePrerelease)\n if (cmp instanceof Error) {\n comparatorErrors.push(cmp)\n return\n }\n if (cmp.isAny) {\n this.set = [cmp]\n this.isAny = true\n return\n }\n this.set.push(cmp)\n if (!isFirst) this.isSingle = false\n else if (\n Array.isArray(cmp.tuples) &&\n cmp.tuples.length === 1 &&\n Array.isArray(cmp.tuples[0]) &&\n cmp.tuples[0][0] === ''\n ) {\n this.isSingle = true\n }\n isFirst = false\n })\n if (!this.set.length && comparatorErrors.length) {\n if (comparatorErrors.length === 1 && comparatorErrors[0]) {\n throw comparatorErrors[0]\n }\n throw new AggregateError(comparatorErrors)\n }\n }\n\n #maybeComparator(part: string, includePrerelease: boolean) {\n try {\n return new Comparator(part, includePrerelease)\n } catch (er) {\n return asError(er)\n }\n }\n\n /**\n * test a {@link Version} against the range\n */\n test(v: Version) {\n return this.set.some(c => c.test(v))\n }\n\n /** return the simplified canonical form of this range */\n toString() {\n if (this.#toString) return this.#toString\n if (this.isSingle) {\n this.#toString = String(this.set[0])\n return this.#toString\n }\n this.#toString = this.set.map(c => String(c)).join(' || ')\n return this.#toString\n }\n}\n"]}
import type { Range } from './range.ts';
/**
* Values of valid increment types.
*/
export declare const versionIncrements: readonly ["major", "minor", "patch", "pre", "premajor", "preminor", "prepatch", "prerelease"];
/**
* Types of incrementing supported by {@link Version#inc}
*/
export type IncrementType = (typeof versionIncrements)[number];
/**
* A parsed object representation of a SemVer version string
*
* This is a bit less forgiving than node-semver, in that prerelease versions
* MUST start with '-'. Otherwise, the allowed syntax is identical.
*/
export declare class Version {
/** raw string provided to create this Version */
raw: string;
/** major version number */
major: number;
/** minor version number */
minor: number;
/** patch version number */
patch: number;
/**
* List of `'.'`-separated strings and numbers indicating that this
* version is a prerelease.
*
* This is undefined if the version does not have a prerelease section.
*/
prerelease?: (number | string)[];
/**
* List of `'.'`-separated strings in the `build` section.
*
* This is undefined if the version does not have a build.
*/
build?: string[];
/** Canonical strict form of this version */
toString(): string;
/** Generate a `Version` object from a SemVer string */
static parse(version: string): Version;
constructor(version: string, major: number, minor: number, patch: number, prerelease: string | undefined, build: string | undefined);
/**
* Return 1 if this is > the provided version, -1 if we're less, or 0 if
* they are equal.
*
* No special handling for prerelease versions, this is just a precedence
* comparison.
*
* This can be used to sort a list of versions by precedence:
*
* ```ts
* const versions: Version[] = getVersionsSomehow()
* const sorted = versions.sort((a, b) => a.compare(b))
* ```
*/
compare(v: Version): -1 | 0 | 1;
/**
* The inverse of compare, for sorting version lists in reverse order
*/
rcompare(v: Version): number;
/** true if this version is > the argument */
greaterThan(v: Version): boolean;
/** true if this version is >= the argument */
greaterThanEqual(v: Version): boolean;
/** true if this version is < the argument */
lessThan(v: Version): boolean;
/** true if this version is &lt;= the argument */
lessThanEqual(v: Version): boolean;
/** true if these two versions have equal SemVer precedence */
equals(v: Version): boolean;
/** just compare the M.m.p parts of the version */
tupleEquals(v: Version): boolean;
/** true if this version satisfies the range */
satisfies(r: Range): boolean;
/**
* Increment the version in place, in the manner specified.
*
* Part behaviors:
*
* - `'major'` If the version is a `M.0.0-...` version with a prerelease, then
* simply drop the prerelease. Otherwise, set the minor and patch to 0, and
* increment the major. So `1.0.0-beta` becomes `1.0.0`, and `1.2.3` becomes
* `2.0.0`
*
* - `'minor'` If the version is a `M.m.0-...` version with a prerelease, then
* simply drop the prerelease. Otherwise, set the patch to 0, and increment the
* minor. So `1.2.0-beta` becomes `1.2.0`, and `1.2.3` becomes `1.3.0`.
*
* - `'patch'` If the version has a prerelease, then simply drop the
* prerelease. Otherwise, increment the patch value. So `1.2.3-beta` becomes
* `1.2.3` and `1.2.3` becomes `1.2.4`.
*
* - `'premajor'` Set the patch and minor versions to `0`, increment the major
* version, and add a prerelease, using the optional identifier.
*
* - `'preminor'` Set the patch version to `0`, increment the minor version,
* and add a prerelease, using the optional identifier.
*
* - `'prepatch'` If a prerelease is already present, increment the patch
* version, otherwise leave it untouched, and add a prerelease, using the
* optional identifier.
*
* - `'prerelease'` If a prerelease version is present, then behave the same as
* `'prepatch'`. Otherwise, add a prerelease, using the optional identifier.
*
* - `'pre'` This is mostly for use by the other prerelease incrementers.
*
* - If a prerelease identifier is provided:
*
* Update that named portion of the prerelease. For example,
* `inc('1.2.3-beta.4', 'pre', 'beta')` would result in `1.2.3-beta.5`.
*
* If there is no prerelease identifier by that name, then replace the
* prerelease with `[name]`. So `inc('1.2.3-alpha.4', 'pre', 'beta')`
* would result in `1.2.3-beta`.
*
* If the prerelease identifer is present, but has no numeric value
* following it, then add `0`. So `inc('1.2.3-beta', 'pre', 'beta')`
* would result in `1.2.3-beta.0`.
*
* - If no prerelease identifier is provided:
*
* If there is no current prerelease, then set the prerelease to `0`. So,
* `inc('1.2.3', 'pre')` becomes `1.2.3-0`.
*
* If the last item in the prerelease is numeric, then increment it. So,
* `inc('1.2.3-beta.3', 'pre')` becomes `1.2.3-beta.4`.
*/
inc(part: IncrementType, prereleaseIdentifier?: string): this;
}
//# sourceMappingURL=version.d.ts.map
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AA2CvC;;GAEG;AACH,eAAO,MAAM,iBAAiB,+FASpB,CAAA;AAEV;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAA;AAE9D;;;;;GAKG;AACH,qBAAa,OAAO;IAClB,iDAAiD;IACjD,GAAG,EAAE,MAAM,CAAA;IAEX,4BAA4B;IAC5B,KAAK,EAAE,MAAM,CAAA;IACb,2BAA2B;IAC3B,KAAK,EAAE,MAAM,CAAA;IACb,2BAA2B;IAC3B,KAAK,EAAE,MAAM,CAAA;IACb;;;;;OAKG;IACH,UAAU,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAA;IAChC;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;IAEhB,4CAA4C;IAC5C,QAAQ;IAMR,uDAAuD;IACvD,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,MAAM;gBA2C1B,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,MAAM,GAAG,SAAS,EAC9B,KAAK,EAAE,MAAM,GAAG,SAAS;IA+B3B;;;;;;;;;;;;;OAaG;IACH,OAAO,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC;IAiC/B;;OAEG;IACH,QAAQ,CAAC,CAAC,EAAE,OAAO;IAInB,6CAA6C;IAC7C,WAAW,CAAC,CAAC,EAAE,OAAO;IAItB,8CAA8C;IAC9C,gBAAgB,CAAC,CAAC,EAAE,OAAO;IAI3B,6CAA6C;IAC7C,QAAQ,CAAC,CAAC,EAAE,OAAO;IAInB,iDAAiD;IACjD,aAAa,CAAC,CAAC,EAAE,OAAO;IAIxB,8DAA8D;IAC9D,MAAM,CAAC,CAAC,EAAE,OAAO;IAIjB,kDAAkD;IAClD,WAAW,CAAC,CAAC,EAAE,OAAO;IAQtB,+CAA+C;IAC/C,SAAS,CAAC,CAAC,EAAE,KAAK;IAIlB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAqDG;IACH,GAAG,CAAC,IAAI,EAAE,aAAa,EAAE,oBAAoB,CAAC,EAAE,MAAM;CAiHvD"}
import { syntaxError, typeError } from '@vltpkg/error-cause';
import { fastSplit } from '@vltpkg/fast-split';
const maybeNumber = (s) => {
if (!/^[0-9]+$/.test(s))
return s;
const n = Number(s);
return n <= Number.MAX_SAFE_INTEGER ? n : s;
};
const safeNumber = (s, version, field) => {
const n = Number(s);
if (n > Number.MAX_SAFE_INTEGER) {
throw invalidVersion(version, `invalid ${field}, must be <= ${Number.MAX_SAFE_INTEGER}`);
}
return n;
};
const re = {
prefix: /^[ v=]+/,
main: /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)/,
prerelease: /-([0-9a-zA-Z_.-]+)(?:$|\+)/,
build: /\+([0-9a-zA-Z_.-]+)$/,
full: /^[ v=]*(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9a-zA-Z_.-]+))?(?:\+([0-9a-zA-Z_.-]+))?$/,
};
const invalidVersion = (version, message) => {
const er = syntaxError(`invalid version: ${message}`, { version }, Version);
return er;
};
/**
* Values of valid increment types.
*/
export const versionIncrements = [
'major',
'minor',
'patch',
'pre',
'premajor',
'preminor',
'prepatch',
'prerelease',
];
/**
* A parsed object representation of a SemVer version string
*
* This is a bit less forgiving than node-semver, in that prerelease versions
* MUST start with '-'. Otherwise, the allowed syntax is identical.
*/
export class Version {
/** raw string provided to create this Version */
raw;
/** major version number */
major;
/** minor version number */
minor;
/** patch version number */
patch;
/**
* List of `'.'`-separated strings and numbers indicating that this
* version is a prerelease.
*
* This is undefined if the version does not have a prerelease section.
*/
prerelease;
/**
* List of `'.'`-separated strings in the `build` section.
*
* This is undefined if the version does not have a build.
*/
build;
/** Canonical strict form of this version */
toString() {
return `${this.major}.${this.minor}.${this.patch}${this.prerelease ? '-' + this.prerelease.join('.') : ''}${this.build ? '+' + this.build.join('.') : ''}`;
}
/** Generate a `Version` object from a SemVer string */
static parse(version) {
version = version.replace(re.prefix, '').trim();
if (version.length > 256) {
throw invalidVersion(version, 'must be less than 256 characters');
}
const parsed = re.full.exec(version);
if (!parsed) {
const main = re.main.exec(version);
if (!main) {
throw invalidVersion(version, 'no Major.minor.patch tuple present');
}
else {
throw invalidVersion(version, 'invalid build or patch section');
}
}
const [_, major_, minor_, patch_, prerelease, build] = parsed;
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const major = safeNumber(major_, version, 'major');
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const minor = safeNumber(minor_, version, 'minor');
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const patch = safeNumber(patch_, version, 'patch');
return new Version(version, major, minor, patch, prerelease, build);
}
constructor(version, major, minor, patch, prerelease, build) {
this.raw = version;
this.major = major;
this.minor = minor;
this.patch = patch;
// has prerelease and/or build
if (prerelease) {
this.prerelease = fastSplit(prerelease, '.', -1, c => {
if (!c) {
throw invalidVersion(version, 'invalid prerelease, empty identifiers not allowed');
}
return maybeNumber(c);
});
}
if (build) {
this.build = fastSplit(build, '.', -1, c => {
if (!c) {
throw invalidVersion(version, 'invalid build metadata, empty identifiers not allowed');
}
});
}
}
/**
* Return 1 if this is > the provided version, -1 if we're less, or 0 if
* they are equal.
*
* No special handling for prerelease versions, this is just a precedence
* comparison.
*
* This can be used to sort a list of versions by precedence:
*
* ```ts
* const versions: Version[] = getVersionsSomehow()
* const sorted = versions.sort((a, b) => a.compare(b))
* ```
*/
compare(v) {
if (this.major > v.major)
return 1;
if (this.major < v.major)
return -1;
if (this.minor > v.minor)
return 1;
if (this.minor < v.minor)
return -1;
if (this.patch > v.patch)
return 1;
if (this.patch < v.patch)
return -1;
// main tuple is equal now
// if the version has no pr, we're definitely less than or equal to
if (!v.prerelease?.length)
return !this.prerelease?.length ? 0 : -1;
// v has a pr. if we don't, we're > it
if (!this.prerelease?.length)
return 1;
// we both have prereleases
const len = Math.max(this.prerelease.length, v.prerelease.length);
const me = this.prerelease;
const thee = v.prerelease;
for (let i = 0; i < len; i++) {
const m = me[i];
const t = thee[i];
if (m === t)
continue;
// having a field is > not having it
if (t === undefined)
return 1;
if (m === undefined)
return -1;
// string parts are higher precedence than
if (typeof m !== typeof t) {
return typeof m === 'string' ? 1 : -1;
}
return m > t ? 1 : -1;
}
return 0;
}
/**
* The inverse of compare, for sorting version lists in reverse order
*/
rcompare(v) {
return -1 * this.compare(v);
}
/** true if this version is > the argument */
greaterThan(v) {
return this.compare(v) === 1;
}
/** true if this version is >= the argument */
greaterThanEqual(v) {
return this.compare(v) > -1;
}
/** true if this version is < the argument */
lessThan(v) {
return this.compare(v) === -1;
}
/** true if this version is &lt;= the argument */
lessThanEqual(v) {
return this.compare(v) < 1;
}
/** true if these two versions have equal SemVer precedence */
equals(v) {
return this.compare(v) === 0;
}
/** just compare the M.m.p parts of the version */
tupleEquals(v) {
return (this.major === v.major &&
this.minor === v.minor &&
this.patch === v.patch);
}
/** true if this version satisfies the range */
satisfies(r) {
return r.test(this);
}
/**
* Increment the version in place, in the manner specified.
*
* Part behaviors:
*
* - `'major'` If the version is a `M.0.0-...` version with a prerelease, then
* simply drop the prerelease. Otherwise, set the minor and patch to 0, and
* increment the major. So `1.0.0-beta` becomes `1.0.0`, and `1.2.3` becomes
* `2.0.0`
*
* - `'minor'` If the version is a `M.m.0-...` version with a prerelease, then
* simply drop the prerelease. Otherwise, set the patch to 0, and increment the
* minor. So `1.2.0-beta` becomes `1.2.0`, and `1.2.3` becomes `1.3.0`.
*
* - `'patch'` If the version has a prerelease, then simply drop the
* prerelease. Otherwise, increment the patch value. So `1.2.3-beta` becomes
* `1.2.3` and `1.2.3` becomes `1.2.4`.
*
* - `'premajor'` Set the patch and minor versions to `0`, increment the major
* version, and add a prerelease, using the optional identifier.
*
* - `'preminor'` Set the patch version to `0`, increment the minor version,
* and add a prerelease, using the optional identifier.
*
* - `'prepatch'` If a prerelease is already present, increment the patch
* version, otherwise leave it untouched, and add a prerelease, using the
* optional identifier.
*
* - `'prerelease'` If a prerelease version is present, then behave the same as
* `'prepatch'`. Otherwise, add a prerelease, using the optional identifier.
*
* - `'pre'` This is mostly for use by the other prerelease incrementers.
*
* - If a prerelease identifier is provided:
*
* Update that named portion of the prerelease. For example,
* `inc('1.2.3-beta.4', 'pre', 'beta')` would result in `1.2.3-beta.5`.
*
* If there is no prerelease identifier by that name, then replace the
* prerelease with `[name]`. So `inc('1.2.3-alpha.4', 'pre', 'beta')`
* would result in `1.2.3-beta`.
*
* If the prerelease identifer is present, but has no numeric value
* following it, then add `0`. So `inc('1.2.3-beta', 'pre', 'beta')`
* would result in `1.2.3-beta.0`.
*
* - If no prerelease identifier is provided:
*
* If there is no current prerelease, then set the prerelease to `0`. So,
* `inc('1.2.3', 'pre')` becomes `1.2.3-0`.
*
* If the last item in the prerelease is numeric, then increment it. So,
* `inc('1.2.3-beta.3', 'pre')` becomes `1.2.3-beta.4`.
*/
inc(part, prereleaseIdentifier) {
switch (part) {
case 'premajor':
this.prerelease = undefined;
this.patch = 0;
this.minor = 0;
this.major++;
this.inc('pre', prereleaseIdentifier);
break;
case 'preminor':
this.prerelease = undefined;
this.patch = 0;
this.minor++;
this.inc('pre', prereleaseIdentifier);
break;
case 'prepatch':
this.prerelease = undefined;
this.inc('patch');
this.inc('pre', prereleaseIdentifier);
break;
case 'prerelease':
if (!this.prerelease?.length)
this.inc('patch', prereleaseIdentifier);
this.inc('pre', prereleaseIdentifier);
break;
case 'pre': {
// this is a bit different than node-semver's logic, but simpler
// always do zero-based incrementing, and either bump the existing
// numeric pr value, or add a `.0` after the identifier.
if (!prereleaseIdentifier) {
if (!this.prerelease?.length) {
this.prerelease = [0];
break;
}
const last = this.prerelease[this.prerelease.length - 1];
if (typeof last === 'number') {
this.prerelease[this.prerelease.length - 1] = last + 1;
}
else {
this.prerelease.push(0);
}
break;
}
if (!this.prerelease?.length) {
this.prerelease = [prereleaseIdentifier];
break;
}
const i = this.prerelease.indexOf(maybeNumber(prereleaseIdentifier));
if (i === -1) {
this.prerelease = [prereleaseIdentifier];
break;
}
const baseValue = this.prerelease[i + 1];
if (typeof baseValue === 'number') {
this.prerelease[i + 1] = baseValue + 1;
break;
}
if (i === this.prerelease.length - 1) {
this.prerelease.push(0);
break;
}
this.prerelease.splice(i + 1, 0, 0);
break;
}
case 'major':
if (!this.prerelease?.length || this.minor || this.patch)
this.major++;
this.prerelease = undefined;
this.patch = 0;
this.minor = 0;
break;
case 'minor':
if (!this.prerelease?.length || this.patch)
this.minor++;
this.prerelease = undefined;
this.patch = 0;
break;
case 'patch':
if (!this.prerelease?.length)
this.patch++;
this.prerelease = undefined;
break;
default:
throw typeError('Invalid increment identifier', {
version: this,
found: part,
validOptions: [
'major',
'minor',
'patch',
'premajor',
'preminor',
'prepatch',
'prerelease',
'pre',
],
}, this.inc);
}
this.raw = this.toString();
return this;
}
}
//# sourceMappingURL=version.js.map
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAG9C,MAAM,WAAW,GAAG,CAAC,CAAS,EAAmB,EAAE;IACjD,IAAI,CAA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AY,EAAE;wBACZ,OAAO;wBACP,OAAO;wBACP,OAAO;wBACP,UAAU;wBACV,UAAU;wBACV,UAAU;wBACV,YAAY;wBACZ,KAAK;qBACN;iBACF,EACD,IAAI,CAAC,GAAG,CACT,CAAA;QACL,CAAC;QAED,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAA;QAC1B,OAAO,IAAI,CAAA;IACb,CAAC;CACF","sourcesContent":["import { syntaxError, typeError } from '@vltpkg/error-cause'\nimport { fastSplit } from '@vltpkg/fast-split'\nimport type { Range } from './range.ts'\n\nconst maybeNumber = (s: string): number | string => {\n if (!/^[0-9]+$/.test(s)) return s\n const n = Number(s)\n return n <= Number.MAX_SAFE_INTEGER ? n : s\n}\n\nconst safeNumber = (\n s: string,\n version: string,\n field: string,\n): number => {\n const n = Number(s)\n if (n > Number.MAX_SAFE_INTEGER) {\n throw invalidVersion(\n version,\n `invalid ${field}, must be <= ${Number.MAX_SAFE_INTEGER}`,\n )\n }\n return n\n}\n\nconst re = {\n prefix: /^[ v=]+/,\n main: /^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)/,\n prerelease: /-([0-9a-zA-Z_.-]+)(?:$|\\+)/,\n build: /\\+([0-9a-zA-Z_.-]+)$/,\n full: /^[ v=]*(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-([0-9a-zA-Z_.-]+))?(?:\\+([0-9a-zA-Z_.-]+))?$/,\n} as const\n\nconst invalidVersion = (\n version: string,\n message: string,\n): SyntaxError => {\n const er = syntaxError(\n `invalid version: ${message}`,\n { version },\n Version,\n )\n return er\n}\n\n/**\n * Values of valid increment types.\n */\nexport const versionIncrements = [\n 'major',\n 'minor',\n 'patch',\n 'pre',\n 'premajor',\n 'preminor',\n 'prepatch',\n 'prerelease',\n] as const\n\n/**\n * Types of incrementing supported by {@link Version#inc}\n */\nexport type IncrementType = (typeof versionIncrements)[number]\n\n/**\n * A parsed object representation of a SemVer version string\n *\n * This is a bit less forgiving than node-semver, in that prerelease versions\n * MUST start with '-'. Otherwise, the allowed syntax is identical.\n */\nexport class Version {\n /** raw string provided to create this Version */\n raw: string\n\n /** major version number */\n major: number\n /** minor version number */\n minor: number\n /** patch version number */\n patch: number\n /**\n * List of `'.'`-separated strings and numbers indicating that this\n * version is a prerelease.\n *\n * This is undefined if the version does not have a prerelease section.\n */\n prerelease?: (number | string)[]\n /**\n * List of `'.'`-separated strings in the `build` section.\n *\n * This is undefined if the version does not have a build.\n */\n build?: string[]\n\n /** Canonical strict form of this version */\n toString() {\n return `${this.major}.${this.minor}.${this.patch}${\n this.prerelease ? '-' + this.prerelease.join('.') : ''\n }${this.build ? '+' + this.build.join('.') : ''}`\n }\n\n /** Generate a `Version` object from a SemVer string */\n static parse(version: string) {\n version = version.replace(re.prefix, '').trim()\n if (version.length > 256) {\n throw invalidVersion(\n version,\n 'must be less than 256 characters',\n )\n }\n\n const parsed = re.full.exec(version)\n if (!parsed) {\n const main = re.main.exec(version)\n if (!main) {\n throw invalidVersion(\n version,\n 'no Major.minor.patch tuple present',\n )\n } else {\n throw invalidVersion(\n version,\n 'invalid build or patch section',\n )\n }\n }\n const [_, major_, minor_, patch_, prerelease, build] = parsed\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const major = safeNumber(major_!, version, 'major')\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const minor = safeNumber(minor_!, version, 'minor')\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const patch = safeNumber(patch_!, version, 'patch')\n\n return new Version(\n version,\n major,\n minor,\n patch,\n prerelease,\n build,\n )\n }\n\n constructor(\n version: string,\n major: number,\n minor: number,\n patch: number,\n prerelease: string | undefined,\n build: string | undefined,\n ) {\n this.raw = version\n this.major = major\n this.minor = minor\n this.patch = patch\n\n // has prerelease and/or build\n if (prerelease) {\n this.prerelease = fastSplit(prerelease, '.', -1, c => {\n if (!c) {\n throw invalidVersion(\n version,\n 'invalid prerelease, empty identifiers not allowed',\n )\n }\n return maybeNumber(c)\n })\n }\n if (build) {\n this.build = fastSplit(build, '.', -1, c => {\n if (!c) {\n throw invalidVersion(\n version,\n 'invalid build metadata, empty identifiers not allowed',\n )\n }\n })\n }\n }\n\n /**\n * Return 1 if this is > the provided version, -1 if we're less, or 0 if\n * they are equal.\n *\n * No special handling for prerelease versions, this is just a precedence\n * comparison.\n *\n * This can be used to sort a list of versions by precedence:\n *\n * ```ts\n * const versions: Version[] = getVersionsSomehow()\n * const sorted = versions.sort((a, b) => a.compare(b))\n * ```\n */\n compare(v: Version): -1 | 0 | 1 {\n if (this.major > v.major) return 1\n if (this.major < v.major) return -1\n if (this.minor > v.minor) return 1\n if (this.minor < v.minor) return -1\n if (this.patch > v.patch) return 1\n if (this.patch < v.patch) return -1\n // main tuple is equal now\n // if the version has no pr, we're definitely less than or equal to\n if (!v.prerelease?.length)\n return !this.prerelease?.length ? 0 : -1\n // v has a pr. if we don't, we're > it\n if (!this.prerelease?.length) return 1\n // we both have prereleases\n const len = Math.max(this.prerelease.length, v.prerelease.length)\n const me = this.prerelease\n const thee = v.prerelease\n for (let i = 0; i < len; i++) {\n const m = me[i]\n const t = thee[i]\n if (m === t) continue\n // having a field is > not having it\n if (t === undefined) return 1\n if (m === undefined) return -1\n // string parts are higher precedence than\n if (typeof m !== typeof t) {\n return typeof m === 'string' ? 1 : -1\n }\n return m > t ? 1 : -1\n }\n return 0\n }\n\n /**\n * The inverse of compare, for sorting version lists in reverse order\n */\n rcompare(v: Version) {\n return -1 * this.compare(v)\n }\n\n /** true if this version is > the argument */\n greaterThan(v: Version) {\n return this.compare(v) === 1\n }\n\n /** true if this version is >= the argument */\n greaterThanEqual(v: Version) {\n return this.compare(v) > -1\n }\n\n /** true if this version is < the argument */\n lessThan(v: Version) {\n return this.compare(v) === -1\n }\n\n /** true if this version is &lt;= the argument */\n lessThanEqual(v: Version) {\n return this.compare(v) < 1\n }\n\n /** true if these two versions have equal SemVer precedence */\n equals(v: Version) {\n return this.compare(v) === 0\n }\n\n /** just compare the M.m.p parts of the version */\n tupleEquals(v: Version) {\n return (\n this.major === v.major &&\n this.minor === v.minor &&\n this.patch === v.patch\n )\n }\n\n /** true if this version satisfies the range */\n satisfies(r: Range) {\n return r.test(this)\n }\n\n /**\n * Increment the version in place, in the manner specified.\n *\n * Part behaviors:\n *\n * - `'major'` If the version is a `M.0.0-...` version with a prerelease, then\n * simply drop the prerelease. Otherwise, set the minor and patch to 0, and\n * increment the major. So `1.0.0-beta` becomes `1.0.0`, and `1.2.3` becomes\n * `2.0.0`\n *\n * - `'minor'` If the version is a `M.m.0-...` version with a prerelease, then\n * simply drop the prerelease. Otherwise, set the patch to 0, and increment the\n * minor. So `1.2.0-beta` becomes `1.2.0`, and `1.2.3` becomes `1.3.0`.\n *\n * - `'patch'` If the version has a prerelease, then simply drop the\n * prerelease. Otherwise, increment the patch value. So `1.2.3-beta` becomes\n * `1.2.3` and `1.2.3` becomes `1.2.4`.\n *\n * - `'premajor'` Set the patch and minor versions to `0`, increment the major\n * version, and add a prerelease, using the optional identifier.\n *\n * - `'preminor'` Set the patch version to `0`, increment the minor version,\n * and add a prerelease, using the optional identifier.\n *\n * - `'prepatch'` If a prerelease is already present, increment the patch\n * version, otherwise leave it untouched, and add a prerelease, using the\n * optional identifier.\n *\n * - `'prerelease'` If a prerelease version is present, then behave the same as\n * `'prepatch'`. Otherwise, add a prerelease, using the optional identifier.\n *\n * - `'pre'` This is mostly for use by the other prerelease incrementers.\n *\n * - If a prerelease identifier is provided:\n *\n * Update that named portion of the prerelease. For example,\n * `inc('1.2.3-beta.4', 'pre', 'beta')` would result in `1.2.3-beta.5`.\n *\n * If there is no prerelease identifier by that name, then replace the\n * prerelease with `[name]`. So `inc('1.2.3-alpha.4', 'pre', 'beta')`\n * would result in `1.2.3-beta`.\n *\n * If the prerelease identifer is present, but has no numeric value\n * following it, then add `0`. So `inc('1.2.3-beta', 'pre', 'beta')`\n * would result in `1.2.3-beta.0`.\n *\n * - If no prerelease identifier is provided:\n *\n * If there is no current prerelease, then set the prerelease to `0`. So,\n * `inc('1.2.3', 'pre')` becomes `1.2.3-0`.\n *\n * If the last item in the prerelease is numeric, then increment it. So,\n * `inc('1.2.3-beta.3', 'pre')` becomes `1.2.3-beta.4`.\n */\n inc(part: IncrementType, prereleaseIdentifier?: string) {\n switch (part) {\n case 'premajor':\n this.prerelease = undefined\n this.patch = 0\n this.minor = 0\n this.major++\n this.inc('pre', prereleaseIdentifier)\n break\n\n case 'preminor':\n this.prerelease = undefined\n this.patch = 0\n this.minor++\n this.inc('pre', prereleaseIdentifier)\n break\n\n case 'prepatch':\n this.prerelease = undefined\n this.inc('patch')\n this.inc('pre', prereleaseIdentifier)\n break\n\n case 'prerelease':\n if (!this.prerelease?.length)\n this.inc('patch', prereleaseIdentifier)\n this.inc('pre', prereleaseIdentifier)\n break\n\n case 'pre': {\n // this is a bit different than node-semver's logic, but simpler\n // always do zero-based incrementing, and either bump the existing\n // numeric pr value, or add a `.0` after the identifier.\n if (!prereleaseIdentifier) {\n if (!this.prerelease?.length) {\n this.prerelease = [0]\n break\n }\n const last = this.prerelease[this.prerelease.length - 1]\n if (typeof last === 'number') {\n this.prerelease[this.prerelease.length - 1] = last + 1\n } else {\n this.prerelease.push(0)\n }\n break\n }\n if (!this.prerelease?.length) {\n this.prerelease = [prereleaseIdentifier]\n break\n }\n const i = this.prerelease.indexOf(\n maybeNumber(prereleaseIdentifier),\n )\n if (i === -1) {\n this.prerelease = [prereleaseIdentifier]\n break\n }\n const baseValue = this.prerelease[i + 1]\n if (typeof baseValue === 'number') {\n this.prerelease[i + 1] = baseValue + 1\n break\n }\n if (i === this.prerelease.length - 1) {\n this.prerelease.push(0)\n break\n }\n this.prerelease.splice(i + 1, 0, 0)\n break\n }\n\n case 'major':\n if (!this.prerelease?.length || this.minor || this.patch)\n this.major++\n this.prerelease = undefined\n this.patch = 0\n this.minor = 0\n break\n\n case 'minor':\n if (!this.prerelease?.length || this.patch) this.minor++\n this.prerelease = undefined\n this.patch = 0\n break\n\n case 'patch':\n if (!this.prerelease?.length) this.patch++\n this.prerelease = undefined\n break\n\n default:\n throw typeError(\n 'Invalid increment identifier',\n {\n version: this,\n found: part,\n validOptions: [\n 'major',\n 'minor',\n 'patch',\n 'premajor',\n 'preminor',\n 'prepatch',\n 'prerelease',\n 'pre',\n ],\n },\n this.inc,\n )\n }\n\n this.raw = this.toString()\n return this\n }\n}\n"]}