Skip to content

Commit

Permalink
add minSatisfying
Browse files Browse the repository at this point in the history
  • Loading branch information
wraithgar committed Jul 13, 2016
1 parent 4bdb8f4 commit 984491a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ strings that they parse.
range.
* `maxSatisfying(versions, range)`: Return the highest version in the list
that satisfies the range, or `null` if none of them do.
* `minSatisfying(versions, range)`: Return the lowest version in the list
that satisfies the range, or `null` if none of them do.
* `gtr(version, range)`: Return `true` if version is greater than all the
versions possible in the range.
* `ltr(version, range)`: Return `true` if version is less than all the
Expand Down
9 changes: 9 additions & 0 deletions semver.js
Original file line number Diff line number Diff line change
Expand Up @@ -1094,6 +1094,15 @@ function maxSatisfying(versions, range, loose) {
})[0] || null;
}

exports.minSatisfying = minSatisfying;
function minSatisfying(versions, range, loose) {
return versions.filter(function(version) {
return satisfies(version, range, loose);
}).sort(function(a, b) {
return compare(a, b, loose);
})[0] || null;
}

exports.validRange = validRange;
function validRange(range, loose) {
try {
Expand Down
16 changes: 16 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -696,3 +696,19 @@ test('\nmax satisfying', function(t) {
});
t.end();
});

test('\nmin satisfying', function(t) {
[[['1.2.3', '1.2.4'], '1.2', '1.2.3'],
[['1.2.4', '1.2.3'], '1.2', '1.2.3'],
[['1.2.3', '1.2.4', '1.2.5', '1.2.6'], '~1.2.3', '1.2.3'],
[['1.1.0', '1.2.0', '1.2.1', '1.3.0', '2.0.0b1', '2.0.0b2', '2.0.0b3', '2.0.0', '2.1.0'], '~2.0.0', '2.0.0', true]
].forEach(function(v) {
var versions = v[0];
var range = v[1];
var expect = v[2];
var loose = v[3];
var actual = semver.minSatisfying(versions, range, loose);
t.equal(actual, expect);
});
t.end();
});

0 comments on commit 984491a

Please sign in to comment.