Skip to content

Commit

Permalink
deprecation(semver): rename isSemVerComparator() (#3957)
Browse files Browse the repository at this point in the history
  • Loading branch information
timreichen authored Dec 18, 2023
1 parent 1f2a07a commit 4e75a00
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 20 deletions.
30 changes: 30 additions & 0 deletions semver/is_comparator.ts
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)
);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
import { assert } from "../assert/mod.ts";
import { INVALID, MIN } from "./constants.ts";
import { isSemVerComparator } from "./is_semver_comparator.ts";
import { isComparator } from "./is_comparator.ts";

Deno.test({
name: "valid_comparator",
Expand All @@ -25,7 +25,7 @@ Deno.test({
await t.step(
`valid_comparator_${(i++).toString().padStart(2, "0")}`,
() => {
const actual = isSemVerComparator(c);
const actual = isComparator(c);
assert(actual);
},
);
Expand Down
21 changes: 3 additions & 18 deletions semver/is_semver_comparator.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
import { isSemVer } from "./is_semver.ts";
import { isValidOperator } from "./_shared.ts";
import type { SemVerComparator } from "./types.ts";
import { ALL, NONE } from "./constants.ts";
import { isComparator } from "./is_comparator.ts";

/**
* Does a deep check on the value to see if it is a valid SemVerComparator object.
Expand All @@ -13,18 +10,6 @@ import { ALL, NONE } from "./constants.ts";
* Adds a type assertion if true.
* @param value The value to check if its a SemVerComparator
* @returns True if the object is a SemVerComparator otherwise false
* @deprecated (will be removed in 0.212.0) Use {@linkcode isComparator} instead.
*/
export function isSemVerComparator(value: unknown): value is SemVerComparator {
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 SemVerComparator;
return (
isValidOperator(operator) &&
isSemVer(semver) &&
isSemVer(min) &&
isSemVer(max)
);
}
export const isSemVerComparator = isComparator;
9 changes: 9 additions & 0 deletions semver/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ export type FormatStyle =
* The shape of a valid semantic version comparator
* @example >=0.0.0
*/
export interface Comparator {
operator: Operator;
semver: SemVer;
min: SemVer;
max: SemVer;
}
/**
* @deprecated (will be removed in 0.212.0) Use {@linkcode Comparator} instead.
*/
export interface SemVerComparator {
operator: Operator;
semver: SemVer;
Expand Down

0 comments on commit 4e75a00

Please sign in to comment.