@helpers4/version 2.0.0-alpha.6 → 2.0.0-alpha.8
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 +1 -1
- package/lib/index.d.ts +6 -0
- package/lib/index.js +4 -0
- package/lib/index.js.map +1 -1
- package/meta/api.json +250 -0
- package/{examples.json → meta/examples.json} +6 -6
- package/meta/licenses.json +4 -0
- package/package.json +6 -6
- package/api.json +0 -104
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@ A set of helpers for working with URLs.
|
|
|
9
9
|
|
|
10
10
|
## Documentation
|
|
11
11
|
|
|
12
|
-
[https://helpers4.
|
|
12
|
+
[https://helpers4.dev/typescript/categories/version/](https://helpers4.dev/typescript/categories/version/)
|
|
13
13
|
|
|
14
14
|
<!-- AUTOMATIC-METHODS -->
|
|
15
15
|
- compare
|
package/lib/index.d.ts
CHANGED
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
* compare('1.0.0-alpha', '1.0.0-beta') // -1
|
|
22
22
|
* compare('1.0.0-alpha.1', '1.0.0-alpha.2') // -1
|
|
23
23
|
* compare('1.0.0+build1', '1.0.0+build2') // 0 (build metadata ignored)
|
|
24
|
+
* @since 1.9.0
|
|
24
25
|
*/
|
|
25
26
|
declare function compare(version1: string, version2: string): number;
|
|
26
27
|
|
|
@@ -34,6 +35,7 @@ declare function compare(version1: string, version2: string): number;
|
|
|
34
35
|
* @param version - The version to increment
|
|
35
36
|
* @param type - The increment type ('major', 'minor', 'patch')
|
|
36
37
|
* @returns Incremented version string
|
|
38
|
+
* @since 1.9.0
|
|
37
39
|
*/
|
|
38
40
|
declare function increment(version: string, type: 'major' | 'minor' | 'patch'): string;
|
|
39
41
|
|
|
@@ -44,6 +46,7 @@ declare function increment(version: string, type: 'major' | 'minor' | 'patch'):
|
|
|
44
46
|
*/
|
|
45
47
|
/**
|
|
46
48
|
* Represents a parsed semantic version according to SemVer 2.0.0 specification
|
|
49
|
+
* @since 2.0.0
|
|
47
50
|
*/
|
|
48
51
|
interface ParsedVersion {
|
|
49
52
|
/** Major version number */
|
|
@@ -73,6 +76,7 @@ interface ParsedVersion {
|
|
|
73
76
|
* parse('v1.0.0-alpha.1') // { major: 1, minor: 0, patch: 0, prerelease: ['alpha', '1'], build: [] }
|
|
74
77
|
* parse('2.0.0+build.123') // { major: 2, minor: 0, patch: 0, prerelease: [], build: ['build', '123'] }
|
|
75
78
|
* parse('1.0.0-beta+exp.sha.5114f85') // { major: 1, minor: 0, patch: 0, prerelease: ['beta'], build: ['exp', 'sha', '5114f85'] }
|
|
79
|
+
* @since 2.0.0
|
|
76
80
|
*/
|
|
77
81
|
declare function parse(version: string): ParsedVersion;
|
|
78
82
|
|
|
@@ -86,6 +90,7 @@ declare function parse(version: string): ParsedVersion;
|
|
|
86
90
|
* @param version - Version to check
|
|
87
91
|
* @param range - Range pattern (e.g., ">=1.0.0", "~1.2.0", "^1.0.0")
|
|
88
92
|
* @returns True if version satisfies the range
|
|
93
|
+
* @since 1.9.0
|
|
89
94
|
*/
|
|
90
95
|
declare function satisfiesRange(version: string, range: string): boolean;
|
|
91
96
|
|
|
@@ -110,6 +115,7 @@ declare function satisfiesRange(version: string, range: string): boolean;
|
|
|
110
115
|
* stripV("") // ""
|
|
111
116
|
* stripV("1.0.0-beta") // "1.0.0-beta"
|
|
112
117
|
* ```
|
|
118
|
+
* @since 1.9.0
|
|
113
119
|
*/
|
|
114
120
|
declare function stripV(version: string): string;
|
|
115
121
|
declare function stripV(version: null): null;
|
package/lib/index.js
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
* parse('v1.0.0-alpha.1') // { major: 1, minor: 0, patch: 0, prerelease: ['alpha', '1'], build: [] }
|
|
16
16
|
* parse('2.0.0+build.123') // { major: 2, minor: 0, patch: 0, prerelease: [], build: ['build', '123'] }
|
|
17
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
|
|
18
19
|
*/
|
|
19
20
|
function parse(version) {
|
|
20
21
|
const [versionWithPrerelease, buildString] = version.replace(/^v/, "").split("+");
|
|
@@ -92,6 +93,7 @@ function comparePrerelease(pre1, pre2) {
|
|
|
92
93
|
* compare('1.0.0-alpha', '1.0.0-beta') // -1
|
|
93
94
|
* compare('1.0.0-alpha.1', '1.0.0-alpha.2') // -1
|
|
94
95
|
* compare('1.0.0+build1', '1.0.0+build2') // 0 (build metadata ignored)
|
|
96
|
+
* @since 1.9.0
|
|
95
97
|
*/
|
|
96
98
|
function compare(version1, version2) {
|
|
97
99
|
const v1 = parse(version1);
|
|
@@ -113,6 +115,7 @@ function compare(version1, version2) {
|
|
|
113
115
|
* @param version - The version to increment
|
|
114
116
|
* @param type - The increment type ('major', 'minor', 'patch')
|
|
115
117
|
* @returns Incremented version string
|
|
118
|
+
* @since 1.9.0
|
|
116
119
|
*/
|
|
117
120
|
function increment(version, type) {
|
|
118
121
|
const normalize = (v) => v.replace(/^v/, "");
|
|
@@ -150,6 +153,7 @@ function increment(version, type) {
|
|
|
150
153
|
* @param version - Version to check
|
|
151
154
|
* @param range - Range pattern (e.g., ">=1.0.0", "~1.2.0", "^1.0.0")
|
|
152
155
|
* @returns True if version satisfies the range
|
|
156
|
+
* @since 1.9.0
|
|
153
157
|
*/
|
|
154
158
|
function satisfiesRange(version, range) {
|
|
155
159
|
const normalize = (v) => v.replace(/^v/, "");
|
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 */\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 */\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 */\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 */\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 */\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 */\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":";;;;;;;;;;;;;;;;;;AAuCA,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;;;;;;;;;;;;;;;;;;;;ACzCH,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,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AAgB,kBAAkB,MAAM,IAAI,CAAC,IAAI,OAAO;AAE7E,SAAO,iBAAiB,eACtB,iBAAiB,eACjB,sBAAsB,mBAAmB,cAAc,IAAI;OAG7D,QAAO;;AAIX,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;;;;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 {\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,MAAM,O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,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"}
|
package/meta/api.json
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
{
|
|
2
|
+
"category": "version",
|
|
3
|
+
"version": "2.0.0-alpha.8",
|
|
4
|
+
"functions": [
|
|
5
|
+
{
|
|
6
|
+
"name": "compare",
|
|
7
|
+
"kind": "function",
|
|
8
|
+
"description": "Compares two semantic version strings according to SemVer 2.0.0 specification\n\nSupports:\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",
|
|
9
|
+
"since": "1.9.0",
|
|
10
|
+
"signatures": [
|
|
11
|
+
{
|
|
12
|
+
"signature": "compare(version1: string, version2: string): number",
|
|
13
|
+
"description": "Compares two semantic version strings according to SemVer 2.0.0 specification\n\nSupports:\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",
|
|
14
|
+
"params": [
|
|
15
|
+
{
|
|
16
|
+
"name": "version1",
|
|
17
|
+
"type": "string",
|
|
18
|
+
"description": "First version string"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"name": "version2",
|
|
22
|
+
"type": "string",
|
|
23
|
+
"description": "Second version string"
|
|
24
|
+
}
|
|
25
|
+
],
|
|
26
|
+
"returns": {
|
|
27
|
+
"type": "number",
|
|
28
|
+
"description": "-1 if version1 < version2, 0 if equal, 1 if version1 > version2"
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
],
|
|
32
|
+
"examples": [
|
|
33
|
+
{
|
|
34
|
+
"title": "Compare two semver versions",
|
|
35
|
+
"description": "Returns -1, 0, or 1 based on SemVer ordering.",
|
|
36
|
+
"code": "compare('1.0.0', '2.0.0') // => -1\ncompare('1.0.0', '1.0.0') // => 0\ncompare('2.0.0', '1.0.0') // => 1"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"title": "Prerelease is lower than release",
|
|
40
|
+
"description": "A prerelease version is always less than the release.",
|
|
41
|
+
"code": "compare('1.0.0-alpha', '1.0.0')\n// => -1"
|
|
42
|
+
}
|
|
43
|
+
],
|
|
44
|
+
"sourceFile": "compare.ts"
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"name": "increment",
|
|
48
|
+
"kind": "function",
|
|
49
|
+
"description": "Increments a semantic version",
|
|
50
|
+
"since": "1.9.0",
|
|
51
|
+
"signatures": [
|
|
52
|
+
{
|
|
53
|
+
"signature": "increment(version: string, type: \"major\" | \"minor\" | \"patch\"): string",
|
|
54
|
+
"description": "Increments a semantic version",
|
|
55
|
+
"params": [
|
|
56
|
+
{
|
|
57
|
+
"name": "version",
|
|
58
|
+
"type": "string",
|
|
59
|
+
"description": "The version to increment"
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
"name": "type",
|
|
63
|
+
"type": "\"major\" | \"minor\" | \"patch\"",
|
|
64
|
+
"description": "The increment type ('major', 'minor', 'patch')"
|
|
65
|
+
}
|
|
66
|
+
],
|
|
67
|
+
"returns": {
|
|
68
|
+
"type": "string",
|
|
69
|
+
"description": "Incremented version string"
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
],
|
|
73
|
+
"examples": [
|
|
74
|
+
{
|
|
75
|
+
"title": "Increment the patch version",
|
|
76
|
+
"description": "Bumps the patch number while keeping major and minor.",
|
|
77
|
+
"code": "increment('1.2.3', 'patch')\n// => '1.2.4'"
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
"title": "Increment the minor version",
|
|
81
|
+
"description": "Bumps the minor number and resets patch to 0.",
|
|
82
|
+
"code": "increment('1.2.3', 'minor')\n// => '1.3.0'"
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
"title": "Preserve the v prefix",
|
|
86
|
+
"description": "The v prefix is preserved if present in the input.",
|
|
87
|
+
"code": "increment('v1.0.0', 'major')\n// => 'v2.0.0'"
|
|
88
|
+
}
|
|
89
|
+
],
|
|
90
|
+
"sourceFile": "increment.ts"
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
"name": "parse",
|
|
94
|
+
"kind": "function",
|
|
95
|
+
"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)",
|
|
96
|
+
"since": "2.0.0",
|
|
97
|
+
"signatures": [
|
|
98
|
+
{
|
|
99
|
+
"signature": "parse(version: string): ParsedVersion",
|
|
100
|
+
"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)",
|
|
101
|
+
"params": [
|
|
102
|
+
{
|
|
103
|
+
"name": "version",
|
|
104
|
+
"type": "string",
|
|
105
|
+
"description": "Version string to parse"
|
|
106
|
+
}
|
|
107
|
+
],
|
|
108
|
+
"returns": {
|
|
109
|
+
"type": "ParsedVersion",
|
|
110
|
+
"description": "Parsed version object with major, minor, patch, prerelease, and build"
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
],
|
|
114
|
+
"examples": [
|
|
115
|
+
{
|
|
116
|
+
"title": "Parse a semver string",
|
|
117
|
+
"description": "Breaks a semantic version string into its components.",
|
|
118
|
+
"code": "parse('1.2.3')\n// => { major: 1, minor: 2, patch: 3, prerelease: [], build: [] }"
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
"title": "Parse a prerelease version",
|
|
122
|
+
"description": "Handles prerelease identifiers and optional v prefix.",
|
|
123
|
+
"code": "parse('v2.0.0-alpha.1')\n// => { major: 2, minor: 0, patch: 0, prerelease: ['alpha', '1'], build: [] }"
|
|
124
|
+
}
|
|
125
|
+
],
|
|
126
|
+
"sourceFile": "parse.ts"
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
"name": "ParsedVersion",
|
|
130
|
+
"kind": "interface",
|
|
131
|
+
"description": "Represents a parsed semantic version according to SemVer 2.0.0 specification",
|
|
132
|
+
"since": "2.0.0",
|
|
133
|
+
"signatures": [],
|
|
134
|
+
"examples": [],
|
|
135
|
+
"sourceFile": "parse.ts"
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
"name": "satisfiesRange",
|
|
139
|
+
"kind": "function",
|
|
140
|
+
"description": "Checks if a version satisfies a range (simple implementation)",
|
|
141
|
+
"since": "1.9.0",
|
|
142
|
+
"signatures": [
|
|
143
|
+
{
|
|
144
|
+
"signature": "satisfiesRange(version: string, range: string): boolean",
|
|
145
|
+
"description": "Checks if a version satisfies a range (simple implementation)",
|
|
146
|
+
"params": [
|
|
147
|
+
{
|
|
148
|
+
"name": "version",
|
|
149
|
+
"type": "string",
|
|
150
|
+
"description": "Version to check"
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
"name": "range",
|
|
154
|
+
"type": "string",
|
|
155
|
+
"description": "Range pattern (e.g., \">=1.0.0\", \"~1.2.0\", \"^1.0.0\")"
|
|
156
|
+
}
|
|
157
|
+
],
|
|
158
|
+
"returns": {
|
|
159
|
+
"type": "boolean",
|
|
160
|
+
"description": "True if version satisfies the range"
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
],
|
|
164
|
+
"examples": [
|
|
165
|
+
{
|
|
166
|
+
"title": "Check caret range",
|
|
167
|
+
"description": "Caret (^) allows patch and minor updates within the same major.",
|
|
168
|
+
"code": "satisfiesRange('1.2.3', '^1.0.0')\n// => true"
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
"title": "Check greater-than-or-equal range",
|
|
172
|
+
"description": "The >= operator checks if the version is at least the specified value.",
|
|
173
|
+
"code": "satisfiesRange('2.0.0', '>=1.5.0')\n// => true"
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
"title": "Out of range",
|
|
177
|
+
"description": "Returns false when the version does not satisfy the range.",
|
|
178
|
+
"code": "satisfiesRange('0.9.0', '>=1.0.0')\n// => false"
|
|
179
|
+
}
|
|
180
|
+
],
|
|
181
|
+
"sourceFile": "satisfiesRange.ts"
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
"name": "stripV",
|
|
185
|
+
"kind": "function",
|
|
186
|
+
"description": "Strip the leading \"v\" from a version string if it exists.",
|
|
187
|
+
"since": "1.9.0",
|
|
188
|
+
"signatures": [
|
|
189
|
+
{
|
|
190
|
+
"signature": "stripV(version: string): string",
|
|
191
|
+
"description": "Strip the leading \"v\" from a version string if it exists.",
|
|
192
|
+
"params": [
|
|
193
|
+
{
|
|
194
|
+
"name": "version",
|
|
195
|
+
"type": "string",
|
|
196
|
+
"description": "The version string to process"
|
|
197
|
+
}
|
|
198
|
+
],
|
|
199
|
+
"returns": {
|
|
200
|
+
"type": "string",
|
|
201
|
+
"description": "The version string without leading \"v\", or the original value if it's not a string or doesn't start with \"v\""
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
"signature": "stripV(version: null): null",
|
|
206
|
+
"description": "Strip the leading \"v\" from a version string if it exists.",
|
|
207
|
+
"params": [
|
|
208
|
+
{
|
|
209
|
+
"name": "version",
|
|
210
|
+
"type": "null",
|
|
211
|
+
"description": "The version string to process"
|
|
212
|
+
}
|
|
213
|
+
],
|
|
214
|
+
"returns": {
|
|
215
|
+
"type": "null",
|
|
216
|
+
"description": "The version string without leading \"v\", or the original value if it's not a string or doesn't start with \"v\""
|
|
217
|
+
}
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
"signature": "stripV(version: undefined): undefined",
|
|
221
|
+
"description": "Strip the leading \"v\" from a version string if it exists.",
|
|
222
|
+
"params": [
|
|
223
|
+
{
|
|
224
|
+
"name": "version",
|
|
225
|
+
"type": "undefined",
|
|
226
|
+
"description": "The version string to process"
|
|
227
|
+
}
|
|
228
|
+
],
|
|
229
|
+
"returns": {
|
|
230
|
+
"type": "undefined",
|
|
231
|
+
"description": "The version string without leading \"v\", or the original value if it's not a string or doesn't start with \"v\""
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
],
|
|
235
|
+
"examples": [
|
|
236
|
+
{
|
|
237
|
+
"title": "Remove v prefix from a version string",
|
|
238
|
+
"description": "Strips the leading \"v\" from a git tag-style version string.",
|
|
239
|
+
"code": "stripV('v1.2.3')\n// => '1.2.3'"
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
"title": "No-op when there is no v prefix",
|
|
243
|
+
"description": "Returns the string unchanged when it does not start with \"v\".",
|
|
244
|
+
"code": "stripV('1.2.3')\n// => '1.2.3'"
|
|
245
|
+
}
|
|
246
|
+
],
|
|
247
|
+
"sourceFile": "stripV.ts"
|
|
248
|
+
}
|
|
249
|
+
]
|
|
250
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"category": "version",
|
|
3
|
-
"
|
|
3
|
+
"functions": [
|
|
4
4
|
{
|
|
5
|
-
"
|
|
5
|
+
"name": "compare",
|
|
6
6
|
"examples": [
|
|
7
7
|
{
|
|
8
8
|
"title": "Compare two semver versions",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
]
|
|
18
18
|
},
|
|
19
19
|
{
|
|
20
|
-
"
|
|
20
|
+
"name": "increment",
|
|
21
21
|
"examples": [
|
|
22
22
|
{
|
|
23
23
|
"title": "Increment the patch version",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
]
|
|
38
38
|
},
|
|
39
39
|
{
|
|
40
|
-
"
|
|
40
|
+
"name": "parse",
|
|
41
41
|
"examples": [
|
|
42
42
|
{
|
|
43
43
|
"title": "Parse a semver string",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
]
|
|
53
53
|
},
|
|
54
54
|
{
|
|
55
|
-
"
|
|
55
|
+
"name": "satisfiesRange",
|
|
56
56
|
"examples": [
|
|
57
57
|
{
|
|
58
58
|
"title": "Check caret range",
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
]
|
|
73
73
|
},
|
|
74
74
|
{
|
|
75
|
-
"
|
|
75
|
+
"name": "stripV",
|
|
76
76
|
"examples": [
|
|
77
77
|
{
|
|
78
78
|
"title": "Remove v prefix from a version string",
|
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.8",
|
|
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",
|
|
@@ -17,8 +17,9 @@
|
|
|
17
17
|
"types": "./lib/index.d.ts",
|
|
18
18
|
"import": "./lib/index.js"
|
|
19
19
|
},
|
|
20
|
-
"./
|
|
21
|
-
"./
|
|
20
|
+
"./meta/api.json": "./meta/api.json",
|
|
21
|
+
"./meta/examples.json": "./meta/examples.json",
|
|
22
|
+
"./meta/licenses.json": "./meta/licenses.json",
|
|
22
23
|
"./package.json": "./package.json"
|
|
23
24
|
},
|
|
24
25
|
"keywords": [
|
|
@@ -34,8 +35,7 @@
|
|
|
34
35
|
"lib/index.js",
|
|
35
36
|
"lib/index.d.ts",
|
|
36
37
|
"lib/index.js.map",
|
|
37
|
-
"
|
|
38
|
-
"api.json",
|
|
38
|
+
"meta/",
|
|
39
39
|
"LICENSE.md",
|
|
40
40
|
"package.json",
|
|
41
41
|
"README.md"
|
|
@@ -43,4 +43,4 @@
|
|
|
43
43
|
"engines": {
|
|
44
44
|
"node": ">=18.0.0"
|
|
45
45
|
}
|
|
46
|
-
}
|
|
46
|
+
}
|
package/api.json
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"category": "version",
|
|
3
|
-
"members": [
|
|
4
|
-
{
|
|
5
|
-
"name": "compare",
|
|
6
|
-
"kind": "function",
|
|
7
|
-
"description": "Compares two semantic version strings according to SemVer 2.0.0 specification\n\nSupports:\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",
|
|
8
|
-
"signature": "compare(version1: string, version2: string): number",
|
|
9
|
-
"params": [
|
|
10
|
-
{
|
|
11
|
-
"name": "version1",
|
|
12
|
-
"type": "string",
|
|
13
|
-
"description": "First version string"
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
"name": "version2",
|
|
17
|
-
"type": "string",
|
|
18
|
-
"description": "Second version string"
|
|
19
|
-
}
|
|
20
|
-
],
|
|
21
|
-
"returns": "number",
|
|
22
|
-
"examples": [
|
|
23
|
-
"```ts\ncompare('1.0.0', '2.0.0') // -1\ncompare('1.0.0-alpha', '1.0.0') // -1 (prerelease < release)\ncompare('1.0.0-alpha', '1.0.0-beta') // -1\ncompare('1.0.0-alpha.1', '1.0.0-alpha.2') // -1\ncompare('1.0.0+build1', '1.0.0+build2') // 0 (build metadata ignored)\n```"
|
|
24
|
-
]
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
"name": "increment",
|
|
28
|
-
"kind": "function",
|
|
29
|
-
"description": "Increments a semantic version",
|
|
30
|
-
"signature": "increment(version: string, type: \"major\" | \"minor\" | \"patch\"): string",
|
|
31
|
-
"params": [
|
|
32
|
-
{
|
|
33
|
-
"name": "version",
|
|
34
|
-
"type": "string",
|
|
35
|
-
"description": "The version to increment"
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
"name": "type",
|
|
39
|
-
"type": "\"major\" | \"minor\" | \"patch\"",
|
|
40
|
-
"description": "The increment type ('major', 'minor', 'patch')"
|
|
41
|
-
}
|
|
42
|
-
],
|
|
43
|
-
"returns": "string"
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
"name": "parse",
|
|
47
|
-
"kind": "function",
|
|
48
|
-
"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)",
|
|
49
|
-
"signature": "parse(version: string): ParsedVersion",
|
|
50
|
-
"params": [
|
|
51
|
-
{
|
|
52
|
-
"name": "version",
|
|
53
|
-
"type": "string",
|
|
54
|
-
"description": "Version string to parse"
|
|
55
|
-
}
|
|
56
|
-
],
|
|
57
|
-
"returns": "ParsedVersion",
|
|
58
|
-
"examples": [
|
|
59
|
-
"```ts\nparse('1.2.3') // { major: 1, minor: 2, patch: 3, prerelease: [], build: [] }\nparse('v1.0.0-alpha.1') // { major: 1, minor: 0, patch: 0, prerelease: ['alpha', '1'], build: [] }\nparse('2.0.0+build.123') // { major: 2, minor: 0, patch: 0, prerelease: [], build: ['build', '123'] }\nparse('1.0.0-beta+exp.sha.5114f85') // { major: 1, minor: 0, patch: 0, prerelease: ['beta'], build: ['exp', 'sha', '5114f85'] }\n```"
|
|
60
|
-
]
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
"name": "ParsedVersion",
|
|
64
|
-
"kind": "interface",
|
|
65
|
-
"description": "Represents a parsed semantic version according to SemVer 2.0.0 specification"
|
|
66
|
-
},
|
|
67
|
-
{
|
|
68
|
-
"name": "satisfiesRange",
|
|
69
|
-
"kind": "function",
|
|
70
|
-
"description": "Checks if a version satisfies a range (simple implementation)",
|
|
71
|
-
"signature": "satisfiesRange(version: string, range: string): boolean",
|
|
72
|
-
"params": [
|
|
73
|
-
{
|
|
74
|
-
"name": "version",
|
|
75
|
-
"type": "string",
|
|
76
|
-
"description": "Version to check"
|
|
77
|
-
},
|
|
78
|
-
{
|
|
79
|
-
"name": "range",
|
|
80
|
-
"type": "string",
|
|
81
|
-
"description": "Range pattern (e.g., \">=1.0.0\", \"~1.2.0\", \"^1.0.0\")"
|
|
82
|
-
}
|
|
83
|
-
],
|
|
84
|
-
"returns": "boolean"
|
|
85
|
-
},
|
|
86
|
-
{
|
|
87
|
-
"name": "stripV",
|
|
88
|
-
"kind": "function",
|
|
89
|
-
"description": "Strip the leading \"v\" from a version string if it exists.",
|
|
90
|
-
"signature": "stripV(version: string): string",
|
|
91
|
-
"params": [
|
|
92
|
-
{
|
|
93
|
-
"name": "version",
|
|
94
|
-
"type": "string",
|
|
95
|
-
"description": "The version string to process"
|
|
96
|
-
}
|
|
97
|
-
],
|
|
98
|
-
"returns": "string",
|
|
99
|
-
"examples": [
|
|
100
|
-
"```typescript\nstripV(\"v1.2.3\") // \"1.2.3\"\nstripV(\"1.2.3\") // \"1.2.3\"\nstripV(\"v20.1.0\") // \"20.1.0\"\nstripV(null) // null\nstripV(undefined) // undefined\nstripV(\"\") // \"\"\nstripV(\"1.0.0-beta\") // \"1.0.0-beta\"\n```"
|
|
101
|
-
]
|
|
102
|
-
}
|
|
103
|
-
]
|
|
104
|
-
}
|