Skip to content

Commit

Permalink
Merge e9f8bd1 into 5d0dcda
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Apr 10, 2020
2 parents 5d0dcda + e9f8bd1 commit fd2d2f7
Show file tree
Hide file tree
Showing 10 changed files with 870 additions and 804 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,10 @@
# changes log

## 7.3.0

* Add `subset(r1, r2)` method to determine if `r1` range is entirely
contained by `r2` range.

## 7.2.2

* Fix bug where `2.0.0-pre` would be included in `^1.0.0` if
Expand Down
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -79,6 +79,7 @@ const semverGtr = require('semver/ranges/gtr')
const semverLtr = require('semver/ranges/ltr')
const semverIntersects = require('semver/ranges/intersects')
const simplifyRange = require('semver/ranges/simplify')
const rangeSubset = require('semver/ranges/subset')
```
As a command-line utility:
Expand Down Expand Up @@ -455,6 +456,8 @@ strings that they parse.
programmatically, to provide the user with something a bit more
ergonomic. If the provided range is shorter in string-length than the
generated range, then that is returned.
* `subset(subRange, superRange)`: Return `true` if the `subRange` range is
entirely contained by the `superRange` range.

Note that, since ranges may be non-contiguous, a version might not be
greater than a range, less than a range, *or* satisfy a range! For
Expand Down
7 changes: 7 additions & 0 deletions classes/range.js
Expand Up @@ -92,6 +92,7 @@ class Range {
.map(comp => parseComparator(comp, this.options))
.join(' ')
.split(/\s+/)
.map(comp => replaceGTE0(comp, this.options))
// in loose mode, throw out any that are not valid comparators
.filter(this.options.loose ? comp => !!comp.match(compRe) : () => true)
.map(comp => new Comparator(comp, this.options))
Expand Down Expand Up @@ -379,6 +380,12 @@ const replaceStars = (comp, options) => {
return comp.trim().replace(re[t.STAR], '')
}

const replaceGTE0 = (comp, options) => {
debug('replaceGTE0', comp, options)
return comp.trim()
.replace(re[options.includePrerelease ? t.GTE0PRE : t.GTE0], '')
}

// This function is passed to string.replace(re[t.HYPHENRANGE])
// M, m, patch, prerelease, build
// 1.2 - 3.4.5 => >=1.2.0 <=3.4.5
Expand Down
1 change: 1 addition & 0 deletions index.js
Expand Up @@ -44,4 +44,5 @@ module.exports = {
ltr: require('./ranges/ltr'),
intersects: require('./ranges/intersects'),
simplifyRange: require('./ranges/simplify'),
subset: require('./ranges/subset'),
}
3 changes: 3 additions & 0 deletions internal/re.js
Expand Up @@ -177,3 +177,6 @@ createToken('HYPHENRANGELOOSE', `^\\s*(${src[t.XRANGEPLAINLOOSE]})` +

// Star ranges basically just allow anything at all.
createToken('STAR', '(<|>)?=?\\s*\\*')
// >=0.0.0 is like a star
createToken('GTE0', '^\\s*>=\\s*0\.0\.0\\s*$')
createToken('GTE0PRE', '^\\s*>=\\s*0\.0\.0-0\\s*$')

0 comments on commit fd2d2f7

Please sign in to comment.