Skip to content

Commit

Permalink
feat(numeric): improve acceptable type to expand bigint
Browse files Browse the repository at this point in the history
  • Loading branch information
TomokiMiyauci committed May 28, 2023
1 parent 893b1eb commit 62b0245
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 21 deletions.
15 changes: 0 additions & 15 deletions _tools/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,6 @@ export const makeOptions = (version: string): BuildOptions => ({
version: "1.3.1",
subPath: "is_nullable.js",
},
"https://deno.land/x/isx@1.3.1/number/is_non_positive_number.ts": {
name: "@miyauci/isx",
version: "1.3.1",
subPath: "number/is_non_positive_number.js",
},
"https://deno.land/x/isx@1.3.1/number/is_negative_number.ts": {
name: "@miyauci/isx",
version: "1.3.1",
subPath: "number/is_negative_number.js",
},
"https://deno.land/x/isx@1.3.1/number/is_non_negative_number.ts": {
name: "@miyauci/isx",
version: "1.3.1",
subPath: "number/is_non_negative_number.js",
},
"https://deno.land/x/isx@1.3.1/date/is_valid_date.ts": {
name: "@miyauci/isx",
version: "1.3.1",
Expand Down
20 changes: 17 additions & 3 deletions deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ export { isSingle } from "https://deno.land/x/isx@1.3.1/iterable/is_single.ts";
export { isNullable } from "https://deno.land/x/isx@1.3.1/is_nullable.ts";
export { isString } from "https://deno.land/x/isx@1.3.1/is_string.ts";
export { isBigint } from "https://deno.land/x/isx@1.3.1/is_bigint.ts";
export { isNegativeNumber } from "https://deno.land/x/isx@1.3.1/number/is_negative_number.ts";
export { isNonPositiveNumber } from "https://deno.land/x/isx@1.3.1/number/is_non_positive_number.ts";
export { isNonNegativeNumber } from "https://deno.land/x/isx@1.3.1/number/is_non_negative_number.ts";
export { isValidDate } from "https://deno.land/x/isx@1.3.1/date/is_valid_date.ts";
export { filterKeys } from "https://deno.land/std@0.187.0/collections/filter_keys.ts";
export { maxBy } from "https://deno.land/std@0.187.0/collections/max_by.ts";
Expand All @@ -22,6 +19,23 @@ export function isPositiveNumber(input: number | bigint): boolean {
return input > 0;
}

/** Whether the input is negative number or not.
* @param input - Any numeric.
*/
export function isNegativeNumber(input: number | bigint): boolean {
return input < 0;
}

/** Whether the input is non-positive number or not. */
export function isNonPositiveNumber(input: number | bigint): boolean {
return isNegativeNumber(input) || !input;
}

/** Whether the input is non-negative number or not. */
export function isNonNegativeNumber(input: number | bigint): boolean {
return isPositiveNumber(input) || !input;
}

/** Constructor type. */
// deno-lint-ignore no-explicit-any
export type Constructor = abstract new (...args: any) => any;
Expand Down
2 changes: 1 addition & 1 deletion validators/numeric/negative_number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { ScalarValidator } from "../../utils.ts";
import { isNegativeNumber, ToPredicate } from "../../deps.ts";

export class NegativeNumberValidator extends ScalarValidator<number> {
export class NegativeNumberValidator extends ScalarValidator<number | bigint> {
is = isNegativeNumber as ToPredicate<typeof isNegativeNumber>;

override toString() {
Expand Down
3 changes: 2 additions & 1 deletion validators/numeric/non_negative_number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import { ScalarValidator } from "../../utils.ts";
import { isNonNegativeNumber, ToPredicate } from "../../deps.ts";

export class NonNegativeNumberValidator extends ScalarValidator<number> {
export class NonNegativeNumberValidator
extends ScalarValidator<number | bigint> {
is = isNonNegativeNumber as ToPredicate<typeof isNonNegativeNumber>;

override toString() {
Expand Down
3 changes: 2 additions & 1 deletion validators/numeric/non_positive_number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import { ScalarValidator } from "../../utils.ts";
import { isNonPositiveNumber, ToPredicate } from "../../deps.ts";

export class NonPositiveNumberValidator extends ScalarValidator<number> {
export class NonPositiveNumberValidator
extends ScalarValidator<number | bigint> {
is = isNonPositiveNumber as ToPredicate<typeof isNonPositiveNumber>;

override toString() {
Expand Down

0 comments on commit 62b0245

Please sign in to comment.