deno.land / std@0.224.0 / semver / range_min.ts

range_min.ts
View Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.// This module is browser compatible.import { INVALID, MAX, MIN } from "./constants.ts";import { satisfies } from "./satisfies.ts";import type { Comparator, Range, SemVer } from "./types.ts";import { lessThan } from "./less_than.ts";import { greaterThan } from "./greater_than.ts";import { increment } from "./increment.ts";import { isWildcardComparator } from "./_shared.ts";
function comparatorMin(comparator: Comparator): SemVer { const semver = comparator; if (isWildcardComparator(semver)) return MIN; switch (comparator.operator) { case ">": return semver.prerelease && semver.prerelease.length > 0 ? increment(semver, "pre") : increment(semver, "patch"); case "!=": case "<=": case "<": // The min(<0.0.0) is MAX return greaterThan(semver, MIN) ? MIN : MAX; case ">=": case undefined: case "=": return { major: semver.major, minor: semver.minor, patch: semver.patch, prerelease: semver.prerelease, build: semver.build, }; }}
/** * @deprecated This will be removed in 1.0.0. Use {@linkcode greaterThanRange} or * {@linkcode lessThanRange} for comparing ranges and semvers. The minimum * version of a range is often not well defined, and therefore this API * shouldn't be used. See * {@link https://github.com/denoland/deno_std/issues/4365} for details. * * The minimum valid SemVer for a given range or INVALID * @param range The range to calculate the min for * @returns A valid SemVer or INVALID */export function rangeMin(range: Range): SemVer { let min; for (const comparators of range) { for (const comparator of comparators) { const candidate = comparatorMin(comparator); if (!satisfies(candidate, range)) continue; min = (min && lessThan(min, candidate)) ? min : candidate; } } return min ?? INVALID;}
std

Version Info

Tagged at
6 months ago