@helpers4/version 2.0.0-alpha.17 → 2.0.0-alpha.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/lib/index.d.ts +64 -1
- package/lib/index.js +14 -1
- package/lib/index.js.map +1 -1
- package/llms.txt +156 -9
- package/meta/api.json +161 -11
- package/meta/examples.json +35 -0
- package/package.json +3 -1
package/README.md
CHANGED
package/lib/index.d.ts
CHANGED
|
@@ -84,6 +84,40 @@ declare function parse(version: string): ParsedVersion;
|
|
|
84
84
|
declare function parse(version: undefined): undefined;
|
|
85
85
|
declare function parse(version: null): null;
|
|
86
86
|
|
|
87
|
+
/**
|
|
88
|
+
* This file is part of helpers4.
|
|
89
|
+
* Copyright (C) 2025 baxyz
|
|
90
|
+
* SPDX-License-Identifier: LGPL-3.0-or-later
|
|
91
|
+
*/
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Returns `true` when the version string has a prerelease suffix
|
|
95
|
+
* (i.e. contains a `-` after the core `MAJOR.MINOR.PATCH`).
|
|
96
|
+
*
|
|
97
|
+
* @param version - A semantic version string (e.g. `'2.0.0-alpha.1'`, `'1.0.0'`).
|
|
98
|
+
* @returns `true` if the version is a prerelease, `false` otherwise.
|
|
99
|
+
* @example
|
|
100
|
+
* isPrerelease('2.0.0-alpha.1') // true
|
|
101
|
+
* isPrerelease('1.0.0-rc.0') // true
|
|
102
|
+
* isPrerelease('1.0.0') // false
|
|
103
|
+
* isPrerelease('2.1.0') // false
|
|
104
|
+
* @since next
|
|
105
|
+
*/
|
|
106
|
+
declare function isPrerelease(version: string): boolean;
|
|
107
|
+
/**
|
|
108
|
+
* Returns `true` when the parsed version has at least one prerelease identifier.
|
|
109
|
+
*
|
|
110
|
+
* @param version - A {@link ParsedVersion} object (as returned by {@link parse}).
|
|
111
|
+
* @returns `true` if `version.prerelease` is non-empty, `false` otherwise.
|
|
112
|
+
* @example
|
|
113
|
+
* isPrerelease(parse('2.0.0-alpha.1')) // true
|
|
114
|
+
* isPrerelease(parse('1.0.0')) // false
|
|
115
|
+
* @since next
|
|
116
|
+
*/
|
|
117
|
+
declare function isPrerelease(version: ParsedVersion): boolean;
|
|
118
|
+
declare function isPrerelease(version: undefined): undefined;
|
|
119
|
+
declare function isPrerelease(version: null): null;
|
|
120
|
+
|
|
87
121
|
/**
|
|
88
122
|
* This file is part of helpers4.
|
|
89
123
|
* Copyright (C) 2025 baxyz
|
|
@@ -98,6 +132,35 @@ declare function parse(version: null): null;
|
|
|
98
132
|
*/
|
|
99
133
|
declare function satisfiesRange(version: string, range: string): boolean;
|
|
100
134
|
|
|
135
|
+
/**
|
|
136
|
+
* This file is part of helpers4.
|
|
137
|
+
* Copyright (C) 2025 baxyz
|
|
138
|
+
* SPDX-License-Identifier: LGPL-3.0-or-later
|
|
139
|
+
*/
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Reconstruct a semantic version string from a {@link ParsedVersion} object.
|
|
143
|
+
*
|
|
144
|
+
* This is the inverse of {@link parse}:
|
|
145
|
+
* `stringify(parse(v)) === stripV(v)` for any valid SemVer string `v`.
|
|
146
|
+
*
|
|
147
|
+
* @param parsed - A parsed semantic version object.
|
|
148
|
+
* @returns The reconstructed version string (without leading `v`).
|
|
149
|
+
* @example
|
|
150
|
+
* stringify({ major: 1, minor: 2, patch: 3, prerelease: [], build: [] })
|
|
151
|
+
* // => '1.2.3'
|
|
152
|
+
* @example
|
|
153
|
+
* stringify({ major: 2, minor: 0, patch: 0, prerelease: ['alpha', '1'], build: [] })
|
|
154
|
+
* // => '2.0.0-alpha.1'
|
|
155
|
+
* @example
|
|
156
|
+
* stringify({ major: 1, minor: 0, patch: 0, prerelease: ['beta'], build: ['exp', 'sha', '5114f85'] })
|
|
157
|
+
* // => '1.0.0-beta+exp.sha.5114f85'
|
|
158
|
+
* @since next
|
|
159
|
+
*/
|
|
160
|
+
declare function stringify(parsed: ParsedVersion): string;
|
|
161
|
+
declare function stringify(parsed: undefined): undefined;
|
|
162
|
+
declare function stringify(parsed: null): null;
|
|
163
|
+
|
|
101
164
|
/**
|
|
102
165
|
* This file is part of helpers4.
|
|
103
166
|
* Copyright (C) 2025 baxyz
|
|
@@ -125,5 +188,5 @@ declare function stripV(version: string): string;
|
|
|
125
188
|
declare function stripV(version: null): null;
|
|
126
189
|
declare function stripV(version: undefined): undefined;
|
|
127
190
|
|
|
128
|
-
export { compare, increment, parse, satisfiesRange, stripV };
|
|
191
|
+
export { compare, increment, isPrerelease, parse, satisfiesRange, stringify, stripV };
|
|
129
192
|
export type { ParsedVersion };
|
package/lib/index.js
CHANGED
|
@@ -113,6 +113,13 @@ function increment(version, type) {
|
|
|
113
113
|
return hasV ? `v${result}` : result;
|
|
114
114
|
}
|
|
115
115
|
//#endregion
|
|
116
|
+
//#region helpers/version/isPrerelease.ts
|
|
117
|
+
function isPrerelease(version) {
|
|
118
|
+
if (version === void 0 || version === null) return version;
|
|
119
|
+
if (typeof version === "string") return version.split("+")[0].includes("-");
|
|
120
|
+
return version.prerelease.length > 0;
|
|
121
|
+
}
|
|
122
|
+
//#endregion
|
|
116
123
|
//#region helpers/version/satisfiesRange.ts
|
|
117
124
|
/**
|
|
118
125
|
* This file is part of helpers4.
|
|
@@ -159,11 +166,17 @@ function compareVersionsSimple(version1, version2) {
|
|
|
159
166
|
return 0;
|
|
160
167
|
}
|
|
161
168
|
//#endregion
|
|
169
|
+
//#region helpers/version/stringify.ts
|
|
170
|
+
function stringify(parsed) {
|
|
171
|
+
if (parsed === void 0 || parsed === null) return parsed;
|
|
172
|
+
return `${`${parsed.major}.${parsed.minor}.${parsed.patch}`}${parsed.prerelease.length > 0 ? `-${parsed.prerelease.join(".")}` : ""}${parsed.build.length > 0 ? `+${parsed.build.join(".")}` : ""}`;
|
|
173
|
+
}
|
|
174
|
+
//#endregion
|
|
162
175
|
//#region helpers/version/stripV.ts
|
|
163
176
|
function stripV(version) {
|
|
164
177
|
return typeof version === "string" && version.startsWith("v") ? version.slice(1) : version;
|
|
165
178
|
}
|
|
166
179
|
//#endregion
|
|
167
|
-
export { compare, increment, parse, satisfiesRange, stripV };
|
|
180
|
+
export { compare, increment, isPrerelease, parse, satisfiesRange, stringify, stripV };
|
|
168
181
|
|
|
169
182
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../helpers/version/parse.ts","../../../helpers/version/compare.ts","../../../helpers/version/increment.ts","../../../helpers/version/satisfiesRange.ts","../../../helpers/version/stripV.ts"],"sourcesContent":["/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Represents a parsed semantic version according to SemVer 2.0.0 specification\n * @since 2.0.0\n */\nexport interface ParsedVersion {\n /** Major version number */\n major: number;\n /** Minor version number */\n minor: number;\n /** Patch version number */\n patch: number;\n /** Pre-release identifiers (e.g., ['alpha', '1'] for -alpha.1) */\n prerelease: string[];\n /** Build metadata identifiers (e.g., ['build', '123'] for +build.123) */\n build: string[];\n}\n\n/**\n * Parses a semantic version string into its components according to SemVer 2.0.0 specification\n *\n * Supports:\n * - Core version: MAJOR.MINOR.PATCH\n * - Pre-release: -alpha, -beta.1, -rc.1, -0.3.7, -x.7.z.92\n * - Build metadata: +build, +sha.abc123, +20130313144700\n * - Optional 'v' prefix (commonly used in git tags)\n *\n * @param version - Version string to parse\n * @returns Parsed version object with major, minor, patch, prerelease, and build\n * @example\n * parse('1.2.3') // { major: 1, minor: 2, patch: 3, prerelease: [], build: [] }\n * parse('v1.0.0-alpha.1') // { major: 1, minor: 0, patch: 0, prerelease: ['alpha', '1'], build: [] }\n * parse('2.0.0+build.123') // { major: 2, minor: 0, patch: 0, prerelease: [], build: ['build', '123'] }\n * parse('1.0.0-beta+exp.sha.5114f85') // { major: 1, minor: 0, patch: 0, prerelease: ['beta'], build: ['exp', 'sha', '5114f85'] }\n * @since 2.0.0\n */\nexport function parse(version: string): ParsedVersion;\nexport function parse(version: undefined): undefined;\nexport function parse(version: null): null;\nexport function parse(version: string | undefined | null): ParsedVersion | undefined | null {\n if (version === undefined || version === null) return version;\n // Remove optional 'v' prefix\n const normalized = version.replace(/^v/, '');\n\n // Split build metadata first (everything after +)\n const [versionWithPrerelease, buildString] = normalized.split('+');\n const build = buildString ? buildString.split('.') : [];\n\n // Split prerelease (everything after -)\n const [coreVersion, prereleaseString] = versionWithPrerelease.split('-');\n const prerelease = prereleaseString ? prereleaseString.split('.') : [];\n\n // Parse core version\n const parts = coreVersion.split('.').map(Number);\n\n return {\n major: parts[0] || 0,\n minor: parts[1] || 0,\n patch: parts[2] || 0,\n prerelease,\n build,\n };\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\nimport { parse } from './parse';\n\n/**\n * Compares two prerelease identifier arrays according to SemVer spec\n * Rules:\n * - Numeric identifiers are compared as integers\n * - Alphanumeric identifiers are compared lexically (ASCII)\n * - Numeric identifiers have lower precedence than alphanumeric\n * - A larger set of prerelease fields has higher precedence if all preceding are equal\n * @param pre1 - First prerelease array\n * @param pre2 - Second prerelease array\n * @returns -1, 0, or 1\n */\nfunction comparePrerelease(pre1: string[], pre2: string[]): number {\n // No prerelease has higher precedence than prerelease\n // e.g., 1.0.0 > 1.0.0-alpha\n if (pre1.length === 0 && pre2.length === 0) return 0;\n if (pre1.length === 0) return 1; // No prerelease > prerelease\n if (pre2.length === 0) return -1; // prerelease < no prerelease\n\n const maxLength = Math.max(pre1.length, pre2.length);\n\n for (let i = 0; i < maxLength; i++) {\n // A larger set has higher precedence if all preceding are equal\n if (i >= pre1.length) return -1;\n if (i >= pre2.length) return 1;\n\n const id1 = pre1[i];\n const id2 = pre2[i];\n\n const isNum1 = /^\\d+$/.test(id1);\n const isNum2 = /^\\d+$/.test(id2);\n\n // Both numeric: compare as integers\n if (isNum1 && isNum2) {\n const num1 = parseInt(id1, 10);\n const num2 = parseInt(id2, 10);\n if (num1 < num2) return -1;\n if (num1 > num2) return 1;\n // num1 === num2, continue to next identifier\n }\n // Numeric has lower precedence than alphanumeric\n else if (isNum1) {\n return -1;\n } else if (isNum2) {\n return 1;\n }\n // Both alphanumeric: compare lexically (ASCII sort)\n else {\n if (id1 < id2) return -1;\n if (id1 > id2) return 1;\n // id1 === id2, continue to next identifier\n }\n }\n\n return 0;\n}\n\n/**\n * Compares two semantic version strings according to SemVer 2.0.0 specification\n *\n * Supports:\n * - Core version: MAJOR.MINOR.PATCH\n * - Pre-release: -alpha, -beta.1, -rc.1, etc.\n * - Build metadata: +build, +sha.abc123 (ignored in comparison per spec)\n * - Optional 'v' prefix\n *\n * @param version1 - First version string\n * @param version2 - Second version string\n * @returns -1 if version1 < version2, 0 if equal, 1 if version1 > version2\n * @example\n * compare('1.0.0', '2.0.0') // -1\n * compare('1.0.0-alpha', '1.0.0') // -1 (prerelease < release)\n * compare('1.0.0-alpha', '1.0.0-beta') // -1\n * compare('1.0.0-alpha.1', '1.0.0-alpha.2') // -1\n * compare('1.0.0+build1', '1.0.0+build2') // 0 (build metadata ignored)\n * @since 1.9.0\n */\nexport function compare(version1: string, version2: string): number {\n const v1 = parse(version1);\n const v2 = parse(version2);\n\n // Compare major, minor, patch\n if (v1.major !== v2.major) return v1.major < v2.major ? -1 : 1;\n if (v1.minor !== v2.minor) return v1.minor < v2.minor ? -1 : 1;\n if (v1.patch !== v2.patch) return v1.patch < v2.patch ? -1 : 1;\n\n // Compare prerelease (build metadata is ignored per SemVer spec)\n return comparePrerelease(v1.prerelease, v2.prerelease);\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Increments a semantic version\n * @param version - The version to increment\n * @param type - The increment type ('major', 'minor', 'patch')\n * @returns Incremented version string\n * @since 1.9.0\n */\nexport function increment(version: string, type: 'major' | 'minor' | 'patch'): string;\nexport function increment(version: undefined, type: 'major' | 'minor' | 'patch'): undefined;\nexport function increment(version: null, type: 'major' | 'minor' | 'patch'): null;\nexport function increment(\n version: string | undefined | null,\n type: 'major' | 'minor' | 'patch'\n): string | undefined | null {\n if (version === undefined || version === null) return version;\n const hasV = version.startsWith('v');\n const normalizedVersion = version.replace(/^v/, '');\n\n const parts = normalizedVersion.split('.').map(Number);\n\n // Ensure we have at least major.minor.patch\n while (parts.length < 3) {\n parts.push(0);\n }\n\n let [major, minor, patch] = parts;\n\n switch (type) {\n case 'major':\n major++;\n minor = 0;\n patch = 0;\n break;\n case 'minor':\n minor++;\n patch = 0;\n break;\n case 'patch':\n patch++;\n break;\n default:\n throw new Error(`Invalid increment type: ${type}`);\n }\n\n const result = `${major}.${minor}.${patch}`;\n return hasV ? `v${result}` : result;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Checks if a version satisfies a range (simple implementation)\n * @param version - Version to check\n * @param range - Range pattern (e.g., \">=1.0.0\", \"~1.2.0\", \"^1.0.0\")\n * @returns True if version satisfies the range\n * @since 1.9.0\n */\nexport function satisfiesRange(version: string, range: string): boolean {\n const normalizedVersion = version.replace(/^v/, '');\n\n // Handle exact match\n if (!range.match(/[~^<>=]/)) {\n return normalizedVersion === range.replace(/^v/, '');\n }\n\n // Handle >= operator\n if (range.startsWith('>=')) {\n const targetVersion = range.slice(2).replace(/^v/, '');\n return compareVersionsSimple(normalizedVersion, targetVersion) >= 0;\n }\n\n // Handle > operator\n if (range.startsWith('>')) {\n const targetVersion = range.slice(1).replace(/^v/, '');\n return compareVersionsSimple(normalizedVersion, targetVersion) > 0;\n }\n\n // Handle <= operator\n if (range.startsWith('<=')) {\n const targetVersion = range.slice(2).replace(/^v/, '');\n return compareVersionsSimple(normalizedVersion, targetVersion) <= 0;\n }\n\n // Handle < operator\n if (range.startsWith('<')) {\n const targetVersion = range.slice(1).replace(/^v/, '');\n return compareVersionsSimple(normalizedVersion, targetVersion) < 0;\n }\n\n // Handle caret range (^1.2.3 allows patch and minor updates)\n if (range.startsWith('^')) {\n const targetVersion = range.slice(1).replace(/^v/, '');\n const [targetMajor] = targetVersion.split('.').map(Number);\n const [versionMajor] = normalizedVersion.split('.').map(Number);\n\n return versionMajor === targetMajor &&\n compareVersionsSimple(normalizedVersion, targetVersion) >= 0;\n }\n\n // Handle tilde range (~1.2.3 allows patch updates)\n if (range.startsWith('~')) {\n const targetVersion = range.slice(1).replace(/^v/, '');\n const [targetMajor, targetMinor] = targetVersion.split('.').map(Number);\n const [versionMajor, versionMinor] = normalizedVersion.split('.').map(Number);\n\n return versionMajor === targetMajor &&\n versionMinor === targetMinor &&\n compareVersionsSimple(normalizedVersion, targetVersion) >= 0;\n } else {\n // Unsupported range format\n return false;\n }\n}\n\nfunction compareVersionsSimple(version1: string, version2: string): number {\n const parts1 = version1.split('.').map(Number);\n const parts2 = version2.split('.').map(Number);\n\n const maxLength = Math.max(parts1.length, parts2.length);\n\n for (let i = 0; i < maxLength; i++) {\n const part1 = parts1[i] || 0;\n const part2 = parts2[i] || 0;\n\n if (part1 < part2) return -1;\n if (part1 > part2) return 1;\n }\n\n return 0;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Strip the leading \"v\" from a version string if it exists.\n * \n * @param version - The version string to process\n * @returns The version string without leading \"v\", or the original value if it's not a string or doesn't start with \"v\"\n * \n * @example\n * ```typescript\n * stripV(\"v1.2.3\") // \"1.2.3\"\n * stripV(\"1.2.3\") // \"1.2.3\"\n * stripV(\"v20.1.0\") // \"20.1.0\"\n * stripV(null) // null\n * stripV(undefined) // undefined\n * stripV(\"\") // \"\"\n * stripV(\"1.0.0-beta\") // \"1.0.0-beta\"\n * ```\n * @since 1.9.0\n */\nexport function stripV(version: string): string;\nexport function stripV(version: null): null;\nexport function stripV(version: undefined): undefined;\nexport function stripV(version: string | null | undefined): string | null | undefined {\n return typeof version === \"string\" && version.startsWith(\"v\") ? version.slice(1) : version;\n}\n"],"mappings":";AA4CA,SAAgB,MAAM,SAAsE;AAC1F,KAAI,YAAY,KAAA,KAAa,YAAY,KAAM,QAAO;CAKtD,MAAM,CAAC,uBAAuB,eAHX,QAAQ,QAAQ,MAAM,GAAG,CAGY,MAAM,IAAI;CAClE,MAAM,QAAQ,cAAc,YAAY,MAAM,IAAI,GAAG,EAAE;CAGvD,MAAM,CAAC,aAAa,oBAAoB,sBAAsB,MAAM,IAAI;CACxE,MAAM,aAAa,mBAAmB,iBAAiB,MAAM,IAAI,GAAG,EAAE;CAGtE,MAAM,QAAQ,YAAY,MAAM,IAAI,CAAC,IAAI,OAAO;AAEhD,QAAO;EACL,OAAO,MAAM,MAAM;EACnB,OAAO,MAAM,MAAM;EACnB,OAAO,MAAM,MAAM;EACnB;EACA;EACD;;;;;;;;;;;;;;;;;;;;AC/CH,SAAS,kBAAkB,MAAgB,MAAwB;AAGjE,KAAI,KAAK,WAAW,KAAK,KAAK,WAAW,EAAG,QAAO;AACnD,KAAI,KAAK,WAAW,EAAG,QAAO;AAC9B,KAAI,KAAK,WAAW,EAAG,QAAO;CAE9B,MAAM,YAAY,KAAK,IAAI,KAAK,QAAQ,KAAK,OAAO;AAEpD,MAAK,IAAI,IAAI,GAAG,IAAI,WAAW,KAAK;AAElC,MAAI,KAAK,KAAK,OAAQ,QAAO;AAC7B,MAAI,KAAK,KAAK,OAAQ,QAAO;EAE7B,MAAM,MAAM,KAAK;EACjB,MAAM,MAAM,KAAK;EAEjB,MAAM,SAAS,QAAQ,KAAK,IAAI;EAChC,MAAM,SAAS,QAAQ,KAAK,IAAI;AAGhC,MAAI,UAAU,QAAQ;GACpB,MAAM,OAAO,SAAS,KAAK,GAAG;GAC9B,MAAM,OAAO,SAAS,KAAK,GAAG;AAC9B,OAAI,OAAO,KAAM,QAAO;AACxB,OAAI,OAAO,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KAAK,IAAI,OAAO,QAAQ,OAAO,OAAO;AAExD,MAAK,IAAI,IAAI,GAAG,IAAI,WAAW,KAAK;EAClC,MAAM,QAAQ,OAAO,MAAM;EAC3B,MAAM,QAAQ,OAAO,MAAM;AAE3B,MAAI,QAAQ,MAAO,QAAO;AAC1B,MAAI,QAAQ,MAAO,QAAO;;AAG5B,QAAO;;;;ACzDT,SAAgB,OAAO,SAA+D;AACpF,QAAO,OAAO,YAAY,YAAY,QAAQ,WAAW,IAAI,GAAG,QAAQ,MAAM,EAAE,GAAG"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../helpers/version/parse.ts","../../../helpers/version/compare.ts","../../../helpers/version/increment.ts","../../../helpers/version/isPrerelease.ts","../../../helpers/version/satisfiesRange.ts","../../../helpers/version/stringify.ts","../../../helpers/version/stripV.ts"],"sourcesContent":["/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Represents a parsed semantic version according to SemVer 2.0.0 specification\n * @since 2.0.0\n */\nexport interface ParsedVersion {\n /** Major version number */\n major: number;\n /** Minor version number */\n minor: number;\n /** Patch version number */\n patch: number;\n /** Pre-release identifiers (e.g., ['alpha', '1'] for -alpha.1) */\n prerelease: string[];\n /** Build metadata identifiers (e.g., ['build', '123'] for +build.123) */\n build: string[];\n}\n\n/**\n * Parses a semantic version string into its components according to SemVer 2.0.0 specification\n *\n * Supports:\n * - Core version: MAJOR.MINOR.PATCH\n * - Pre-release: -alpha, -beta.1, -rc.1, -0.3.7, -x.7.z.92\n * - Build metadata: +build, +sha.abc123, +20130313144700\n * - Optional 'v' prefix (commonly used in git tags)\n *\n * @param version - Version string to parse\n * @returns Parsed version object with major, minor, patch, prerelease, and build\n * @example\n * parse('1.2.3') // { major: 1, minor: 2, patch: 3, prerelease: [], build: [] }\n * parse('v1.0.0-alpha.1') // { major: 1, minor: 0, patch: 0, prerelease: ['alpha', '1'], build: [] }\n * parse('2.0.0+build.123') // { major: 2, minor: 0, patch: 0, prerelease: [], build: ['build', '123'] }\n * parse('1.0.0-beta+exp.sha.5114f85') // { major: 1, minor: 0, patch: 0, prerelease: ['beta'], build: ['exp', 'sha', '5114f85'] }\n * @since 2.0.0\n */\nexport function parse(version: string): ParsedVersion;\nexport function parse(version: undefined): undefined;\nexport function parse(version: null): null;\nexport function parse(version: string | undefined | null): ParsedVersion | undefined | null {\n if (version === undefined || version === null) return version;\n // Remove optional 'v' prefix\n const normalized = version.replace(/^v/, '');\n\n // Split build metadata first (everything after +)\n const [versionWithPrerelease, buildString] = normalized.split('+');\n const build = buildString ? buildString.split('.') : [];\n\n // Split prerelease (everything after -)\n const [coreVersion, prereleaseString] = versionWithPrerelease.split('-');\n const prerelease = prereleaseString ? prereleaseString.split('.') : [];\n\n // Parse core version\n const parts = coreVersion.split('.').map(Number);\n\n return {\n major: parts[0] || 0,\n minor: parts[1] || 0,\n patch: parts[2] || 0,\n prerelease,\n build,\n };\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\nimport { parse } from './parse';\n\n/**\n * Compares two prerelease identifier arrays according to SemVer spec\n * Rules:\n * - Numeric identifiers are compared as integers\n * - Alphanumeric identifiers are compared lexically (ASCII)\n * - Numeric identifiers have lower precedence than alphanumeric\n * - A larger set of prerelease fields has higher precedence if all preceding are equal\n * @param pre1 - First prerelease array\n * @param pre2 - Second prerelease array\n * @returns -1, 0, or 1\n */\nfunction comparePrerelease(pre1: string[], pre2: string[]): number {\n // No prerelease has higher precedence than prerelease\n // e.g., 1.0.0 > 1.0.0-alpha\n if (pre1.length === 0 && pre2.length === 0) return 0;\n if (pre1.length === 0) return 1; // No prerelease > prerelease\n if (pre2.length === 0) return -1; // prerelease < no prerelease\n\n const maxLength = Math.max(pre1.length, pre2.length);\n\n for (let i = 0; i < maxLength; i++) {\n // A larger set has higher precedence if all preceding are equal\n if (i >= pre1.length) return -1;\n if (i >= pre2.length) return 1;\n\n const id1 = pre1[i];\n const id2 = pre2[i];\n\n const isNum1 = /^\\d+$/.test(id1);\n const isNum2 = /^\\d+$/.test(id2);\n\n // Both numeric: compare as integers\n if (isNum1 && isNum2) {\n const num1 = parseInt(id1, 10);\n const num2 = parseInt(id2, 10);\n if (num1 < num2) return -1;\n if (num1 > num2) return 1;\n // num1 === num2, continue to next identifier\n }\n // Numeric has lower precedence than alphanumeric\n else if (isNum1) {\n return -1;\n } else if (isNum2) {\n return 1;\n }\n // Both alphanumeric: compare lexically (ASCII sort)\n else {\n if (id1 < id2) return -1;\n if (id1 > id2) return 1;\n // id1 === id2, continue to next identifier\n }\n }\n\n return 0;\n}\n\n/**\n * Compares two semantic version strings according to SemVer 2.0.0 specification\n *\n * Supports:\n * - Core version: MAJOR.MINOR.PATCH\n * - Pre-release: -alpha, -beta.1, -rc.1, etc.\n * - Build metadata: +build, +sha.abc123 (ignored in comparison per spec)\n * - Optional 'v' prefix\n *\n * @param version1 - First version string\n * @param version2 - Second version string\n * @returns -1 if version1 < version2, 0 if equal, 1 if version1 > version2\n * @example\n * compare('1.0.0', '2.0.0') // -1\n * compare('1.0.0-alpha', '1.0.0') // -1 (prerelease < release)\n * compare('1.0.0-alpha', '1.0.0-beta') // -1\n * compare('1.0.0-alpha.1', '1.0.0-alpha.2') // -1\n * compare('1.0.0+build1', '1.0.0+build2') // 0 (build metadata ignored)\n * @since 1.9.0\n */\nexport function compare(version1: string, version2: string): number {\n const v1 = parse(version1);\n const v2 = parse(version2);\n\n // Compare major, minor, patch\n if (v1.major !== v2.major) return v1.major < v2.major ? -1 : 1;\n if (v1.minor !== v2.minor) return v1.minor < v2.minor ? -1 : 1;\n if (v1.patch !== v2.patch) return v1.patch < v2.patch ? -1 : 1;\n\n // Compare prerelease (build metadata is ignored per SemVer spec)\n return comparePrerelease(v1.prerelease, v2.prerelease);\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Increments a semantic version\n * @param version - The version to increment\n * @param type - The increment type ('major', 'minor', 'patch')\n * @returns Incremented version string\n * @since 1.9.0\n */\nexport function increment(version: string, type: 'major' | 'minor' | 'patch'): string;\nexport function increment(version: undefined, type: 'major' | 'minor' | 'patch'): undefined;\nexport function increment(version: null, type: 'major' | 'minor' | 'patch'): null;\nexport function increment(\n version: string | undefined | null,\n type: 'major' | 'minor' | 'patch'\n): string | undefined | null {\n if (version === undefined || version === null) return version;\n const hasV = version.startsWith('v');\n const normalizedVersion = version.replace(/^v/, '');\n\n const parts = normalizedVersion.split('.').map(Number);\n\n // Ensure we have at least major.minor.patch\n while (parts.length < 3) {\n parts.push(0);\n }\n\n let [major, minor, patch] = parts;\n\n switch (type) {\n case 'major':\n major++;\n minor = 0;\n patch = 0;\n break;\n case 'minor':\n minor++;\n patch = 0;\n break;\n case 'patch':\n patch++;\n break;\n default:\n throw new Error(`Invalid increment type: ${type}`);\n }\n\n const result = `${major}.${minor}.${patch}`;\n return hasV ? `v${result}` : result;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\nimport type { ParsedVersion } from './parse';\n\n/**\n * Returns `true` when the version string has a prerelease suffix\n * (i.e. contains a `-` after the core `MAJOR.MINOR.PATCH`).\n *\n * @param version - A semantic version string (e.g. `'2.0.0-alpha.1'`, `'1.0.0'`).\n * @returns `true` if the version is a prerelease, `false` otherwise.\n * @example\n * isPrerelease('2.0.0-alpha.1') // true\n * isPrerelease('1.0.0-rc.0') // true\n * isPrerelease('1.0.0') // false\n * isPrerelease('2.1.0') // false\n * @since next\n */\nexport function isPrerelease(version: string): boolean;\n/**\n * Returns `true` when the parsed version has at least one prerelease identifier.\n *\n * @param version - A {@link ParsedVersion} object (as returned by {@link parse}).\n * @returns `true` if `version.prerelease` is non-empty, `false` otherwise.\n * @example\n * isPrerelease(parse('2.0.0-alpha.1')) // true\n * isPrerelease(parse('1.0.0')) // false\n * @since next\n */\nexport function isPrerelease(version: ParsedVersion): boolean;\nexport function isPrerelease(version: undefined): undefined;\nexport function isPrerelease(version: null): null;\nexport function isPrerelease(version: string | ParsedVersion | undefined | null): boolean | undefined | null {\n if (version === undefined || version === null) return version;\n if (typeof version === 'string') return version.split('+')[0].includes('-');\n return version.prerelease.length > 0;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Checks if a version satisfies a range (simple implementation)\n * @param version - Version to check\n * @param range - Range pattern (e.g., \">=1.0.0\", \"~1.2.0\", \"^1.0.0\")\n * @returns True if version satisfies the range\n * @since 1.9.0\n */\nexport function satisfiesRange(version: string, range: string): boolean {\n const normalizedVersion = version.replace(/^v/, '');\n\n // Handle exact match\n if (!range.match(/[~^<>=]/)) {\n return normalizedVersion === range.replace(/^v/, '');\n }\n\n // Handle >= operator\n if (range.startsWith('>=')) {\n const targetVersion = range.slice(2).replace(/^v/, '');\n return compareVersionsSimple(normalizedVersion, targetVersion) >= 0;\n }\n\n // Handle > operator\n if (range.startsWith('>')) {\n const targetVersion = range.slice(1).replace(/^v/, '');\n return compareVersionsSimple(normalizedVersion, targetVersion) > 0;\n }\n\n // Handle <= operator\n if (range.startsWith('<=')) {\n const targetVersion = range.slice(2).replace(/^v/, '');\n return compareVersionsSimple(normalizedVersion, targetVersion) <= 0;\n }\n\n // Handle < operator\n if (range.startsWith('<')) {\n const targetVersion = range.slice(1).replace(/^v/, '');\n return compareVersionsSimple(normalizedVersion, targetVersion) < 0;\n }\n\n // Handle caret range (^1.2.3 allows patch and minor updates)\n if (range.startsWith('^')) {\n const targetVersion = range.slice(1).replace(/^v/, '');\n const [targetMajor] = targetVersion.split('.').map(Number);\n const [versionMajor] = normalizedVersion.split('.').map(Number);\n\n return versionMajor === targetMajor &&\n compareVersionsSimple(normalizedVersion, targetVersion) >= 0;\n }\n\n // Handle tilde range (~1.2.3 allows patch updates)\n if (range.startsWith('~')) {\n const targetVersion = range.slice(1).replace(/^v/, '');\n const [targetMajor, targetMinor] = targetVersion.split('.').map(Number);\n const [versionMajor, versionMinor] = normalizedVersion.split('.').map(Number);\n\n return versionMajor === targetMajor &&\n versionMinor === targetMinor &&\n compareVersionsSimple(normalizedVersion, targetVersion) >= 0;\n } else {\n // Unsupported range format\n return false;\n }\n}\n\nfunction compareVersionsSimple(version1: string, version2: string): number {\n const parts1 = version1.split('.').map(Number);\n const parts2 = version2.split('.').map(Number);\n\n const maxLength = Math.max(parts1.length, parts2.length);\n\n for (let i = 0; i < maxLength; i++) {\n const part1 = parts1[i] || 0;\n const part2 = parts2[i] || 0;\n\n if (part1 < part2) return -1;\n if (part1 > part2) return 1;\n }\n\n return 0;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\nimport type { ParsedVersion } from './parse';\n\n/**\n * Reconstruct a semantic version string from a {@link ParsedVersion} object.\n *\n * This is the inverse of {@link parse}:\n * `stringify(parse(v)) === stripV(v)` for any valid SemVer string `v`.\n *\n * @param parsed - A parsed semantic version object.\n * @returns The reconstructed version string (without leading `v`).\n * @example\n * stringify({ major: 1, minor: 2, patch: 3, prerelease: [], build: [] })\n * // => '1.2.3'\n * @example\n * stringify({ major: 2, minor: 0, patch: 0, prerelease: ['alpha', '1'], build: [] })\n * // => '2.0.0-alpha.1'\n * @example\n * stringify({ major: 1, minor: 0, patch: 0, prerelease: ['beta'], build: ['exp', 'sha', '5114f85'] })\n * // => '1.0.0-beta+exp.sha.5114f85'\n * @since next\n */\nexport function stringify(parsed: ParsedVersion): string;\nexport function stringify(parsed: undefined): undefined;\nexport function stringify(parsed: null): null;\nexport function stringify(parsed: ParsedVersion | undefined | null): string | undefined | null {\n if (parsed === undefined || parsed === null) return parsed;\n const base = `${parsed.major}.${parsed.minor}.${parsed.patch}`;\n const prerelease = parsed.prerelease.length > 0 ? `-${parsed.prerelease.join('.')}` : '';\n const build = parsed.build.length > 0 ? `+${parsed.build.join('.')}` : '';\n return `${base}${prerelease}${build}`;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Strip the leading \"v\" from a version string if it exists.\n * \n * @param version - The version string to process\n * @returns The version string without leading \"v\", or the original value if it's not a string or doesn't start with \"v\"\n * \n * @example\n * ```typescript\n * stripV(\"v1.2.3\") // \"1.2.3\"\n * stripV(\"1.2.3\") // \"1.2.3\"\n * stripV(\"v20.1.0\") // \"20.1.0\"\n * stripV(null) // null\n * stripV(undefined) // undefined\n * stripV(\"\") // \"\"\n * stripV(\"1.0.0-beta\") // \"1.0.0-beta\"\n * ```\n * @since 1.9.0\n */\nexport function stripV(version: string): string;\nexport function stripV(version: null): null;\nexport function stripV(version: undefined): undefined;\nexport function stripV(version: string | null | undefined): string | null | undefined {\n return typeof version === \"string\" && version.startsWith(\"v\") ? version.slice(1) : version;\n}\n"],"mappings":";AA4CA,SAAgB,MAAM,SAAsE;AAC1F,KAAI,YAAY,KAAA,KAAa,YAAY,KAAM,QAAO;CAKtD,MAAM,CAAC,uBAAuB,eAHX,QAAQ,QAAQ,MAAM,GAAG,CAGY,MAAM,IAAI;CAClE,MAAM,QAAQ,cAAc,YAAY,MAAM,IAAI,GAAG,EAAE;CAGvD,MAAM,CAAC,aAAa,oBAAoB,sBAAsB,MAAM,IAAI;CACxE,MAAM,aAAa,mBAAmB,iBAAiB,MAAM,IAAI,GAAG,EAAE;CAGtE,MAAM,QAAQ,YAAY,MAAM,IAAI,CAAC,IAAI,OAAO;AAEhD,QAAO;EACL,OAAO,MAAM,MAAM;EACnB,OAAO,MAAM,MAAM;EACnB,OAAO,MAAM,MAAM;EACnB;EACA;EACD;;;;;;;;;;;;;;;;;;;;AC/CH,SAAS,kBAAkB,MAAgB,MAAwB;AAGjE,KAAI,KAAK,WAAW,K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AO,MAAM,KAAK,IAAI,KAAK;;;;ACPzE,SAAgB,OAAO,SAA+D;AACpF,QAAO,OAAO,YAAY,YAAY,QAAQ,WAAW,IAAI,GAAG,QAAQ,MAAM,EAAE,GAAG"}
|
package/llms.txt
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# @helpers4/version
|
|
2
2
|
|
|
3
3
|
> Tree-shakable TypeScript utility functions for the `version` domain.
|
|
4
|
-
> Package: `@helpers4/version` — Version: 2.0.0-alpha.
|
|
4
|
+
> Package: `@helpers4/version` — Version: 2.0.0-alpha.19
|
|
5
5
|
> License: LGPL-3.0-or-later
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
@@ -15,7 +15,7 @@ pnpm add @helpers4/version
|
|
|
15
15
|
## Usage
|
|
16
16
|
|
|
17
17
|
```typescript
|
|
18
|
-
import { compare, increment,
|
|
18
|
+
import { compare, increment, isPrerelease, ... } from '@helpers4/version';
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
## Functions
|
|
@@ -24,9 +24,10 @@ import { compare, increment, parse, ... } from '@helpers4/version';
|
|
|
24
24
|
|---|---|
|
|
25
25
|
| `compare` | Compares two semantic version strings according to SemVer 2.0.0 specification Supports: - Core vers |
|
|
26
26
|
| `increment` | Increments a semantic version |
|
|
27
|
+
| `isPrerelease` | Returns `true` when the version string has a prerelease suffix (i.e. contains a `-` after the core ` |
|
|
27
28
|
| `parse` | Parses a semantic version string into its components according to SemVer 2.0.0 specification Suppor |
|
|
28
|
-
| `ParsedVersion` | Represents a parsed semantic version according to SemVer 2.0.0 specification |
|
|
29
29
|
| `satisfiesRange` | Checks if a version satisfies a range (simple implementation) |
|
|
30
|
+
| `stringify` | Reconstruct a semantic version string from a ParsedVersion object. This is the inverse of parse: `s |
|
|
30
31
|
| `stripV` | Strip the leading "v" from a version string if it exists. |
|
|
31
32
|
|
|
32
33
|
---
|
|
@@ -153,6 +154,90 @@ increment('v1.0.0', 'major')
|
|
|
153
154
|
|
|
154
155
|
---
|
|
155
156
|
|
|
157
|
+
### `isPrerelease`
|
|
158
|
+
|
|
159
|
+
Returns `true` when the version string has a prerelease suffix
|
|
160
|
+
(i.e. contains a `-` after the core `MAJOR.MINOR.PATCH`).
|
|
161
|
+
|
|
162
|
+
```typescript
|
|
163
|
+
import { isPrerelease } from '@helpers4/version';
|
|
164
|
+
|
|
165
|
+
isPrerelease(version: string): boolean
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
**Parameters:**
|
|
169
|
+
|
|
170
|
+
- `version: string` — A semantic version string (e.g. `'2.0.0-alpha.1'`, `'1.0.0'`).
|
|
171
|
+
|
|
172
|
+
**Returns:** `boolean` — `true` if the version is a prerelease, `false` otherwise.
|
|
173
|
+
|
|
174
|
+
```typescript
|
|
175
|
+
import { isPrerelease } from '@helpers4/version';
|
|
176
|
+
|
|
177
|
+
isPrerelease(version: ParsedVersion): boolean
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
**Parameters:**
|
|
181
|
+
|
|
182
|
+
- `version: ParsedVersion` — A ParsedVersion object (as returned by parse).
|
|
183
|
+
|
|
184
|
+
**Returns:** `boolean` — `true` if `version.prerelease` is non-empty, `false` otherwise.
|
|
185
|
+
|
|
186
|
+
```typescript
|
|
187
|
+
import { isPrerelease } from '@helpers4/version';
|
|
188
|
+
|
|
189
|
+
isPrerelease(version: undefined): undefined
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
**Parameters:**
|
|
193
|
+
|
|
194
|
+
- `version: undefined` — A semantic version string (e.g. `'2.0.0-alpha.1'`, `'1.0.0'`).
|
|
195
|
+
|
|
196
|
+
**Returns:** `undefined` — `true` if the version is a prerelease, `false` otherwise.
|
|
197
|
+
|
|
198
|
+
```typescript
|
|
199
|
+
import { isPrerelease } from '@helpers4/version';
|
|
200
|
+
|
|
201
|
+
isPrerelease(version: null): null
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
**Parameters:**
|
|
205
|
+
|
|
206
|
+
- `version: null` — A semantic version string (e.g. `'2.0.0-alpha.1'`, `'1.0.0'`).
|
|
207
|
+
|
|
208
|
+
**Returns:** `null` — `true` if the version is a prerelease, `false` otherwise.
|
|
209
|
+
|
|
210
|
+
**Examples:**
|
|
211
|
+
|
|
212
|
+
*Detect a prerelease version*
|
|
213
|
+
|
|
214
|
+
Returns true for any version string that contains a prerelease suffix.
|
|
215
|
+
|
|
216
|
+
```typescript
|
|
217
|
+
isPrerelease('2.0.0-alpha.1') // true
|
|
218
|
+
isPrerelease('1.0.0-rc.0') // true
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
*Stable versions return false*
|
|
222
|
+
|
|
223
|
+
Returns false when the version has no prerelease suffix.
|
|
224
|
+
|
|
225
|
+
```typescript
|
|
226
|
+
isPrerelease('1.0.0') // false
|
|
227
|
+
isPrerelease('2.1.3') // false
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
*Accept a ParsedVersion object*
|
|
231
|
+
|
|
232
|
+
Works with the result of parse() — checks the prerelease array instead of string matching.
|
|
233
|
+
|
|
234
|
+
```typescript
|
|
235
|
+
isPrerelease(parse('2.0.0-alpha.1')) // true
|
|
236
|
+
isPrerelease(parse('1.0.0')) // false
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
---
|
|
240
|
+
|
|
156
241
|
### `parse`
|
|
157
242
|
|
|
158
243
|
Parses a semantic version string into its components according to SemVer 2.0.0 specification
|
|
@@ -221,12 +306,6 @@ parse('v2.0.0-alpha.1')
|
|
|
221
306
|
|
|
222
307
|
---
|
|
223
308
|
|
|
224
|
-
### `ParsedVersion`
|
|
225
|
-
|
|
226
|
-
Represents a parsed semantic version according to SemVer 2.0.0 specification
|
|
227
|
-
|
|
228
|
-
---
|
|
229
|
-
|
|
230
309
|
### `satisfiesRange`
|
|
231
310
|
|
|
232
311
|
Checks if a version satisfies a range (simple implementation)
|
|
@@ -275,6 +354,74 @@ satisfiesRange('0.9.0', '>=1.0.0')
|
|
|
275
354
|
|
|
276
355
|
---
|
|
277
356
|
|
|
357
|
+
### `stringify`
|
|
358
|
+
|
|
359
|
+
Reconstruct a semantic version string from a ParsedVersion object.
|
|
360
|
+
|
|
361
|
+
This is the inverse of parse:
|
|
362
|
+
`stringify(parse(v)) === stripV(v)` for any valid SemVer string `v`.
|
|
363
|
+
|
|
364
|
+
```typescript
|
|
365
|
+
import { stringify } from '@helpers4/version';
|
|
366
|
+
|
|
367
|
+
stringify(parsed: ParsedVersion): string
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
**Parameters:**
|
|
371
|
+
|
|
372
|
+
- `parsed: ParsedVersion` — A parsed semantic version object.
|
|
373
|
+
|
|
374
|
+
**Returns:** `string` — The reconstructed version string (without leading `v`).
|
|
375
|
+
|
|
376
|
+
```typescript
|
|
377
|
+
import { stringify } from '@helpers4/version';
|
|
378
|
+
|
|
379
|
+
stringify(parsed: undefined): undefined
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
**Parameters:**
|
|
383
|
+
|
|
384
|
+
- `parsed: undefined` — A parsed semantic version object.
|
|
385
|
+
|
|
386
|
+
**Returns:** `undefined` — The reconstructed version string (without leading `v`).
|
|
387
|
+
|
|
388
|
+
```typescript
|
|
389
|
+
import { stringify } from '@helpers4/version';
|
|
390
|
+
|
|
391
|
+
stringify(parsed: null): null
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
**Parameters:**
|
|
395
|
+
|
|
396
|
+
- `parsed: null` — A parsed semantic version object.
|
|
397
|
+
|
|
398
|
+
**Returns:** `null` — The reconstructed version string (without leading `v`).
|
|
399
|
+
|
|
400
|
+
**Examples:**
|
|
401
|
+
|
|
402
|
+
*Reconstruct a stable version*
|
|
403
|
+
|
|
404
|
+
Converts a ParsedVersion object back to a version string.
|
|
405
|
+
|
|
406
|
+
```typescript
|
|
407
|
+
stringify({ major: 1, minor: 2, patch: 3, prerelease: [], build: [] })
|
|
408
|
+
// => '1.2.3'
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
*Round-trip with parse*
|
|
412
|
+
|
|
413
|
+
stringify(parse(v)) returns the original version string (without leading v).
|
|
414
|
+
|
|
415
|
+
```typescript
|
|
416
|
+
stringify(parse('2.0.0-alpha.1'))
|
|
417
|
+
// => '2.0.0-alpha.1'
|
|
418
|
+
|
|
419
|
+
stringify(parse('1.0.0-beta+exp.sha.5114f85'))
|
|
420
|
+
// => '1.0.0-beta+exp.sha.5114f85'
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
---
|
|
424
|
+
|
|
278
425
|
### `stripV`
|
|
279
426
|
|
|
280
427
|
Strip the leading "v" from a version string if it exists.
|
package/meta/api.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"category": "version",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.19",
|
|
4
4
|
"functions": [
|
|
5
5
|
{
|
|
6
6
|
"name": "compare",
|
|
@@ -129,6 +129,92 @@
|
|
|
129
129
|
],
|
|
130
130
|
"sourceFile": "increment.ts"
|
|
131
131
|
},
|
|
132
|
+
{
|
|
133
|
+
"name": "isPrerelease",
|
|
134
|
+
"kind": "function",
|
|
135
|
+
"description": "Returns `true` when the version string has a prerelease suffix\n(i.e. contains a `-` after the core `MAJOR.MINOR.PATCH`).",
|
|
136
|
+
"since": "next",
|
|
137
|
+
"signatures": [
|
|
138
|
+
{
|
|
139
|
+
"signature": "isPrerelease(version: string): boolean",
|
|
140
|
+
"description": "Returns `true` when the version string has a prerelease suffix\n(i.e. contains a `-` after the core `MAJOR.MINOR.PATCH`).",
|
|
141
|
+
"params": [
|
|
142
|
+
{
|
|
143
|
+
"name": "version",
|
|
144
|
+
"type": "string",
|
|
145
|
+
"description": "A semantic version string (e.g. `'2.0.0-alpha.1'`, `'1.0.0'`)."
|
|
146
|
+
}
|
|
147
|
+
],
|
|
148
|
+
"returns": {
|
|
149
|
+
"type": "boolean",
|
|
150
|
+
"description": "`true` if the version is a prerelease, `false` otherwise."
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
"signature": "isPrerelease(version: ParsedVersion): boolean",
|
|
155
|
+
"description": "Returns `true` when the parsed version has at least one prerelease identifier.",
|
|
156
|
+
"params": [
|
|
157
|
+
{
|
|
158
|
+
"name": "version",
|
|
159
|
+
"type": "ParsedVersion",
|
|
160
|
+
"description": "A ParsedVersion object (as returned by parse)."
|
|
161
|
+
}
|
|
162
|
+
],
|
|
163
|
+
"returns": {
|
|
164
|
+
"type": "boolean",
|
|
165
|
+
"description": "`true` if `version.prerelease` is non-empty, `false` otherwise."
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
"signature": "isPrerelease(version: undefined): undefined",
|
|
170
|
+
"description": "Returns `true` when the version string has a prerelease suffix\n(i.e. contains a `-` after the core `MAJOR.MINOR.PATCH`).",
|
|
171
|
+
"params": [
|
|
172
|
+
{
|
|
173
|
+
"name": "version",
|
|
174
|
+
"type": "undefined",
|
|
175
|
+
"description": "A semantic version string (e.g. `'2.0.0-alpha.1'`, `'1.0.0'`)."
|
|
176
|
+
}
|
|
177
|
+
],
|
|
178
|
+
"returns": {
|
|
179
|
+
"type": "undefined",
|
|
180
|
+
"description": "`true` if the version is a prerelease, `false` otherwise."
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
"signature": "isPrerelease(version: null): null",
|
|
185
|
+
"description": "Returns `true` when the version string has a prerelease suffix\n(i.e. contains a `-` after the core `MAJOR.MINOR.PATCH`).",
|
|
186
|
+
"params": [
|
|
187
|
+
{
|
|
188
|
+
"name": "version",
|
|
189
|
+
"type": "null",
|
|
190
|
+
"description": "A semantic version string (e.g. `'2.0.0-alpha.1'`, `'1.0.0'`)."
|
|
191
|
+
}
|
|
192
|
+
],
|
|
193
|
+
"returns": {
|
|
194
|
+
"type": "null",
|
|
195
|
+
"description": "`true` if the version is a prerelease, `false` otherwise."
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
],
|
|
199
|
+
"examples": [
|
|
200
|
+
{
|
|
201
|
+
"title": "Detect a prerelease version",
|
|
202
|
+
"description": "Returns true for any version string that contains a prerelease suffix.",
|
|
203
|
+
"code": "isPrerelease('2.0.0-alpha.1') // true\nisPrerelease('1.0.0-rc.0') // true"
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
"title": "Stable versions return false",
|
|
207
|
+
"description": "Returns false when the version has no prerelease suffix.",
|
|
208
|
+
"code": "isPrerelease('1.0.0') // false\nisPrerelease('2.1.3') // false"
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
"title": "Accept a ParsedVersion object",
|
|
212
|
+
"description": "Works with the result of parse() — checks the prerelease array instead of string matching.",
|
|
213
|
+
"code": "isPrerelease(parse('2.0.0-alpha.1')) // true\nisPrerelease(parse('1.0.0')) // false"
|
|
214
|
+
}
|
|
215
|
+
],
|
|
216
|
+
"sourceFile": "isPrerelease.ts"
|
|
217
|
+
},
|
|
132
218
|
{
|
|
133
219
|
"name": "parse",
|
|
134
220
|
"kind": "function",
|
|
@@ -193,16 +279,14 @@
|
|
|
193
279
|
"code": "parse('v2.0.0-alpha.1')\n// => { major: 2, minor: 0, patch: 0, prerelease: ['alpha', '1'], build: [] }"
|
|
194
280
|
}
|
|
195
281
|
],
|
|
196
|
-
"sourceFile": "parse.ts"
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
"examples": [],
|
|
205
|
-
"sourceFile": "parse.ts"
|
|
282
|
+
"sourceFile": "parse.ts",
|
|
283
|
+
"relatedTypes": [
|
|
284
|
+
{
|
|
285
|
+
"name": "ParsedVersion",
|
|
286
|
+
"description": "Represents a parsed semantic version according to SemVer 2.0.0 specification",
|
|
287
|
+
"typeDefinition": "interface ParsedVersion {\n build: string[];\n major: number;\n minor: number;\n patch: number;\n prerelease: string[];\n}"
|
|
288
|
+
}
|
|
289
|
+
]
|
|
206
290
|
},
|
|
207
291
|
{
|
|
208
292
|
"name": "satisfiesRange",
|
|
@@ -250,6 +334,72 @@
|
|
|
250
334
|
],
|
|
251
335
|
"sourceFile": "satisfiesRange.ts"
|
|
252
336
|
},
|
|
337
|
+
{
|
|
338
|
+
"name": "stringify",
|
|
339
|
+
"kind": "function",
|
|
340
|
+
"description": "Reconstruct a semantic version string from a ParsedVersion object.\n\nThis is the inverse of parse:\n`stringify(parse(v)) === stripV(v)` for any valid SemVer string `v`.",
|
|
341
|
+
"since": "next",
|
|
342
|
+
"signatures": [
|
|
343
|
+
{
|
|
344
|
+
"signature": "stringify(parsed: ParsedVersion): string",
|
|
345
|
+
"description": "Reconstruct a semantic version string from a ParsedVersion object.\n\nThis is the inverse of parse:\n`stringify(parse(v)) === stripV(v)` for any valid SemVer string `v`.",
|
|
346
|
+
"params": [
|
|
347
|
+
{
|
|
348
|
+
"name": "parsed",
|
|
349
|
+
"type": "ParsedVersion",
|
|
350
|
+
"description": "A parsed semantic version object."
|
|
351
|
+
}
|
|
352
|
+
],
|
|
353
|
+
"returns": {
|
|
354
|
+
"type": "string",
|
|
355
|
+
"description": "The reconstructed version string (without leading `v`)."
|
|
356
|
+
}
|
|
357
|
+
},
|
|
358
|
+
{
|
|
359
|
+
"signature": "stringify(parsed: undefined): undefined",
|
|
360
|
+
"description": "Reconstruct a semantic version string from a ParsedVersion object.\n\nThis is the inverse of parse:\n`stringify(parse(v)) === stripV(v)` for any valid SemVer string `v`.",
|
|
361
|
+
"params": [
|
|
362
|
+
{
|
|
363
|
+
"name": "parsed",
|
|
364
|
+
"type": "undefined",
|
|
365
|
+
"description": "A parsed semantic version object."
|
|
366
|
+
}
|
|
367
|
+
],
|
|
368
|
+
"returns": {
|
|
369
|
+
"type": "undefined",
|
|
370
|
+
"description": "The reconstructed version string (without leading `v`)."
|
|
371
|
+
}
|
|
372
|
+
},
|
|
373
|
+
{
|
|
374
|
+
"signature": "stringify(parsed: null): null",
|
|
375
|
+
"description": "Reconstruct a semantic version string from a ParsedVersion object.\n\nThis is the inverse of parse:\n`stringify(parse(v)) === stripV(v)` for any valid SemVer string `v`.",
|
|
376
|
+
"params": [
|
|
377
|
+
{
|
|
378
|
+
"name": "parsed",
|
|
379
|
+
"type": "null",
|
|
380
|
+
"description": "A parsed semantic version object."
|
|
381
|
+
}
|
|
382
|
+
],
|
|
383
|
+
"returns": {
|
|
384
|
+
"type": "null",
|
|
385
|
+
"description": "The reconstructed version string (without leading `v`)."
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
],
|
|
389
|
+
"examples": [
|
|
390
|
+
{
|
|
391
|
+
"title": "Reconstruct a stable version",
|
|
392
|
+
"description": "Converts a ParsedVersion object back to a version string.",
|
|
393
|
+
"code": "stringify({ major: 1, minor: 2, patch: 3, prerelease: [], build: [] })\n// => '1.2.3'"
|
|
394
|
+
},
|
|
395
|
+
{
|
|
396
|
+
"title": "Round-trip with parse",
|
|
397
|
+
"description": "stringify(parse(v)) returns the original version string (without leading v).",
|
|
398
|
+
"code": "stringify(parse('2.0.0-alpha.1'))\n// => '2.0.0-alpha.1'\n\nstringify(parse('1.0.0-beta+exp.sha.5114f85'))\n// => '1.0.0-beta+exp.sha.5114f85'"
|
|
399
|
+
}
|
|
400
|
+
],
|
|
401
|
+
"sourceFile": "stringify.ts"
|
|
402
|
+
},
|
|
253
403
|
{
|
|
254
404
|
"name": "stripV",
|
|
255
405
|
"kind": "function",
|
package/meta/examples.json
CHANGED
|
@@ -36,6 +36,26 @@
|
|
|
36
36
|
}
|
|
37
37
|
]
|
|
38
38
|
},
|
|
39
|
+
{
|
|
40
|
+
"name": "isPrerelease",
|
|
41
|
+
"examples": [
|
|
42
|
+
{
|
|
43
|
+
"title": "Detect a prerelease version",
|
|
44
|
+
"description": "Returns true for any version string that contains a prerelease suffix.",
|
|
45
|
+
"code": "isPrerelease('2.0.0-alpha.1') // true\nisPrerelease('1.0.0-rc.0') // true"
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"title": "Stable versions return false",
|
|
49
|
+
"description": "Returns false when the version has no prerelease suffix.",
|
|
50
|
+
"code": "isPrerelease('1.0.0') // false\nisPrerelease('2.1.3') // false"
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"title": "Accept a ParsedVersion object",
|
|
54
|
+
"description": "Works with the result of parse() — checks the prerelease array instead of string matching.",
|
|
55
|
+
"code": "isPrerelease(parse('2.0.0-alpha.1')) // true\nisPrerelease(parse('1.0.0')) // false"
|
|
56
|
+
}
|
|
57
|
+
]
|
|
58
|
+
},
|
|
39
59
|
{
|
|
40
60
|
"name": "parse",
|
|
41
61
|
"examples": [
|
|
@@ -71,6 +91,21 @@
|
|
|
71
91
|
}
|
|
72
92
|
]
|
|
73
93
|
},
|
|
94
|
+
{
|
|
95
|
+
"name": "stringify",
|
|
96
|
+
"examples": [
|
|
97
|
+
{
|
|
98
|
+
"title": "Reconstruct a stable version",
|
|
99
|
+
"description": "Converts a ParsedVersion object back to a version string.",
|
|
100
|
+
"code": "stringify({ major: 1, minor: 2, patch: 3, prerelease: [], build: [] })\n// => '1.2.3'"
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
"title": "Round-trip with parse",
|
|
104
|
+
"description": "stringify(parse(v)) returns the original version string (without leading v).",
|
|
105
|
+
"code": "stringify(parse('2.0.0-alpha.1'))\n// => '2.0.0-alpha.1'\n\nstringify(parse('1.0.0-beta+exp.sha.5114f85'))\n// => '1.0.0-beta+exp.sha.5114f85'"
|
|
106
|
+
}
|
|
107
|
+
]
|
|
108
|
+
},
|
|
74
109
|
{
|
|
75
110
|
"name": "stripV",
|
|
76
111
|
"examples": [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@helpers4/version",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.19",
|
|
4
4
|
"description": "A set of helpers in TS/JS, compatible with tree-shaking, for version.",
|
|
5
5
|
"author": "baxyz <baxy@etik.com>",
|
|
6
6
|
"license": "LGPL-3.0",
|
|
@@ -29,8 +29,10 @@
|
|
|
29
29
|
"version",
|
|
30
30
|
"compare",
|
|
31
31
|
"increment",
|
|
32
|
+
"isPrerelease",
|
|
32
33
|
"parse",
|
|
33
34
|
"satisfiesRange",
|
|
35
|
+
"stringify",
|
|
34
36
|
"stripV"
|
|
35
37
|
],
|
|
36
38
|
"files": [
|