@glion/util-semver 0.14.1
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/LICENSE +21 -0
- package/README.md +379 -0
- package/dist/collection.d.ts +67 -0
- package/dist/collection.d.ts.map +1 -0
- package/dist/compare.d.ts +124 -0
- package/dist/compare.d.ts.map +1 -0
- package/dist/errors.d.ts +19 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +504 -0
- package/dist/index.js.map +1 -0
- package/dist/parse.d.ts +81 -0
- package/dist/parse.d.ts.map +1 -0
- package/dist/range.d.ts +73 -0
- package/dist/range.d.ts.map +1 -0
- package/dist/types.d.ts +30 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +50 -0
package/dist/range.d.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { Comparator } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Pre-parsed range expression for efficient reuse.
|
|
4
|
+
*
|
|
5
|
+
* Parse a range once and reuse it for multiple version checks,
|
|
6
|
+
* avoiding repeated parsing overhead.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // Parse once
|
|
11
|
+
* const range = new Range(">=2.0 <3.0");
|
|
12
|
+
*
|
|
13
|
+
* // Reuse many times (much faster than re-parsing)
|
|
14
|
+
* satisfies("2.5.1", range); // => true
|
|
15
|
+
* satisfies("2.3.0", range); // => true
|
|
16
|
+
* satisfies("3.0.0", range); // => false
|
|
17
|
+
* ```;
|
|
18
|
+
*/
|
|
19
|
+
export declare class Range {
|
|
20
|
+
readonly comparators: readonly Comparator[];
|
|
21
|
+
readonly raw: string;
|
|
22
|
+
constructor(range: string);
|
|
23
|
+
/**
|
|
24
|
+
* Test if a version satisfies this range.
|
|
25
|
+
*
|
|
26
|
+
* @param version - Version string to test
|
|
27
|
+
* @returns True if version satisfies all comparators
|
|
28
|
+
* @throws {VersionParseError} If version string is invalid
|
|
29
|
+
*/
|
|
30
|
+
test(version: string): boolean;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Checks if a version satisfies a range expression.
|
|
34
|
+
*
|
|
35
|
+
* Range expressions consist of one or more space-separated comparators.
|
|
36
|
+
* Each comparator is an optional operator followed by a version.
|
|
37
|
+
*
|
|
38
|
+
* Supported operators:
|
|
39
|
+
*
|
|
40
|
+
* - `=` (or no operator): exact match
|
|
41
|
+
* - `<`: less than
|
|
42
|
+
* - `<=`: less than or equal
|
|
43
|
+
* - `>`: greater than
|
|
44
|
+
* - `>=`: greater than or equal
|
|
45
|
+
*
|
|
46
|
+
* Multiple comparators create AND conditions - all must be satisfied.
|
|
47
|
+
*
|
|
48
|
+
* For performance when checking many versions against the same range,
|
|
49
|
+
* use a Range object instead of a string.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* // String range (parsed every call)
|
|
54
|
+
* satisfies("2.5.1", ">=2.0 <3.0"); // => true
|
|
55
|
+
* satisfies("2.5.1", "2.5.1"); // => true (exact match)
|
|
56
|
+
* satisfies("2.5.1", ">=2.6"); // => false
|
|
57
|
+
*
|
|
58
|
+
* // Range object (parse once, reuse many times - much faster)
|
|
59
|
+
* const range = new Range(">=2.0 <3.0");
|
|
60
|
+
* satisfies("2.5.1", range); // => true
|
|
61
|
+
* satisfies("2.3.0", range); // => true
|
|
62
|
+
* satisfies("3.0.0", range); // => false
|
|
63
|
+
* ```;
|
|
64
|
+
*
|
|
65
|
+
* @param version - Version string to test
|
|
66
|
+
* @param range - Range expression string or pre-parsed Range object
|
|
67
|
+
* @returns True if version satisfies all comparators, false for empty range
|
|
68
|
+
* @throws {VersionParseError} If version string is invalid
|
|
69
|
+
* @throws {RangeParseError} If range expression is invalid or exceeds length
|
|
70
|
+
* limit
|
|
71
|
+
*/
|
|
72
|
+
export declare function satisfies(version: string, range: string | Range): boolean;
|
|
73
|
+
//# sourceMappingURL=range.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"range.d.ts","sourceRoot":"","sources":["../src/range.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAqD1C;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,KAAK;IAChB,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;IAC5C,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;gBAET,KAAK,EAAE,MAAM;IAczB;;;;;;OAMG;IACH,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;CAc/B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,KAAK,GAAG,OAAO,CAGzE"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a semantic version with major, minor, and patch components.
|
|
3
|
+
*/
|
|
4
|
+
export interface Hl7Version {
|
|
5
|
+
major: number;
|
|
6
|
+
minor: number;
|
|
7
|
+
patch: number;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Comparison operators supported in version ranges.
|
|
11
|
+
*/
|
|
12
|
+
export type ComparisonOperator = "=" | "<" | "<=" | ">" | ">=";
|
|
13
|
+
/**
|
|
14
|
+
* Internal representation of a version range comparator.
|
|
15
|
+
*/
|
|
16
|
+
export interface Comparator {
|
|
17
|
+
op: ComparisonOperator;
|
|
18
|
+
v: Hl7Version;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Result of a comparison operation.
|
|
22
|
+
*/
|
|
23
|
+
export type ComparisonResult = -1 | 0 | 1;
|
|
24
|
+
/**
|
|
25
|
+
* Security constraints for input validation.
|
|
26
|
+
*/
|
|
27
|
+
export declare const MAX_VERSION_STRING_LENGTH = 100;
|
|
28
|
+
export declare const MAX_RANGE_STRING_LENGTH = 1000;
|
|
29
|
+
export declare const MAX_SAFE_VERSION_COMPONENT: number;
|
|
30
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,GAAG,GAAG,GAAG,GAAG,IAAI,GAAG,GAAG,GAAG,IAAI,CAAC;AAE/D;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,kBAAkB,CAAC;IACvB,CAAC,EAAE,UAAU,CAAC;CACf;AAED;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAE1C;;GAEG;AACH,eAAO,MAAM,yBAAyB,MAAM,CAAC;AAC7C,eAAO,MAAM,uBAAuB,OAAO,CAAC;AAC5C,eAAO,MAAM,0BAA0B,QAAc,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@glion/util-semver",
|
|
3
|
+
"version": "0.14.1",
|
|
4
|
+
"description": "Tiny, fast HL7v2 version and range utilities (basic comparators only)",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"health",
|
|
7
|
+
"healthcare",
|
|
8
|
+
"hl7",
|
|
9
|
+
"hl7v2",
|
|
10
|
+
"nodejs",
|
|
11
|
+
"typescript"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://glion.dev",
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"author": {
|
|
16
|
+
"name": "Melek Somai",
|
|
17
|
+
"email": "melek@rethinkhealth.io"
|
|
18
|
+
},
|
|
19
|
+
"repository": "rethinkhealth/glion.git",
|
|
20
|
+
"files": [
|
|
21
|
+
"dist"
|
|
22
|
+
],
|
|
23
|
+
"type": "module",
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": "./dist/index.js"
|
|
27
|
+
},
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/node": "^25.5.0",
|
|
33
|
+
"@vitest/coverage-v8": "4.1.2",
|
|
34
|
+
"tsdown": "0.21.7",
|
|
35
|
+
"typescript": "^5.9.3",
|
|
36
|
+
"vitest": "4.1.2",
|
|
37
|
+
"@glion/testing": "0.0.2",
|
|
38
|
+
"@glion/tsconfig": "0.0.1"
|
|
39
|
+
},
|
|
40
|
+
"engines": {
|
|
41
|
+
"node": ">=18"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build": "tsdown && tsc --emitDeclarationOnly",
|
|
45
|
+
"check-types": "tsc --noEmit",
|
|
46
|
+
"test": "vitest run",
|
|
47
|
+
"test:coverage": "vitest run --coverage",
|
|
48
|
+
"test:watch": "vitest"
|
|
49
|
+
}
|
|
50
|
+
}
|