@vltpkg/semver 0.0.0-0.1730239248325
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 +15 -0
- package/README.md +152 -0
- package/dist/esm/comparator.d.ts +76 -0
- package/dist/esm/comparator.d.ts.map +1 -0
- package/dist/esm/comparator.js +515 -0
- package/dist/esm/comparator.js.map +1 -0
- package/dist/esm/index.d.ts +246 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +400 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/range.d.ts +34 -0
- package/dist/esm/range.d.ts.map +1 -0
- package/dist/esm/range.js +72 -0
- package/dist/esm/range.js.map +1 -0
- package/dist/esm/version.d.ts +79 -0
- package/dist/esm/version.d.ts.map +1 -0
- package/dist/esm/version.js +302 -0
- package/dist/esm/version.js.map +1 -0
- package/package.json +68 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Copyright (c) vlt technology, Inc.
|
|
2
|
+
|
|
3
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
4
|
+
|
|
5
|
+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
6
|
+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
7
|
+
Subject to the terms and conditions of this license, each copyright holder and contributor hereby grants to those receiving rights under this license a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except for failure to satisfy the conditions of this license) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer this software, where such license applies only to those patent claims, already acquired or hereafter acquired, licensable by such copyright holder or contributor that are necessarily infringed by:
|
|
8
|
+
|
|
9
|
+
(a) their Contribution(s) (the licensed copyrights of copyright holders and non-copyrightable additions of contributors, in source or binary form) alone; or
|
|
10
|
+
(b) combination of their Contribution(s) with the work of authorship to which such Contribution(s) was added by such copyright holder or contributor, if, at the time the Contribution is added, such addition causes such combination to be necessarily infringed. The patent license shall not apply to any other combinations which include the Contribution.
|
|
11
|
+
Except as expressly stated above, no rights or licenses from any copyright holder or contributor is granted under this license, whether expressly, by implication, estoppel or otherwise.
|
|
12
|
+
|
|
13
|
+
DISCLAIMER
|
|
14
|
+
|
|
15
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/README.md
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
# `@vltpkg/semver`
|
|
2
|
+
|
|
3
|
+
<img src="https://github.com/darcyclarke/octofiles/assets/459713/8ee74129-34e6-4bd4-8686-82954f424709" width="85" />
|
|
4
|
+
|
|
5
|
+
## Semantic Versions
|
|
6
|
+
|
|
7
|
+
Parsing, validating & comparing Semantic Versions used by `vlt`.
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
```js
|
|
12
|
+
import {
|
|
13
|
+
parse,
|
|
14
|
+
valid,
|
|
15
|
+
parseRange,
|
|
16
|
+
validRange,
|
|
17
|
+
increment,
|
|
18
|
+
satisfies,
|
|
19
|
+
sort,
|
|
20
|
+
compare,
|
|
21
|
+
rsort,
|
|
22
|
+
rcompare,
|
|
23
|
+
filter,
|
|
24
|
+
filterMethod,
|
|
25
|
+
gt,
|
|
26
|
+
lt,
|
|
27
|
+
gte,
|
|
28
|
+
lte,
|
|
29
|
+
eq,
|
|
30
|
+
neq,
|
|
31
|
+
maxSatisfying,
|
|
32
|
+
sortedMaxSatisfying,
|
|
33
|
+
rsortedMaxSatisfying,
|
|
34
|
+
Version,
|
|
35
|
+
Range,
|
|
36
|
+
Comparator,
|
|
37
|
+
} from '@vltpkg/semver'
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Functions
|
|
41
|
+
|
|
42
|
+
- `parse(v)`: Attempt to parse a string as a semantic version,
|
|
43
|
+
returning either a `Version` object or `undefined`.
|
|
44
|
+
- `valid(v)`: Return true if the version is valid
|
|
45
|
+
- `increment(v, type, [identifier])` Increment the specified part
|
|
46
|
+
of the version, and return the resulting object. If a Version
|
|
47
|
+
object is provided, it will be modified in-place.
|
|
48
|
+
- `major(v)`: Return the major version number.
|
|
49
|
+
- `minor(v)`: Return the minor version number.
|
|
50
|
+
- `patch(v)`: Return the patch version number.
|
|
51
|
+
- `prerelease(v)`: Returns an array of prerelease components, or
|
|
52
|
+
`undefined` if none exist. Example: `prerelease('1.2.3-alpha.1') ->
|
|
53
|
+
['alpha', 1]`
|
|
54
|
+
- `build(v)`: Returns an array of build components, or
|
|
55
|
+
`undefined` if none exist. Example: `prerelease('1.2.3+linux.33') ->
|
|
56
|
+
['linux', '33']`
|
|
57
|
+
- `stable(v)`: Returns an array of releases that are considered
|
|
58
|
+
"stable" (ie. no prereleases), or an empty array if non exist.
|
|
59
|
+
|
|
60
|
+
### Comparison
|
|
61
|
+
|
|
62
|
+
These functions all compare version strings or objects
|
|
63
|
+
by their SemVer precedence. (Note that build metadata is not
|
|
64
|
+
considered, as per the SemVer 2.0 specification.)
|
|
65
|
+
|
|
66
|
+
Unless otherwise noted, they throw an error on invalid versions.
|
|
67
|
+
|
|
68
|
+
- `gt(v1, v2)`: `v1 > v2`
|
|
69
|
+
- `gte(v1, v2)`: `v1 >= v2`
|
|
70
|
+
- `lt(v1, v2)`: `v1 < v2`
|
|
71
|
+
- `lte(v1, v2)`: `v1 <= v2`
|
|
72
|
+
- `eq(v1, v2)`: `v1 == v2` This is true even if they're not the
|
|
73
|
+
exact same string. You already know how to compare strings.
|
|
74
|
+
- `neq(v1, v2)`: `v1 != v2` The opposite of `eq`.
|
|
75
|
+
- `compare(v1, v2)`: Return `0` if `v1 == v2`, or `1` if `v1` is greater, or `-1` if
|
|
76
|
+
`v2` is greater. Sorts in ascending order if passed to `Array.sort()`.
|
|
77
|
+
- `sortMethod(v1, v2)`: The same as `compare`, except that
|
|
78
|
+
invalid versions are sorted to the end of the list rather than
|
|
79
|
+
throwing an error.
|
|
80
|
+
- `rcompare(v1, v2)`: Inverse of `compare`
|
|
81
|
+
- `rsortMethod(v1, v2)`: Inverse of `sortMethod`. (Invalid
|
|
82
|
+
versions are still sorted to the end of the list.)
|
|
83
|
+
|
|
84
|
+
### Ranges
|
|
85
|
+
|
|
86
|
+
- `validRange(range)`: Return the valid range or null if it's not valid
|
|
87
|
+
- `satisfies(version, range)`: Return true if the version satisfies the
|
|
88
|
+
range.
|
|
89
|
+
- `highest(versions, range)`: Return the highest version in the list
|
|
90
|
+
that satisfies the range, or `null` if none of them do.
|
|
91
|
+
- `sortedHighest(versions, range)`: Optimized form of `highest`,
|
|
92
|
+
if the version list is known to be sorted in ascending SemVer
|
|
93
|
+
precedence order. If the list is not sorted already, may return
|
|
94
|
+
an incorrect result.
|
|
95
|
+
- `rsortedHighest(versions, range)`: Optimized form of `highest`,
|
|
96
|
+
if the version list is known to be sorted in descending SemVer
|
|
97
|
+
precedence order. If the list is not sorted already, may return
|
|
98
|
+
an incorrect result.
|
|
99
|
+
- `lowest(versions, range)`: Return the lowest version in the list
|
|
100
|
+
that satisfies the range, or `null` if none of them do.
|
|
101
|
+
- `sortedLowest(versions, range)`: Optimized form of `lowest`,
|
|
102
|
+
if the version list is known to be sorted in ascending SemVer
|
|
103
|
+
precedence order. If the list is not sorted already, may return
|
|
104
|
+
an incorrect result.
|
|
105
|
+
- `rsortedLowest(versions, range)`: Optimized form of `lowest`,
|
|
106
|
+
if the version list is known to be sorted in descending SemVer
|
|
107
|
+
precedence order. If the list is not sorted already, may return
|
|
108
|
+
an incorrect result.
|
|
109
|
+
|
|
110
|
+
### Classes
|
|
111
|
+
|
|
112
|
+
- `Version` Object representation of a SemVer version. Create
|
|
113
|
+
from a string with `Version.parse(versionString)`.
|
|
114
|
+
- `Range` Representation of a version range.
|
|
115
|
+
- `Comparator` The representation of a single part of a Range,
|
|
116
|
+
which does most of the heavy lifting for parsing and testing
|
|
117
|
+
versions. This is an internal class, and should usually not be
|
|
118
|
+
used directly.
|
|
119
|
+
|
|
120
|
+
## Differences from `node-semver` (the one used by `npm`)
|
|
121
|
+
|
|
122
|
+
- The API is slightly different. Most notably, `@vltpkg/semver`
|
|
123
|
+
lacks range intersection and other methods that are not needed
|
|
124
|
+
by `vlt`. Of course, these may be added eventually if we find a
|
|
125
|
+
need for them.
|
|
126
|
+
|
|
127
|
+
- Build metadata is preserved on `Version` objects and in
|
|
128
|
+
`toString()` values.
|
|
129
|
+
|
|
130
|
+
- It's significantly faster. About 40-50% faster at parsing
|
|
131
|
+
versions, 15-20% faster at parsing ranges, and 60-70% faster at
|
|
132
|
+
testing versions against ranges, which results in the
|
|
133
|
+
`highest()` method being around 2-3 times as fast as
|
|
134
|
+
node-semver's `maxSatisfying`.
|
|
135
|
+
|
|
136
|
+
Of course, if you're not writing a package manager or some
|
|
137
|
+
other program that does millions of version comparisons in
|
|
138
|
+
the course of its operations, this is likely not relevant.)
|
|
139
|
+
|
|
140
|
+
- There's no switch for `loose` vs `strict` mode. It just always
|
|
141
|
+
works the same way.
|
|
142
|
+
|
|
143
|
+
- A leading `v` or `=` on a version is always allowed
|
|
144
|
+
- Prereleases _must_ be prefixed by a `-`.
|
|
145
|
+
- Excessively large numbers in prerelease identifiers are
|
|
146
|
+
treated as strings, rather than throwing an error.
|
|
147
|
+
|
|
148
|
+
For example, `v1.2.3` will be parsed, but `1.2.3foo` will be
|
|
149
|
+
considered invalid. `toString()` values are always the strict
|
|
150
|
+
representation.
|
|
151
|
+
|
|
152
|
+
- There is no CLI implementation, and thus, no dependencies.
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { Version } from './version.js';
|
|
2
|
+
/** all comparators are expressed in terms of these operators */
|
|
3
|
+
export type SimpleOperator = '' | '<' | '<=' | '>' | '>=';
|
|
4
|
+
/** operators that are expanded to simpler forms */
|
|
5
|
+
export type ComplexOperator = '^' | '~' | '~>';
|
|
6
|
+
/** comparator expressed as a [operator,version] tuple */
|
|
7
|
+
export type OVTuple = [SimpleOperator, Version];
|
|
8
|
+
/**
|
|
9
|
+
* The result of parsing a version value that might be either a full
|
|
10
|
+
* version like `1.2.3` or an X-Range like `1.2.x`
|
|
11
|
+
*/
|
|
12
|
+
export type ParsedXRange = ParsedXMajor | ParsedXMinor | ParsedXPatch | ParsedXVersion;
|
|
13
|
+
/**
|
|
14
|
+
* a {@link ParsedXRange} that is just a `*`
|
|
15
|
+
*/
|
|
16
|
+
export type ParsedXMajor = [];
|
|
17
|
+
/**
|
|
18
|
+
* a {@link ParsedXRange} that is just a major version
|
|
19
|
+
*/
|
|
20
|
+
export type ParsedXMinor = [number];
|
|
21
|
+
/**
|
|
22
|
+
* a {@link ParsedXRange} that is just a major and minor version
|
|
23
|
+
*/
|
|
24
|
+
export type ParsedXPatch = [number, number];
|
|
25
|
+
/**
|
|
26
|
+
* a {@link ParsedXRange} that is a full version
|
|
27
|
+
*/
|
|
28
|
+
export type ParsedXVersion = [
|
|
29
|
+
M: number,
|
|
30
|
+
m: number,
|
|
31
|
+
p: number,
|
|
32
|
+
pr?: string | undefined,
|
|
33
|
+
b?: string | undefined
|
|
34
|
+
];
|
|
35
|
+
/**
|
|
36
|
+
* Class used to parse the `||` separated portions
|
|
37
|
+
* of a range, and evaluate versions against it.
|
|
38
|
+
*
|
|
39
|
+
* This does most of the heavy lifting of range testing, and provides
|
|
40
|
+
* little affordance for improperly formatted strings. It should be
|
|
41
|
+
* considered an internal class, and usually not accessed directly.
|
|
42
|
+
*/
|
|
43
|
+
export declare class Comparator {
|
|
44
|
+
#private;
|
|
45
|
+
/**
|
|
46
|
+
* does this range include prereleases, even when they do not
|
|
47
|
+
* match the tuple in the comparator?
|
|
48
|
+
*/
|
|
49
|
+
includePrerelease: boolean;
|
|
50
|
+
/** raw string used to create this comparator */
|
|
51
|
+
raw: string;
|
|
52
|
+
/** tokens extracted from the raw string input */
|
|
53
|
+
tokens: string[];
|
|
54
|
+
/**
|
|
55
|
+
* Either the `any` comparator, the `none` comparator, or an operator
|
|
56
|
+
* and a {@link ParsedXRange}
|
|
57
|
+
*/
|
|
58
|
+
tuples: (Comparator | OVTuple)[];
|
|
59
|
+
/** true if this comparator can not match anything */
|
|
60
|
+
isNone: boolean;
|
|
61
|
+
/**
|
|
62
|
+
* true if this comparator is a `'*'` type of range.
|
|
63
|
+
*
|
|
64
|
+
* Note that it still will not match versions with a prerelease value,
|
|
65
|
+
* unless the tuple in the version matches the tuple provided to the
|
|
66
|
+
* comparator, and the comparator version also has a prerelease value,
|
|
67
|
+
* unless `includePrerelease` is set.
|
|
68
|
+
*/
|
|
69
|
+
isAny: boolean;
|
|
70
|
+
/** the canonical strict simplified parsed form of this constructor */
|
|
71
|
+
toString(): string;
|
|
72
|
+
constructor(comp: string, includePrerelease?: boolean);
|
|
73
|
+
/** return true if the version is a match for this comparator */
|
|
74
|
+
test(v: Version): boolean;
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=comparator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"comparator.d.ts","sourceRoot":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