mirror of
https://github.com/denoland/std.git
synced 2024-11-22 04:59:05 +00:00
7af9f89053
* docs(semver): minor documentation cleanups * fix
30 lines
912 B
TypeScript
30 lines
912 B
TypeScript
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
|
// This module is browser compatible.
|
|
import { format } from "./format.ts";
|
|
import type { Comparator, Range } from "./types.ts";
|
|
|
|
function formatComparator(comparator: Comparator): string {
|
|
const { operator } = comparator;
|
|
return `${operator === undefined ? "" : operator}${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
|
|
*/
|
|
export function formatRange(range: Range): string {
|
|
return range.map((c) => c.map((c) => formatComparator(c)).join(" "))
|
|
.join("||");
|
|
}
|