keep-a-changelog
Version:
Node package to parse and generate changelogs following the [keepachangelog](https://keepachangelog.com/) format.
34 lines (33 loc) • 1.13 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.minSatisfying = minSatisfying;
const satisfies_js_1 = require("./satisfies.js");
const less_than_js_1 = require("./less_than.js");
/**
* Returns the lowest SemVer in the list that satisfies the range, or `undefined` if
* none of them do.
*
* @example Usage
* ```ts
* import { parse, parseRange, minSatisfying } from "@std/semver";
* import { assertEquals } from "@std/assert";
*
* const versions = ["0.2.0", "1.2.3", "1.3.0", "2.0.0", "2.1.0"].map(parse);
* const range = parseRange(">=1.0.0 <2.0.0");
*
* assertEquals(minSatisfying(versions, range), parse("1.2.3"));
* ```
*
* @param versions The versions to check.
* @param range The range of possible versions to compare to.
* @returns The lowest version in versions that satisfies the range.
*/
function minSatisfying(versions, range) {
let min;
for (const version of versions) {
if (!(0, satisfies_js_1.satisfies)(version, range))
continue;
min = min && (0, less_than_js_1.lessThan)(min, version) ? min : version;
}
return min;
}