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

less_than_range.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
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.// This module is browser compatible.
import type { Comparator, Range, SemVer } from "./types.ts";import { testComparatorSet } from "./_test_comparator_set.ts";import { isWildcardComparator } from "./_shared.ts";import { compare } from "./compare.ts";
/** Check if the semver is less than the range. */export function lessThanRange(semver: SemVer, range: Range): boolean { return range.every((comparatorSet) => lessThanComparatorSet(semver, comparatorSet) );}
function lessThanComparatorSet(semver: SemVer, comparatorSet: Comparator[]) { // If the comparator set contains wildcard, then the semver is not greater than the range. if (comparatorSet.some(isWildcardComparator)) return false; // If the semver satisfies the comparator set, then it's not less than the range. if (testComparatorSet(semver, comparatorSet)) return false; // If the semver is greater than any of the comparator set, then it's not less than the range. if ( comparatorSet.some((comparator) => greaterThanComparator(semver, comparator) ) ) return false; return true;}
function greaterThanComparator( semver: SemVer, comparator: Comparator,): boolean { const cmp = compare(semver, comparator); switch (comparator.operator) { case "=": case undefined: return cmp > 0; case "!=": return false; case ">": return false; case "<": return cmp >= 0; case ">=": return false; case "<=": return cmp > 0; }}
std

Version Info

Tagged at
6 months ago