-
Notifications
You must be signed in to change notification settings - Fork 624
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
deprecation(semver): rename
isSemVerComparator()
(#3957)
- Loading branch information
1 parent
1f2a07a
commit 4e75a00
Showing
4 changed files
with
44 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. | ||
import { isSemVer } from "./is_semver.ts"; | ||
import { isValidOperator } from "./_shared.ts"; | ||
import type { Comparator } from "./types.ts"; | ||
import { ALL, NONE } from "./constants.ts"; | ||
|
||
/** | ||
* Does a deep check on the value to see if it is a valid Comparator object. | ||
* | ||
* Objects with extra fields are still considered valid if they have at | ||
* least the correct fields. | ||
* | ||
* Adds a type assertion if true. | ||
* @param value The value to check if its a Comparator | ||
* @returns True if the object is a Comparator otherwise false | ||
*/ | ||
export function isComparator(value: unknown): value is Comparator { | ||
if (value === null || value === undefined) return false; | ||
if (value === NONE) return true; | ||
if (value === ALL) return true; | ||
if (Array.isArray(value)) return false; | ||
if (typeof value !== "object") return false; | ||
const { operator, semver, min, max } = value as Comparator; | ||
return ( | ||
isValidOperator(operator) && | ||
isSemVer(semver) && | ||
isSemVer(min) && | ||
isSemVer(max) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters