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