keep-a-changelog
Version:
Node package to parse and generate changelogs following the [keepachangelog](https://keepachangelog.com/) format.
36 lines (35 loc) • 1.01 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.format = format;
function formatNumber(value) {
return value.toFixed(0);
}
/**
* Format a SemVer object into a string.
*
* @example Usage
* ```ts
* import { format } from "@std/semver/format";
* import { assertEquals } from "@std/assert";
*
* const semver = {
* major: 1,
* minor: 2,
* patch: 3,
* };
* assertEquals(format(semver), "1.2.3");
* ```
*
* @param version The SemVer to format
* @returns The string representation of a semantic version.
*/
function format(version) {
const major = formatNumber(version.major);
const minor = formatNumber(version.minor);
const patch = formatNumber(version.patch);
const pre = version.prerelease?.join(".") ?? "";
const build = version.build?.join(".") ?? "";
const primary = `${major}.${minor}.${patch}`;
const release = [primary, pre].filter((v) => v).join("-");
return [release, build].filter((v) => v).join("+");
}