deno.land / std@0.201.0 / semver / comparator_max.ts

comparator_max.ts
نووسراو ببینە
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
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.import type { Operator, SemVer } from "./types.ts";import { ANY, INVALID, MAX } from "./constants.ts";
/** * The maximum version that could match this comparator. * * If an invalid comparator is given such as <0.0.0 then * an out of range semver will be returned. * @returns the version, the MAX version or the next smallest patch version */export function comparatorMax(semver: SemVer, operator: Operator): SemVer { if (semver === ANY) { return MAX; } switch (operator) { case "!=": case "!==": case ">": case ">=": return MAX; case "": case "=": case "==": case "===": case "<=": return semver; case "<": { const patch = semver.patch - 1; const minor = patch >= 0 ? semver.minor : semver.minor - 1; const major = minor >= 0 ? semver.major : semver.major - 1; // if you try to do <0.0.0 it will Give you -∞.∞.∞ // which means no SemVer can compare successfully to it. if (major < 0) { return INVALID; } else { return { major, minor: minor >= 0 ? minor : Number.POSITIVE_INFINITY, patch: patch >= 0 ? patch : Number.POSITIVE_INFINITY, prerelease: [], build: [], }; } } }}
std

Version Info

Tagged at
2 years ago