@helpers4/version 2.0.0-alpha.11 → 2.0.0-alpha.15
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 +4 -4
- package/lib/index.d.ts +4 -0
- package/lib/index.js +11 -41
- package/lib/index.js.map +1 -1
- package/llms.txt +338 -0
- package/meta/api.json +71 -1
- package/meta/category.json +6 -0
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -41,15 +41,15 @@ A set of helpers for working with URLs.
|
|
|
41
41
|
| Name | Package | Source Code | Description |
|
|
42
42
|
|------|---------|-------------|-------------|
|
|
43
43
|
| array | [@helpers4/array](https://www.npmjs.com/package/@helpers4/array) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/array) | Array manipulation utilities |
|
|
44
|
-
| date | [@helpers4/date](https://www.npmjs.com/package/@helpers4/date) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/date) |
|
|
44
|
+
| date | [@helpers4/date](https://www.npmjs.com/package/@helpers4/date) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/date) | Date and time utility functions |
|
|
45
45
|
| function | [@helpers4/function](https://www.npmjs.com/package/@helpers4/function) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/function) | Function utilities and type guards |
|
|
46
|
-
| math | [@helpers4/math](https://www.npmjs.com/package/@helpers4/math) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/math) |
|
|
47
|
-
| number | [@helpers4/number](https://www.npmjs.com/package/@helpers4/number) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/number) |
|
|
46
|
+
| math | [@helpers4/math](https://www.npmjs.com/package/@helpers4/math) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/math) | Mathematical utility functions and calculations |
|
|
47
|
+
| number | [@helpers4/number](https://www.npmjs.com/package/@helpers4/number) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/number) | Number utility functions and validation |
|
|
48
48
|
| object | [@helpers4/object](https://www.npmjs.com/package/@helpers4/object) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/object) | Object manipulation utilities |
|
|
49
49
|
| observable | [@helpers4/observable](https://www.npmjs.com/package/@helpers4/observable) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/observable) | Observable utilities and combinators |
|
|
50
50
|
| promise | [@helpers4/promise](https://www.npmjs.com/package/@helpers4/promise) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/promise) | Promise utilities and error handling |
|
|
51
51
|
| string | [@helpers4/string](https://www.npmjs.com/package/@helpers4/string) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/string) | String manipulation and formatting utilities |
|
|
52
|
-
| type | [@helpers4/type](https://www.npmjs.com/package/@helpers4/type) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/type) |
|
|
52
|
+
| type | [@helpers4/type](https://www.npmjs.com/package/@helpers4/type) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/type) | Type checking and validation utilities |
|
|
53
53
|
| url | [@helpers4/url](https://www.npmjs.com/package/@helpers4/url) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/url) | URL parsing and manipulation utilities |
|
|
54
54
|
| version | [@helpers4/version](https://www.npmjs.com/package/@helpers4/version) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/version) | Version string manipulation utilities |
|
|
55
55
|
<!-- /AUTOMATIC-CATEGORIES-TABLE -->
|
package/lib/index.d.ts
CHANGED
|
@@ -38,6 +38,8 @@ declare function compare(version1: string, version2: string): number;
|
|
|
38
38
|
* @since 1.9.0
|
|
39
39
|
*/
|
|
40
40
|
declare function increment(version: string, type: 'major' | 'minor' | 'patch'): string;
|
|
41
|
+
declare function increment(version: undefined, type: 'major' | 'minor' | 'patch'): undefined;
|
|
42
|
+
declare function increment(version: null, type: 'major' | 'minor' | 'patch'): null;
|
|
41
43
|
|
|
42
44
|
/**
|
|
43
45
|
* This file is part of helpers4.
|
|
@@ -79,6 +81,8 @@ interface ParsedVersion {
|
|
|
79
81
|
* @since 2.0.0
|
|
80
82
|
*/
|
|
81
83
|
declare function parse(version: string): ParsedVersion;
|
|
84
|
+
declare function parse(version: undefined): undefined;
|
|
85
|
+
declare function parse(version: null): null;
|
|
82
86
|
|
|
83
87
|
/**
|
|
84
88
|
* This file is part of helpers4.
|
package/lib/index.js
CHANGED
|
@@ -1,23 +1,6 @@
|
|
|
1
1
|
//#region helpers/version/parse.ts
|
|
2
|
-
/**
|
|
3
|
-
* Parses a semantic version string into its components according to SemVer 2.0.0 specification
|
|
4
|
-
*
|
|
5
|
-
* Supports:
|
|
6
|
-
* - Core version: MAJOR.MINOR.PATCH
|
|
7
|
-
* - Pre-release: -alpha, -beta.1, -rc.1, -0.3.7, -x.7.z.92
|
|
8
|
-
* - Build metadata: +build, +sha.abc123, +20130313144700
|
|
9
|
-
* - Optional 'v' prefix (commonly used in git tags)
|
|
10
|
-
*
|
|
11
|
-
* @param version - Version string to parse
|
|
12
|
-
* @returns Parsed version object with major, minor, patch, prerelease, and build
|
|
13
|
-
* @example
|
|
14
|
-
* parse('1.2.3') // { major: 1, minor: 2, patch: 3, prerelease: [], build: [] }
|
|
15
|
-
* parse('v1.0.0-alpha.1') // { major: 1, minor: 0, patch: 0, prerelease: ['alpha', '1'], build: [] }
|
|
16
|
-
* parse('2.0.0+build.123') // { major: 2, minor: 0, patch: 0, prerelease: [], build: ['build', '123'] }
|
|
17
|
-
* parse('1.0.0-beta+exp.sha.5114f85') // { major: 1, minor: 0, patch: 0, prerelease: ['beta'], build: ['exp', 'sha', '5114f85'] }
|
|
18
|
-
* @since 2.0.0
|
|
19
|
-
*/
|
|
20
2
|
function parse(version) {
|
|
3
|
+
if (version === void 0 || version === null) return version;
|
|
21
4
|
const [versionWithPrerelease, buildString] = version.replace(/^v/, "").split("+");
|
|
22
5
|
const build = buildString ? buildString.split(".") : [];
|
|
23
6
|
const [coreVersion, prereleaseString] = versionWithPrerelease.split("-");
|
|
@@ -105,22 +88,10 @@ function compare(version1, version2) {
|
|
|
105
88
|
}
|
|
106
89
|
//#endregion
|
|
107
90
|
//#region helpers/version/increment.ts
|
|
108
|
-
/**
|
|
109
|
-
* This file is part of helpers4.
|
|
110
|
-
* Copyright (C) 2025 baxyz
|
|
111
|
-
* SPDX-License-Identifier: LGPL-3.0-or-later
|
|
112
|
-
*/
|
|
113
|
-
/**
|
|
114
|
-
* Increments a semantic version
|
|
115
|
-
* @param version - The version to increment
|
|
116
|
-
* @param type - The increment type ('major', 'minor', 'patch')
|
|
117
|
-
* @returns Incremented version string
|
|
118
|
-
* @since 1.9.0
|
|
119
|
-
*/
|
|
120
91
|
function increment(version, type) {
|
|
121
|
-
|
|
92
|
+
if (version === void 0 || version === null) return version;
|
|
122
93
|
const hasV = version.startsWith("v");
|
|
123
|
-
const parts =
|
|
94
|
+
const parts = version.replace(/^v/, "").split(".").map(Number);
|
|
124
95
|
while (parts.length < 3) parts.push(0);
|
|
125
96
|
let [major, minor, patch] = parts;
|
|
126
97
|
switch (type) {
|
|
@@ -156,21 +127,20 @@ function increment(version, type) {
|
|
|
156
127
|
* @since 1.9.0
|
|
157
128
|
*/
|
|
158
129
|
function satisfiesRange(version, range) {
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
if (
|
|
162
|
-
if (range.startsWith("
|
|
163
|
-
if (range.startsWith("
|
|
164
|
-
if (range.startsWith("
|
|
165
|
-
if (range.startsWith("<")) return compareVersionsSimple(normalizedVersion, normalize(range.slice(1))) < 0;
|
|
130
|
+
const normalizedVersion = version.replace(/^v/, "");
|
|
131
|
+
if (!range.match(/[~^<>=]/)) return normalizedVersion === range.replace(/^v/, "");
|
|
132
|
+
if (range.startsWith(">=")) return compareVersionsSimple(normalizedVersion, range.slice(2).replace(/^v/, "")) >= 0;
|
|
133
|
+
if (range.startsWith(">")) return compareVersionsSimple(normalizedVersion, range.slice(1).replace(/^v/, "")) > 0;
|
|
134
|
+
if (range.startsWith("<=")) return compareVersionsSimple(normalizedVersion, range.slice(2).replace(/^v/, "")) <= 0;
|
|
135
|
+
if (range.startsWith("<")) return compareVersionsSimple(normalizedVersion, range.slice(1).replace(/^v/, "")) < 0;
|
|
166
136
|
if (range.startsWith("^")) {
|
|
167
|
-
const targetVersion =
|
|
137
|
+
const targetVersion = range.slice(1).replace(/^v/, "");
|
|
168
138
|
const [targetMajor] = targetVersion.split(".").map(Number);
|
|
169
139
|
const [versionMajor] = normalizedVersion.split(".").map(Number);
|
|
170
140
|
return versionMajor === targetMajor && compareVersionsSimple(normalizedVersion, targetVersion) >= 0;
|
|
171
141
|
}
|
|
172
142
|
if (range.startsWith("~")) {
|
|
173
|
-
const targetVersion =
|
|
143
|
+
const targetVersion = range.slice(1).replace(/^v/, "");
|
|
174
144
|
const [targetMajor, targetMinor] = targetVersion.split(".").map(Number);
|
|
175
145
|
const [versionMajor, versionMinor] = normalizedVersion.split(".").map(Number);
|
|
176
146
|
return versionMajor === targetMajor && versionMinor === targetMinor && compareVersionsSimple(normalizedVersion, targetVersion) >= 0;
|
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 {\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(\n version: string,\n type: 'major' | 'minor' | 'patch'\n): string {\n const normalize = (v: string) => v.replace(/^v/, '');\n const hasV = version.startsWith('v');\n const normalizedVersion = normalize(version);\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 normalize = (v: string) => v.replace(/^v/, '');\n const normalizedVersion = normalize(version);\n\n // Handle exact match\n if (!range.match(/[~^<>=]/)) {\n return normalizedVersion === normalize(range);\n }\n\n // Handle >= operator\n if (range.startsWith('>=')) {\n const targetVersion = normalize(range.slice(2));\n return compareVersionsSimple(normalizedVersion, targetVersion) >= 0;\n }\n\n // Handle > operator\n if (range.startsWith('>')) {\n const targetVersion = normalize(range.slice(1));\n return compareVersionsSimple(normalizedVersion, targetVersion) > 0;\n }\n\n // Handle <= operator\n if (range.startsWith('<=')) {\n const targetVersion = normalize(range.slice(2));\n return compareVersionsSimple(normalizedVersion, targetVersion) <= 0;\n }\n\n // Handle < operator\n if (range.startsWith('<')) {\n const targetVersion = normalize(range.slice(1));\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 = normalize(range.slice(1));\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 = normalize(range.slice(1));\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":";;;;;;;;;;;;;;;;;;;AAyCA,SAAgB,MAAM,SAAgC;CAKpD,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;;;;;;;;;;;;;;;;;;;;AC3CH,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,MA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SAAS,MAAM,IAAI,CAAC,IAAI,OAAO;CAE9C,MAAM,YAAY,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;;;;AC1DT,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/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,K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X,SAAS,sBAAsB,UAAkB,UAA0B;CACzE,MAAM,SAAS,SAAS,MAAM,IAAI,CAAC,IAAI,OAAO;CAC9C,MAAM,SAAS,SAAS,MAAM,IAAI,CAAC,IAAI,OAAO;CAE9C,MAAM,YAAY,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"}
|
package/llms.txt
ADDED
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
# @helpers4/version
|
|
2
|
+
|
|
3
|
+
> Tree-shakable TypeScript utility functions for the `version` domain.
|
|
4
|
+
> Package: `@helpers4/version` — Version: 2.0.0-alpha.15
|
|
5
|
+
> License: LGPL-3.0-or-later
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install @helpers4/version
|
|
11
|
+
# or
|
|
12
|
+
pnpm add @helpers4/version
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { compare, increment, parse, ... } from '@helpers4/version';
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Functions
|
|
22
|
+
|
|
23
|
+
| Function | Description |
|
|
24
|
+
|---|---|
|
|
25
|
+
| `compare` | Compares two semantic version strings according to SemVer 2.0.0 specification Supports: - Core vers |
|
|
26
|
+
| `increment` | Increments a semantic version |
|
|
27
|
+
| `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
|
+
| `satisfiesRange` | Checks if a version satisfies a range (simple implementation) |
|
|
30
|
+
| `stripV` | Strip the leading "v" from a version string if it exists. |
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## API Reference
|
|
35
|
+
|
|
36
|
+
### `compare`
|
|
37
|
+
|
|
38
|
+
Compares two semantic version strings according to SemVer 2.0.0 specification
|
|
39
|
+
|
|
40
|
+
Supports:
|
|
41
|
+
- Core version: MAJOR.MINOR.PATCH
|
|
42
|
+
- Pre-release: -alpha, -beta.1, -rc.1, etc.
|
|
43
|
+
- Build metadata: +build, +sha.abc123 (ignored in comparison per spec)
|
|
44
|
+
- Optional 'v' prefix
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
import { compare } from '@helpers4/version';
|
|
48
|
+
|
|
49
|
+
compare(version1: string, version2: string): number
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
**Parameters:**
|
|
53
|
+
|
|
54
|
+
- `version1: string` — First version string
|
|
55
|
+
- `version2: string` — Second version string
|
|
56
|
+
|
|
57
|
+
**Returns:** `number` — -1 if version1 < version2, 0 if equal, 1 if version1 > version2
|
|
58
|
+
|
|
59
|
+
**Examples:**
|
|
60
|
+
|
|
61
|
+
*Compare two semver versions*
|
|
62
|
+
|
|
63
|
+
Returns -1, 0, or 1 based on SemVer ordering.
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
compare('1.0.0', '2.0.0') // => -1
|
|
67
|
+
compare('1.0.0', '1.0.0') // => 0
|
|
68
|
+
compare('2.0.0', '1.0.0') // => 1
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
*Prerelease is lower than release*
|
|
72
|
+
|
|
73
|
+
A prerelease version is always less than the release.
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
compare('1.0.0-alpha', '1.0.0')
|
|
77
|
+
// => -1
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
### `increment`
|
|
83
|
+
|
|
84
|
+
Increments a semantic version
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
import { increment } from '@helpers4/version';
|
|
88
|
+
|
|
89
|
+
increment(version: string, type: "major" | "minor" | "patch"): string
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
**Parameters:**
|
|
93
|
+
|
|
94
|
+
- `version: string` — The version to increment
|
|
95
|
+
- `type: "major" | "minor" | "patch"` — The increment type ('major', 'minor', 'patch')
|
|
96
|
+
|
|
97
|
+
**Returns:** `string` — Incremented version string
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
import { increment } from '@helpers4/version';
|
|
101
|
+
|
|
102
|
+
increment(version: undefined, type: "major" | "minor" | "patch"): undefined
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
**Parameters:**
|
|
106
|
+
|
|
107
|
+
- `version: undefined` — The version to increment
|
|
108
|
+
- `type: "major" | "minor" | "patch"` — The increment type ('major', 'minor', 'patch')
|
|
109
|
+
|
|
110
|
+
**Returns:** `undefined` — Incremented version string
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
import { increment } from '@helpers4/version';
|
|
114
|
+
|
|
115
|
+
increment(version: null, type: "major" | "minor" | "patch"): null
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
**Parameters:**
|
|
119
|
+
|
|
120
|
+
- `version: null` — The version to increment
|
|
121
|
+
- `type: "major" | "minor" | "patch"` — The increment type ('major', 'minor', 'patch')
|
|
122
|
+
|
|
123
|
+
**Returns:** `null` — Incremented version string
|
|
124
|
+
|
|
125
|
+
**Examples:**
|
|
126
|
+
|
|
127
|
+
*Increment the patch version*
|
|
128
|
+
|
|
129
|
+
Bumps the patch number while keeping major and minor.
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
increment('1.2.3', 'patch')
|
|
133
|
+
// => '1.2.4'
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
*Increment the minor version*
|
|
137
|
+
|
|
138
|
+
Bumps the minor number and resets patch to 0.
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
increment('1.2.3', 'minor')
|
|
142
|
+
// => '1.3.0'
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
*Preserve the v prefix*
|
|
146
|
+
|
|
147
|
+
The v prefix is preserved if present in the input.
|
|
148
|
+
|
|
149
|
+
```typescript
|
|
150
|
+
increment('v1.0.0', 'major')
|
|
151
|
+
// => 'v2.0.0'
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
### `parse`
|
|
157
|
+
|
|
158
|
+
Parses a semantic version string into its components according to SemVer 2.0.0 specification
|
|
159
|
+
|
|
160
|
+
Supports:
|
|
161
|
+
- Core version: MAJOR.MINOR.PATCH
|
|
162
|
+
- Pre-release: -alpha, -beta.1, -rc.1, -0.3.7, -x.7.z.92
|
|
163
|
+
- Build metadata: +build, +sha.abc123, +20130313144700
|
|
164
|
+
- Optional 'v' prefix (commonly used in git tags)
|
|
165
|
+
|
|
166
|
+
```typescript
|
|
167
|
+
import { parse } from '@helpers4/version';
|
|
168
|
+
|
|
169
|
+
parse(version: string): ParsedVersion
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
**Parameters:**
|
|
173
|
+
|
|
174
|
+
- `version: string` — Version string to parse
|
|
175
|
+
|
|
176
|
+
**Returns:** `ParsedVersion` — Parsed version object with major, minor, patch, prerelease, and build
|
|
177
|
+
|
|
178
|
+
```typescript
|
|
179
|
+
import { parse } from '@helpers4/version';
|
|
180
|
+
|
|
181
|
+
parse(version: undefined): undefined
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
**Parameters:**
|
|
185
|
+
|
|
186
|
+
- `version: undefined` — Version string to parse
|
|
187
|
+
|
|
188
|
+
**Returns:** `undefined` — Parsed version object with major, minor, patch, prerelease, and build
|
|
189
|
+
|
|
190
|
+
```typescript
|
|
191
|
+
import { parse } from '@helpers4/version';
|
|
192
|
+
|
|
193
|
+
parse(version: null): null
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
**Parameters:**
|
|
197
|
+
|
|
198
|
+
- `version: null` — Version string to parse
|
|
199
|
+
|
|
200
|
+
**Returns:** `null` — Parsed version object with major, minor, patch, prerelease, and build
|
|
201
|
+
|
|
202
|
+
**Examples:**
|
|
203
|
+
|
|
204
|
+
*Parse a semver string*
|
|
205
|
+
|
|
206
|
+
Breaks a semantic version string into its components.
|
|
207
|
+
|
|
208
|
+
```typescript
|
|
209
|
+
parse('1.2.3')
|
|
210
|
+
// => { major: 1, minor: 2, patch: 3, prerelease: [], build: [] }
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
*Parse a prerelease version*
|
|
214
|
+
|
|
215
|
+
Handles prerelease identifiers and optional v prefix.
|
|
216
|
+
|
|
217
|
+
```typescript
|
|
218
|
+
parse('v2.0.0-alpha.1')
|
|
219
|
+
// => { major: 2, minor: 0, patch: 0, prerelease: ['alpha', '1'], build: [] }
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
---
|
|
223
|
+
|
|
224
|
+
### `ParsedVersion`
|
|
225
|
+
|
|
226
|
+
Represents a parsed semantic version according to SemVer 2.0.0 specification
|
|
227
|
+
|
|
228
|
+
---
|
|
229
|
+
|
|
230
|
+
### `satisfiesRange`
|
|
231
|
+
|
|
232
|
+
Checks if a version satisfies a range (simple implementation)
|
|
233
|
+
|
|
234
|
+
```typescript
|
|
235
|
+
import { satisfiesRange } from '@helpers4/version';
|
|
236
|
+
|
|
237
|
+
satisfiesRange(version: string, range: string): boolean
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
**Parameters:**
|
|
241
|
+
|
|
242
|
+
- `version: string` — Version to check
|
|
243
|
+
- `range: string` — Range pattern (e.g., ">=1.0.0", "~1.2.0", "^1.0.0")
|
|
244
|
+
|
|
245
|
+
**Returns:** `boolean` — True if version satisfies the range
|
|
246
|
+
|
|
247
|
+
**Examples:**
|
|
248
|
+
|
|
249
|
+
*Check caret range*
|
|
250
|
+
|
|
251
|
+
Caret (^) allows patch and minor updates within the same major.
|
|
252
|
+
|
|
253
|
+
```typescript
|
|
254
|
+
satisfiesRange('1.2.3', '^1.0.0')
|
|
255
|
+
// => true
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
*Check greater-than-or-equal range*
|
|
259
|
+
|
|
260
|
+
The >= operator checks if the version is at least the specified value.
|
|
261
|
+
|
|
262
|
+
```typescript
|
|
263
|
+
satisfiesRange('2.0.0', '>=1.5.0')
|
|
264
|
+
// => true
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
*Out of range*
|
|
268
|
+
|
|
269
|
+
Returns false when the version does not satisfy the range.
|
|
270
|
+
|
|
271
|
+
```typescript
|
|
272
|
+
satisfiesRange('0.9.0', '>=1.0.0')
|
|
273
|
+
// => false
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
---
|
|
277
|
+
|
|
278
|
+
### `stripV`
|
|
279
|
+
|
|
280
|
+
Strip the leading "v" from a version string if it exists.
|
|
281
|
+
|
|
282
|
+
```typescript
|
|
283
|
+
import { stripV } from '@helpers4/version';
|
|
284
|
+
|
|
285
|
+
stripV(version: string): string
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
**Parameters:**
|
|
289
|
+
|
|
290
|
+
- `version: string` — The version string to process
|
|
291
|
+
|
|
292
|
+
**Returns:** `string` — The version string without leading "v", or the original value if it's not a string or doesn't start with "v"
|
|
293
|
+
|
|
294
|
+
```typescript
|
|
295
|
+
import { stripV } from '@helpers4/version';
|
|
296
|
+
|
|
297
|
+
stripV(version: null): null
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
**Parameters:**
|
|
301
|
+
|
|
302
|
+
- `version: null` — The version string to process
|
|
303
|
+
|
|
304
|
+
**Returns:** `null` — The version string without leading "v", or the original value if it's not a string or doesn't start with "v"
|
|
305
|
+
|
|
306
|
+
```typescript
|
|
307
|
+
import { stripV } from '@helpers4/version';
|
|
308
|
+
|
|
309
|
+
stripV(version: undefined): undefined
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
**Parameters:**
|
|
313
|
+
|
|
314
|
+
- `version: undefined` — The version string to process
|
|
315
|
+
|
|
316
|
+
**Returns:** `undefined` — The version string without leading "v", or the original value if it's not a string or doesn't start with "v"
|
|
317
|
+
|
|
318
|
+
**Examples:**
|
|
319
|
+
|
|
320
|
+
*Remove v prefix from a version string*
|
|
321
|
+
|
|
322
|
+
Strips the leading "v" from a git tag-style version string.
|
|
323
|
+
|
|
324
|
+
```typescript
|
|
325
|
+
stripV('v1.2.3')
|
|
326
|
+
// => '1.2.3'
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
*No-op when there is no v prefix*
|
|
330
|
+
|
|
331
|
+
Returns the string unchanged when it does not start with "v".
|
|
332
|
+
|
|
333
|
+
```typescript
|
|
334
|
+
stripV('1.2.3')
|
|
335
|
+
// => '1.2.3'
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
---
|
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.15",
|
|
4
4
|
"functions": [
|
|
5
5
|
{
|
|
6
6
|
"name": "compare",
|
|
@@ -68,6 +68,46 @@
|
|
|
68
68
|
"type": "string",
|
|
69
69
|
"description": "Incremented version string"
|
|
70
70
|
}
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
"signature": "increment(version: undefined, type: \"major\" | \"minor\" | \"patch\"): undefined",
|
|
74
|
+
"description": "Increments a semantic version",
|
|
75
|
+
"params": [
|
|
76
|
+
{
|
|
77
|
+
"name": "version",
|
|
78
|
+
"type": "undefined",
|
|
79
|
+
"description": "The version to increment"
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
"name": "type",
|
|
83
|
+
"type": "\"major\" | \"minor\" | \"patch\"",
|
|
84
|
+
"description": "The increment type ('major', 'minor', 'patch')"
|
|
85
|
+
}
|
|
86
|
+
],
|
|
87
|
+
"returns": {
|
|
88
|
+
"type": "undefined",
|
|
89
|
+
"description": "Incremented version string"
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
"signature": "increment(version: null, type: \"major\" | \"minor\" | \"patch\"): null",
|
|
94
|
+
"description": "Increments a semantic version",
|
|
95
|
+
"params": [
|
|
96
|
+
{
|
|
97
|
+
"name": "version",
|
|
98
|
+
"type": "null",
|
|
99
|
+
"description": "The version to increment"
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
"name": "type",
|
|
103
|
+
"type": "\"major\" | \"minor\" | \"patch\"",
|
|
104
|
+
"description": "The increment type ('major', 'minor', 'patch')"
|
|
105
|
+
}
|
|
106
|
+
],
|
|
107
|
+
"returns": {
|
|
108
|
+
"type": "null",
|
|
109
|
+
"description": "Incremented version string"
|
|
110
|
+
}
|
|
71
111
|
}
|
|
72
112
|
],
|
|
73
113
|
"examples": [
|
|
@@ -109,6 +149,36 @@
|
|
|
109
149
|
"type": "ParsedVersion",
|
|
110
150
|
"description": "Parsed version object with major, minor, patch, prerelease, and build"
|
|
111
151
|
}
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
"signature": "parse(version: undefined): undefined",
|
|
155
|
+
"description": "Parses a semantic version string into its components according to SemVer 2.0.0 specification\n\nSupports:\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)",
|
|
156
|
+
"params": [
|
|
157
|
+
{
|
|
158
|
+
"name": "version",
|
|
159
|
+
"type": "undefined",
|
|
160
|
+
"description": "Version string to parse"
|
|
161
|
+
}
|
|
162
|
+
],
|
|
163
|
+
"returns": {
|
|
164
|
+
"type": "undefined",
|
|
165
|
+
"description": "Parsed version object with major, minor, patch, prerelease, and build"
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
"signature": "parse(version: null): null",
|
|
170
|
+
"description": "Parses a semantic version string into its components according to SemVer 2.0.0 specification\n\nSupports:\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)",
|
|
171
|
+
"params": [
|
|
172
|
+
{
|
|
173
|
+
"name": "version",
|
|
174
|
+
"type": "null",
|
|
175
|
+
"description": "Version string to parse"
|
|
176
|
+
}
|
|
177
|
+
],
|
|
178
|
+
"returns": {
|
|
179
|
+
"type": "null",
|
|
180
|
+
"description": "Parsed version object with major, minor, patch, prerelease, and build"
|
|
181
|
+
}
|
|
112
182
|
}
|
|
113
183
|
],
|
|
114
184
|
"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.15",
|
|
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",
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"./meta/api.json": "./meta/api.json",
|
|
22
22
|
"./meta/examples.json": "./meta/examples.json",
|
|
23
23
|
"./meta/licenses.json": "./meta/licenses.json",
|
|
24
|
+
"./llms.txt": "./llms.txt",
|
|
24
25
|
"./package.json": "./package.json"
|
|
25
26
|
},
|
|
26
27
|
"keywords": [
|
|
@@ -37,6 +38,7 @@
|
|
|
37
38
|
"lib/index.d.ts",
|
|
38
39
|
"lib/index.js.map",
|
|
39
40
|
"meta/",
|
|
41
|
+
"llms.txt",
|
|
40
42
|
"LICENSE.md",
|
|
41
43
|
"package.json",
|
|
42
44
|
"README.md"
|