@vltpkg/semver 0.0.0-3 → 0.0.0-5
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 +65 -68
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -2,12 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
# @vltpkg/semver
|
|
4
4
|
|
|
5
|
-
A library for parsing, validating & comparing Semantic Versions used
|
|
5
|
+
A library for parsing, validating & comparing Semantic Versions used
|
|
6
|
+
by `vlt`.
|
|
6
7
|
|
|
7
|
-
**[Usage](#usage)**
|
|
8
|
-
·
|
|
9
|
-
**[Functions](#functions)**
|
|
10
|
-
·
|
|
8
|
+
**[Usage](#usage)** · **[Functions](#functions)** ·
|
|
11
9
|
**[Differences from node-semver](#differences)**
|
|
12
10
|
|
|
13
11
|
## Usage
|
|
@@ -46,26 +44,26 @@ import {
|
|
|
46
44
|
- `parse(v)`: Attempt to parse a string as a semantic version,
|
|
47
45
|
returning either a `Version` object or `undefined`.
|
|
48
46
|
- `valid(v)`: Return true if the version is valid
|
|
49
|
-
- `increment(v, type, [identifier])` Increment the specified part
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
- `increment(v, type, [identifier])` Increment the specified part of
|
|
48
|
+
the version, and return the resulting object. If a Version object is
|
|
49
|
+
provided, it will be modified in-place.
|
|
52
50
|
- `major(v)`: Return the major version number.
|
|
53
51
|
- `minor(v)`: Return the minor version number.
|
|
54
52
|
- `patch(v)`: Return the patch version number.
|
|
55
53
|
- `prerelease(v)`: Returns an array of prerelease components, or
|
|
56
|
-
`undefined` if none exist. Example:
|
|
57
|
-
['alpha', 1]`
|
|
58
|
-
- `build(v)`: Returns an array of build components, or
|
|
59
|
-
|
|
60
|
-
['linux', '33']`
|
|
54
|
+
`undefined` if none exist. Example:
|
|
55
|
+
`prerelease('1.2.3-alpha.1') -> ['alpha', 1]`
|
|
56
|
+
- `build(v)`: Returns an array of build components, or `undefined` if
|
|
57
|
+
none exist. Example:
|
|
58
|
+
`prerelease('1.2.3+linux.33') -> ['linux', '33']`
|
|
61
59
|
- `stable(v)`: Returns an array of releases that are considered
|
|
62
60
|
"stable" (ie. no prereleases), or an empty array if non exist.
|
|
63
61
|
|
|
64
62
|
### Comparison
|
|
65
63
|
|
|
66
|
-
These functions all compare version strings or objects
|
|
67
|
-
|
|
68
|
-
|
|
64
|
+
These functions all compare version strings or objects by their SemVer
|
|
65
|
+
precedence. (Note that build metadata is not considered, as per the
|
|
66
|
+
SemVer 2.0 specification.)
|
|
69
67
|
|
|
70
68
|
Unless otherwise noted, they throw an error on invalid versions.
|
|
71
69
|
|
|
@@ -73,83 +71,82 @@ Unless otherwise noted, they throw an error on invalid versions.
|
|
|
73
71
|
- `gte(v1, v2)`: `v1 >= v2`
|
|
74
72
|
- `lt(v1, v2)`: `v1 < v2`
|
|
75
73
|
- `lte(v1, v2)`: `v1 <= v2`
|
|
76
|
-
- `eq(v1, v2)`: `v1 == v2` This is true even if they're not the
|
|
77
|
-
|
|
74
|
+
- `eq(v1, v2)`: `v1 == v2` This is true even if they're not the exact
|
|
75
|
+
same string. You already know how to compare strings.
|
|
78
76
|
- `neq(v1, v2)`: `v1 != v2` The opposite of `eq`.
|
|
79
|
-
- `compare(v1, v2)`: Return `0` if `v1 == v2`, or `1` if `v1` is
|
|
80
|
-
`v2` is greater. Sorts in ascending order if
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
throwing an
|
|
77
|
+
- `compare(v1, v2)`: Return `0` if `v1 == v2`, or `1` if `v1` is
|
|
78
|
+
greater, or `-1` if `v2` is greater. Sorts in ascending order if
|
|
79
|
+
passed to `Array.sort()`.
|
|
80
|
+
- `sortMethod(v1, v2)`: The same as `compare`, except that invalid
|
|
81
|
+
versions are sorted to the end of the list rather than throwing an
|
|
82
|
+
error.
|
|
84
83
|
- `rcompare(v1, v2)`: Inverse of `compare`
|
|
85
|
-
- `rsortMethod(v1, v2)`: Inverse of `sortMethod`. (Invalid
|
|
86
|
-
|
|
84
|
+
- `rsortMethod(v1, v2)`: Inverse of `sortMethod`. (Invalid versions
|
|
85
|
+
are still sorted to the end of the list.)
|
|
87
86
|
|
|
88
87
|
### Ranges
|
|
89
88
|
|
|
90
|
-
- `validRange(range)`: Return the valid range or null if it's not
|
|
91
|
-
|
|
92
|
-
|
|
89
|
+
- `validRange(range)`: Return the valid range or null if it's not
|
|
90
|
+
valid
|
|
91
|
+
- `satisfies(version, range)`: Return true if the version satisfies
|
|
92
|
+
the range.
|
|
93
93
|
- `highest(versions, range)`: Return the highest version in the list
|
|
94
94
|
that satisfies the range, or `null` if none of them do.
|
|
95
|
-
- `sortedHighest(versions, range)`: Optimized form of `highest`,
|
|
96
|
-
|
|
97
|
-
precedence order. If the list is not sorted already, may return
|
|
98
|
-
|
|
99
|
-
- `rsortedHighest(versions, range)`: Optimized form of `highest`,
|
|
100
|
-
|
|
101
|
-
precedence order. If the list is not sorted already, may return
|
|
102
|
-
|
|
95
|
+
- `sortedHighest(versions, range)`: Optimized form of `highest`, if
|
|
96
|
+
the version list is known to be sorted in ascending SemVer
|
|
97
|
+
precedence order. If the list is not sorted already, may return an
|
|
98
|
+
incorrect result.
|
|
99
|
+
- `rsortedHighest(versions, range)`: Optimized form of `highest`, if
|
|
100
|
+
the version list is known to be sorted in descending SemVer
|
|
101
|
+
precedence order. If the list is not sorted already, may return an
|
|
102
|
+
incorrect result.
|
|
103
103
|
- `lowest(versions, range)`: Return the lowest version in the list
|
|
104
104
|
that satisfies the range, or `null` if none of them do.
|
|
105
|
-
- `sortedLowest(versions, range)`: Optimized form of `lowest`,
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
- `rsortedLowest(versions, range)`: Optimized form of `lowest`,
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
105
|
+
- `sortedLowest(versions, range)`: Optimized form of `lowest`, if the
|
|
106
|
+
version list is known to be sorted in ascending SemVer precedence
|
|
107
|
+
order. If the list is not sorted already, may return an incorrect
|
|
108
|
+
result.
|
|
109
|
+
- `rsortedLowest(versions, range)`: Optimized form of `lowest`, if the
|
|
110
|
+
version list is known to be sorted in descending SemVer precedence
|
|
111
|
+
order. If the list is not sorted already, may return an incorrect
|
|
112
|
+
result.
|
|
113
113
|
|
|
114
114
|
### Classes
|
|
115
115
|
|
|
116
|
-
- `Version` Object representation of a SemVer version. Create
|
|
117
|
-
|
|
116
|
+
- `Version` Object representation of a SemVer version. Create from a
|
|
117
|
+
string with `Version.parse(versionString)`.
|
|
118
118
|
- `Range` Representation of a version range.
|
|
119
|
-
- `Comparator` The representation of a single part of a Range,
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
used directly.
|
|
119
|
+
- `Comparator` The representation of a single part of a Range, which
|
|
120
|
+
does most of the heavy lifting for parsing and testing versions.
|
|
121
|
+
This is an internal class, and should usually not be used directly.
|
|
123
122
|
|
|
124
123
|
## Differences
|
|
125
124
|
|
|
126
125
|
### Differences from `node-semver` (the one used by `npm`)
|
|
127
126
|
|
|
128
|
-
- The API is slightly different. Most notably, `@vltpkg/semver`
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
need for them.
|
|
127
|
+
- The API is slightly different. Most notably, `@vltpkg/semver` lacks
|
|
128
|
+
range intersection and other methods that are not needed by `vlt`.
|
|
129
|
+
Of course, these may be added eventually if we find a need for them.
|
|
132
130
|
|
|
133
|
-
- Build metadata is preserved on `Version` objects and in
|
|
134
|
-
|
|
131
|
+
- Build metadata is preserved on `Version` objects and in `toString()`
|
|
132
|
+
values.
|
|
135
133
|
|
|
136
|
-
- It's significantly faster. About 40-50% faster at parsing
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
node-semver's `maxSatisfying`.
|
|
134
|
+
- It's significantly faster. About 40-50% faster at parsing versions,
|
|
135
|
+
15-20% faster at parsing ranges, and 60-70% faster at testing
|
|
136
|
+
versions against ranges, which results in the `highest()` method
|
|
137
|
+
being around 2-3 times as fast as node-semver's `maxSatisfying`.
|
|
141
138
|
|
|
142
|
-
Of course, if you're not writing a package manager or some
|
|
143
|
-
|
|
144
|
-
|
|
139
|
+
Of course, if you're not writing a package manager or some other
|
|
140
|
+
program that does millions of version comparisons in the course of
|
|
141
|
+
its operations, this is likely not relevant.)
|
|
145
142
|
|
|
146
|
-
- There's no switch for `loose` vs `strict` mode. It just always
|
|
147
|
-
|
|
143
|
+
- There's no switch for `loose` vs `strict` mode. It just always works
|
|
144
|
+
the same way.
|
|
148
145
|
|
|
149
146
|
- A leading `v` or `=` on a version is always allowed
|
|
150
147
|
- Prereleases _must_ be prefixed by a `-`.
|
|
151
|
-
- Excessively large numbers in prerelease identifiers are
|
|
152
|
-
|
|
148
|
+
- Excessively large numbers in prerelease identifiers are treated as
|
|
149
|
+
strings, rather than throwing an error.
|
|
153
150
|
|
|
154
151
|
For example, `v1.2.3` will be parsed, but `1.2.3foo` will be
|
|
155
152
|
considered invalid. `toString()` values are always the strict
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vltpkg/semver",
|
|
3
3
|
"description": "The semantic version parser used by vlt",
|
|
4
|
-
"version": "0.0.0-
|
|
4
|
+
"version": "0.0.0-5",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/vltpkg/vltpkg.git",
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@vltpkg/
|
|
23
|
-
"@vltpkg/
|
|
22
|
+
"@vltpkg/fast-split": "0.0.0-5",
|
|
23
|
+
"@vltpkg/error-cause": "0.0.0-5"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@eslint/js": "^9.20.0",
|