keep-a-changelog
Version:
Node package to parse and generate changelogs following the [keepachangelog](https://keepachangelog.com/) format.
31 lines (30 loc) • 1.04 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.formatRange = formatRange;
// Copyright 2018-2025 the Deno authors. MIT license.
// This module is browser compatible.
const format_js_1 = require("./format.js");
const _shared_js_1 = require("./_shared.js");
function formatComparator(comparator) {
const { operator } = comparator;
return `${operator === undefined ? "" : operator}${(0, _shared_js_1.isWildcardComparator)(comparator) ? "*" : (0, format_js_1.format)(comparator)}`;
}
/**
* Formats the SemVerrange into a string.
*
* @example Usage
* ```ts
* import { formatRange, parseRange } from "@std/semver";
* import { assertEquals } from "@std/assert";
*
* const range = parseRange(">=1.2.3 <1.2.4");
* assertEquals(formatRange(range), ">=1.2.3 <1.2.4");
* ```
*
* @param range The range to format
* @returns A string representation of the SemVer range
*/
function formatRange(range) {
return range.map((c) => c.map((c) => formatComparator(c)).join(" "))
.join("||");
}