Skip to content

Commit 692451b

Browse files
authoredMar 20, 2024··
chore: various improvements to README (#688)
1 parent ac9b357 commit 692451b

File tree

1 file changed

+44
-31
lines changed

1 file changed

+44
-31
lines changed
 

‎README.md

+44-31
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ semver.valid(semver.coerce('v2')) // '2.0.0'
2525
semver.valid(semver.coerce('42.6.7.9.3-alpha')) // '42.6.7'
2626
```
2727

28-
You can also just load the module for the function that you care about, if
28+
You can also just load the module for the function that you care about if
2929
you'd like to minimize your footprint.
3030
3131
```js
@@ -78,8 +78,8 @@ const semverOutside = require('semver/ranges/outside')
7878
const semverGtr = require('semver/ranges/gtr')
7979
const semverLtr = require('semver/ranges/ltr')
8080
const semverIntersects = require('semver/ranges/intersects')
81-
const simplifyRange = require('semver/ranges/simplify')
82-
const rangeSubset = require('semver/ranges/subset')
81+
const semverSimplifyRange = require('semver/ranges/simplify')
82+
const semverRangeSubset = require('semver/ranges/subset')
8383
```
8484
8585
As a command-line utility:
@@ -144,7 +144,7 @@ A leading `"="` or `"v"` character is stripped off and ignored.
144144
145145
## Ranges
146146
147-
A `version range` is a set of `comparators` which specify versions
147+
A `version range` is a set of `comparators` that specify versions
148148
that satisfy the range.
149149
150150
A `comparator` is composed of an `operator` and a `version`. The set
@@ -155,7 +155,7 @@ of primitive `operators` is:
155155
* `>` Greater than
156156
* `>=` Greater than or equal to
157157
* `=` Equal. If no operator is specified, then equality is assumed,
158-
so this operator is optional, but MAY be included.
158+
so this operator is optional but MAY be included.
159159
160160
For example, the comparator `>=1.2.7` would match the versions
161161
`1.2.7`, `1.2.8`, `2.5.3`, and `1.3.9`, but not the versions `1.2.6`
@@ -189,26 +189,26 @@ For example, the range `>1.2.3-alpha.3` would be allowed to match the
189189
version `1.2.3-alpha.7`, but it would *not* be satisfied by
190190
`3.4.5-alpha.9`, even though `3.4.5-alpha.9` is technically "greater
191191
than" `1.2.3-alpha.3` according to the SemVer sort rules. The version
192-
range only accepts prerelease tags on the `1.2.3` version. The
193-
version `3.4.5` *would* satisfy the range, because it does not have a
192+
range only accepts prerelease tags on the `1.2.3` version.
193+
Version `3.4.5` *would* satisfy the range because it does not have a
194194
prerelease flag, and `3.4.5` is greater than `1.2.3-alpha.7`.
195195
196-
The purpose for this behavior is twofold. First, prerelease versions
196+
The purpose of this behavior is twofold. First, prerelease versions
197197
frequently are updated very quickly, and contain many breaking changes
198198
that are (by the author's design) not yet fit for public consumption.
199-
Therefore, by default, they are excluded from range matching
199+
Therefore, by default, they are excluded from range-matching
200200
semantics.
201201

202202
Second, a user who has opted into using a prerelease version has
203-
clearly indicated the intent to use *that specific* set of
203+
indicated the intent to use *that specific* set of
204204
alpha/beta/rc versions. By including a prerelease tag in the range,
205205
the user is indicating that they are aware of the risk. However, it
206206
is still not appropriate to assume that they have opted into taking a
207207
similar risk on the *next* set of prerelease versions.
208208

209209
Note that this behavior can be suppressed (treating all prerelease
210-
versions as if they were normal versions, for the purpose of range
211-
matching) by setting the `includePrerelease` flag on the options
210+
versions as if they were normal versions, for range-matching)
211+
by setting the `includePrerelease` flag on the options
212212
object to any
213213
[functions](https://github.com/npm/node-semver#functions) that do
214214
range matching.
@@ -401,12 +401,12 @@ All methods and classes take a final `options` object argument. All
401401
options in this object are `false` by default. The options supported
402402
are:
403403

404-
- `loose` Be more forgiving about not-quite-valid semver strings.
404+
- `loose`: Be more forgiving about not-quite-valid semver strings.
405405
(Any resulting output will always be 100% strict compliant, of
406406
course.) For backwards compatibility reasons, if the `options`
407407
argument is a boolean value instead of an object, it is interpreted
408408
to be the `loose` param.
409-
- `includePrerelease` Set to suppress the [default
409+
- `includePrerelease`: Set to suppress the [default
410410
behavior](https://github.com/npm/node-semver#prerelease-tags) of
411411
excluding prerelease tagged versions from ranges unless they are
412412
explicitly opted into.
@@ -415,16 +415,20 @@ Strict-mode Comparators and Ranges will be strict about the SemVer
415415
strings that they parse.
416416

417417
* `valid(v)`: Return the parsed version, or null if it's not valid.
418-
* `inc(v, release)`: Return the version incremented by the release
419-
type (`major`, `premajor`, `minor`, `preminor`, `patch`,
418+
* `inc(v, release, options, identifier, identifierBase)`:
419+
Return the version incremented by the release
420+
type (`major`, `premajor`, `minor`, `preminor`, `patch`,
420421
`prepatch`, or `prerelease`), or null if it's not valid
421422
* `premajor` in one call will bump the version up to the next major
422423
version and down to a prerelease of that major version.
423424
`preminor`, and `prepatch` work the same way.
424-
* If called from a non-prerelease version, the `prerelease` will work the
425-
same as `prepatch`. It increments the patch version, then makes a
425+
* If called from a non-prerelease version, `prerelease` will work the
426+
same as `prepatch`. It increments the patch version and then makes a
426427
prerelease. If the input version is already a prerelease it simply
427428
increments it.
429+
* `identifier` can be used to prefix `premajor`, `preminor`,
430+
`prepatch`, or `prerelease` version increments. `identifierBase`
431+
is the base to be used for the `prerelease` identifier.
428432
* `prerelease(v)`: Returns an array of prerelease components, or null
429433
if none exist. Example: `prerelease('1.2.3-alpha.1') -> ['alpha', 1]`
430434
* `major(v)`: Return the major version number.
@@ -442,7 +446,7 @@ strings that they parse.
442446
* `lt(v1, v2)`: `v1 < v2`
443447
* `lte(v1, v2)`: `v1 <= v2`
444448
* `eq(v1, v2)`: `v1 == v2` This is true if they're logically equivalent,
445-
even if they're not the exact same string. You already know how to
449+
even if they're not the same string. You already know how to
446450
compare strings.
447451
* `neq(v1, v2)`: `v1 != v2` The opposite of `eq`.
448452
* `cmp(v1, comparator, v2)`: Pass in a comparison string, and it'll call
@@ -451,15 +455,22 @@ strings that they parse.
451455
invalid comparison string is provided.
452456
* `compare(v1, v2)`: Return `0` if `v1 == v2`, or `1` if `v1` is greater, or `-1` if
453457
`v2` is greater. Sorts in ascending order if passed to `Array.sort()`.
454-
* `rcompare(v1, v2)`: The reverse of compare. Sorts an array of versions
458+
* `rcompare(v1, v2)`: The reverse of `compare`. Sorts an array of versions
455459
in descending order when passed to `Array.sort()`.
456460
* `compareBuild(v1, v2)`: The same as `compare` but considers `build` when two versions
457461
are equal. Sorts in ascending order if passed to `Array.sort()`.
458-
`v2` is greater. Sorts in ascending order if passed to `Array.sort()`.
459-
* `diff(v1, v2)`: Returns difference between two versions by the release type
462+
* `compareLoose(v1, v2)`: Short for ``compare(v1, v2, { loose: true })`.
463+
* `diff(v1, v2)`: Returns the difference between two versions by the release type
460464
(`major`, `premajor`, `minor`, `preminor`, `patch`, `prepatch`, or `prerelease`),
461465
or null if the versions are the same.
462466
467+
### Sorting
468+
469+
* `sort(versions)`: Returns a sorted array of versions based on the `compareBuild`
470+
function.
471+
* `rsort(versions)`: The reverse of `sort`. Returns an array of versions based on
472+
the `compareBuild` function in descending order.
473+
463474
### Comparators
464475
465476
* `intersects(comparator)`: Return true if the comparators intersect
@@ -473,19 +484,19 @@ strings that they parse.
473484
that satisfies the range, or `null` if none of them do.
474485
* `minSatisfying(versions, range)`: Return the lowest version in the list
475486
that satisfies the range, or `null` if none of them do.
476-
* `minVersion(range)`: Return the lowest version that can possibly match
487+
* `minVersion(range)`: Return the lowest version that can match
477488
the given range.
478-
* `gtr(version, range)`: Return `true` if version is greater than all the
489+
* `gtr(version, range)`: Return `true` if the version is greater than all the
479490
versions possible in the range.
480-
* `ltr(version, range)`: Return `true` if version is less than all the
491+
* `ltr(version, range)`: Return `true` if the version is less than all the
481492
versions possible in the range.
482493
* `outside(version, range, hilo)`: Return true if the version is outside
483494
the bounds of the range in either the high or low direction. The
484495
`hilo` argument must be either the string `'>'` or `'<'`. (This is
485496
the function called by `gtr` and `ltr`.)
486-
* `intersects(range)`: Return true if any of the ranges comparators intersect
497+
* `intersects(range)`: Return true if any of the range comparators intersect.
487498
* `simplifyRange(versions, range)`: Return a "simplified" range that
488-
matches the same items in `versions` list as the range specified. Note
499+
matches the same items in the `versions` list as the range specified. Note
489500
that it does *not* guarantee that it would match the same versions in all
490501
cases, only for the set of versions provided. This is useful when
491502
generating ranges by joining together multiple versions with `||`
@@ -498,7 +509,7 @@ strings that they parse.
498509
Note that, since ranges may be non-contiguous, a version might not be
499510
greater than a range, less than a range, *or* satisfy a range! For
500511
example, the range `1.2 <1.2.9 || >2.0.0` would have a hole from `1.2.9`
501-
until `2.0.0`, so the version `1.2.10` would not be greater than the
512+
until `2.0.0`, so version `1.2.10` would not be greater than the
502513
range (because `2.0.1` satisfies, which is higher), nor less than the
503514
range (since `1.2.8` satisfies, which is lower), and it also does not
504515
satisfy the range.
@@ -511,13 +522,13 @@ range, use the `satisfies(version, range)` function.
511522
* `coerce(version, options)`: Coerces a string to semver if possible
512523

513524
This aims to provide a very forgiving translation of a non-semver string to
514-
semver. It looks for the first digit in a string, and consumes all
525+
semver. It looks for the first digit in a string and consumes all
515526
remaining characters which satisfy at least a partial semver (e.g., `1`,
516527
`1.2`, `1.2.3`) up to the max permitted length (256 characters). Longer
517528
versions are simply truncated (`4.6.3.9.2-alpha2` becomes `4.6.3`). All
518529
surrounding text is simply ignored (`v3.4 replaces v3.3.1` becomes
519530
`3.4.0`). Only text which lacks digits will fail coercion (`version one`
520-
is not valid). The maximum length for any semver component considered for
531+
is not valid). The maximum length for any semver component considered for
521532
coercion is 16 characters; longer components will be ignored
522533
(`10000000000000000.4.7.4` becomes `4.7.4`). The maximum value for any
523534
semver component is `Number.MAX_SAFE_INTEGER || (2**53 - 1)`; higher value
@@ -593,7 +604,7 @@ eg), and then pull the module name into the documentation for that specific
593604
thing.
594605
-->
595606
596-
You may pull in just the part of this semver utility that you need, if you
607+
You may pull in just the part of this semver utility that you need if you
597608
are sensitive to packing and tree-shaking concerns. The main
598609
`require('semver')` export uses getter functions to lazily load the parts
599610
of the API that are used.
@@ -636,6 +647,8 @@ The following modules are available:
636647
* `require('semver/ranges/min-satisfying')`
637648
* `require('semver/ranges/min-version')`
638649
* `require('semver/ranges/outside')`
650+
* `require('semver/ranges/simplify')`
651+
* `require('semver/ranges/subset')`
639652
* `require('semver/ranges/to-comparators')`
640653
* `require('semver/ranges/valid')`
641654

0 commit comments

Comments
 (0)
Please sign in to comment.