@verifyhash/semver-lite 0.1.0 → 0.1.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 +1 -1
- package/README.md +11 -9
- package/index.d.ts +75 -0
- package/package.json +4 -2
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,12 +1,5 @@
|
|
|
1
1
|
# semver-lite
|
|
2
2
|
|
|
3
|
-
<!-- publish-prep -->
|
|
4
|
-
> **TODO (owner): pick the final npm name/scope before publishing.**
|
|
5
|
-
> The npm name is **not** finalized. `package.json` uses the placeholder
|
|
6
|
-
> `PLACEHOLDER-semver-lite` — replace it with the real published name/scope
|
|
7
|
-
> before any `npm publish`. Graduation to a package registry is a
|
|
8
|
-
> **needs-human** decision, not something this project does on its own.
|
|
9
|
-
|
|
10
3
|
A tiny, **zero-dependency, zero-network** Node.js library for **Semantic
|
|
11
4
|
Versioning 2.0.0**: parse a version string, compare two versions by the exact
|
|
12
5
|
SemVer precedence rules (including the fiddly pre-release ordering), and test
|
|
@@ -18,6 +11,16 @@ and no I/O. Drop it into any project.
|
|
|
18
11
|
|
|
19
12
|
Spec reference: <https://semver.org/spec/v2.0.0.html>
|
|
20
13
|
|
|
14
|
+
## Install
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @verifyhash/semver-lite
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Published as [`@verifyhash/semver-lite`](https://www.npmjs.com/package/@verifyhash/semver-lite);
|
|
21
|
+
source lives in the [verifyhash/libs](https://github.com/verifyhash/libs) monorepo.
|
|
22
|
+
Zero runtime dependencies — you can also vendor the folder directly.
|
|
23
|
+
|
|
21
24
|
## Who it's for
|
|
22
25
|
|
|
23
26
|
JavaScript/Node developers who need dependency- or version-logic — "is `1.4.2`
|
|
@@ -173,5 +176,4 @@ every supported range form (exact, `^`, `~`, x-range, comparators, hyphen, and
|
|
|
173
176
|
|
|
174
177
|
## License
|
|
175
178
|
|
|
176
|
-
MIT — see `LICENSE`.
|
|
177
|
-
publishing.)
|
|
179
|
+
MIT — see `LICENSE`.
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type declarations for @verifyhash/semver-lite — zero-dependency SemVer
|
|
3
|
+
* 2.0.0 parse, precedence compare, and a documented practical subset of
|
|
4
|
+
* npm-style range matching (exact, =, comparators, ^, ~, x-ranges, hyphen
|
|
5
|
+
* ranges, || unions, whitespace AND; npm-style prerelease gating).
|
|
6
|
+
*
|
|
7
|
+
* Pure functions over strings; no network, no I/O.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/** A parsed SemVer 2.0.0 version. */
|
|
11
|
+
export interface ParsedVersion {
|
|
12
|
+
major: number;
|
|
13
|
+
minor: number;
|
|
14
|
+
patch: number;
|
|
15
|
+
/**
|
|
16
|
+
* Prerelease identifiers ('1.2.3-alpha.1' -> ['alpha', 1]); purely numeric
|
|
17
|
+
* identifiers are converted to numbers. Empty when there is no prerelease.
|
|
18
|
+
*/
|
|
19
|
+
prerelease: Array<string | number>;
|
|
20
|
+
/** Build-metadata identifiers ('1.2.3+build.5' -> ['build', '5']); empty when absent. */
|
|
21
|
+
build: string[];
|
|
22
|
+
/** Canonical version string WITHOUT build metadata, e.g. '1.2.3-alpha.1'. */
|
|
23
|
+
version: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Parse a SemVer 2.0.0 string (leading/trailing whitespace tolerated).
|
|
28
|
+
* Returns null on invalid input — it does NOT throw.
|
|
29
|
+
*/
|
|
30
|
+
export function parse(v: string): ParsedVersion | null;
|
|
31
|
+
|
|
32
|
+
/** Whether a string is a valid SemVer 2.0.0 version. */
|
|
33
|
+
export function valid(v: string): boolean;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Compare two versions by SemVer precedence (§11). Build metadata is IGNORED.
|
|
37
|
+
* Throws TypeError on an invalid version.
|
|
38
|
+
* @returns -1 if a < b, 0 if equal precedence, 1 if a > b
|
|
39
|
+
*/
|
|
40
|
+
export function compare(a: string, b: string): -1 | 0 | 1;
|
|
41
|
+
|
|
42
|
+
/** a > b by precedence. Throws TypeError on an invalid version. */
|
|
43
|
+
export function gt(a: string, b: string): boolean;
|
|
44
|
+
|
|
45
|
+
/** a < b by precedence. Throws TypeError on an invalid version. */
|
|
46
|
+
export function lt(a: string, b: string): boolean;
|
|
47
|
+
|
|
48
|
+
/** a >= b by precedence. Throws TypeError on an invalid version. */
|
|
49
|
+
export function gte(a: string, b: string): boolean;
|
|
50
|
+
|
|
51
|
+
/** a <= b by precedence. Throws TypeError on an invalid version. */
|
|
52
|
+
export function lte(a: string, b: string): boolean;
|
|
53
|
+
|
|
54
|
+
/** Equal precedence (build metadata ignored). Throws TypeError on an invalid version. */
|
|
55
|
+
export function eq(a: string, b: string): boolean;
|
|
56
|
+
|
|
57
|
+
/** Different precedence. Throws TypeError on an invalid version. */
|
|
58
|
+
export function neq(a: string, b: string): boolean;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Sort a list of versions ascending by precedence. Returns a NEW array; the
|
|
62
|
+
* input is not mutated. Throws TypeError if any entry is invalid.
|
|
63
|
+
*/
|
|
64
|
+
export function sort(list: readonly string[]): string[];
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Does `version` satisfy `range`? Supports the documented subset: exact,
|
|
68
|
+
* =, >/>=/</<= comparators, caret (^), tilde (~ and ~>), x-ranges (1.2.x,
|
|
69
|
+
* 1.x, *), hyphen ranges (1.2.3 - 2.3.4), || unions, and whitespace-joined
|
|
70
|
+
* AND. A prerelease version only matches when some comparator in the set
|
|
71
|
+
* names the same major.minor.patch WITH a prerelease (npm semantics).
|
|
72
|
+
* Returns false (does not throw) for an invalid version or non-string range;
|
|
73
|
+
* throws TypeError on a malformed range token.
|
|
74
|
+
*/
|
|
75
|
+
export function satisfies(version: string, range: string): boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@verifyhash/semver-lite",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Zero-dependency SemVer 2.0.0 parse, precedence compare, and a documented practical subset of npm-style range matching for Node.js.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"semver",
|
|
@@ -15,13 +15,15 @@
|
|
|
15
15
|
"tilde"
|
|
16
16
|
],
|
|
17
17
|
"main": "index.js",
|
|
18
|
+
"types": "index.d.ts",
|
|
18
19
|
"scripts": {
|
|
19
20
|
"test": "node test/index.test.js"
|
|
20
21
|
},
|
|
21
22
|
"license": "MIT",
|
|
22
23
|
"files": [
|
|
23
24
|
"index.js",
|
|
24
|
-
"README.md"
|
|
25
|
+
"README.md",
|
|
26
|
+
"index.d.ts"
|
|
25
27
|
],
|
|
26
28
|
"publishConfig": {
|
|
27
29
|
"access": "public"
|