diff --git a/validators/number.test.ts b/validators/number.test.ts index e5ba370..2ed6de1 100644 --- a/validators/number.test.ts +++ b/validators/number.test.ts @@ -7,6 +7,8 @@ import { Deno.test("isNumber (match)", async () => { const values = [ + undefined, + null, 0, 1, 2e64, @@ -21,8 +23,6 @@ Deno.test("isNumber (match)", async () => { Deno.test("isNumber (no match)", async () => { const values = [ - undefined, - null, NaN, "0", true, @@ -39,6 +39,8 @@ Deno.test("isNumber (no match)", async () => { Deno.test("isInteger (match)", async () => { const values = [ + undefined, + null, 0, 1, 2e64, @@ -51,8 +53,6 @@ Deno.test("isInteger (match)", async () => { Deno.test("isInteger (no match)", async () => { const values = [ - undefined, - null, NaN, "0", true, diff --git a/validators/number.ts b/validators/number.ts index 9fd57e8..c53acaf 100644 --- a/validators/number.ts +++ b/validators/number.ts @@ -3,6 +3,7 @@ import { Validator, Args } from "../mod.ts"; export const isNumber: Validator = { type: "isNumber", check: (value: any) => { + if (value === null || value === undefined) return; if (!Number.isFinite(value)) { return {}; } @@ -15,6 +16,7 @@ export const isNumber: Validator = { export const isInteger: Validator = { type: "isInteger", check: (value: any) => { + if (value === null || value === undefined) return; if (!Number.isInteger(value)) { return {}; } diff --git a/validators/string.test.ts b/validators/string.test.ts index 0776460..23ba2a5 100644 --- a/validators/string.test.ts +++ b/validators/string.test.ts @@ -7,6 +7,8 @@ import { Deno.test("isString (match)", async () => { const values = [ + undefined, + null, "", "foo", new String(), @@ -19,8 +21,6 @@ Deno.test("isString (match)", async () => { Deno.test("isString (no match)", async () => { const values = [ - undefined, - null, 0, 1, true, diff --git a/validators/string.ts b/validators/string.ts index 89cedbe..3d84c3d 100644 --- a/validators/string.ts +++ b/validators/string.ts @@ -3,6 +3,7 @@ import { Validator, Args } from "../mod.ts"; export const isString: Validator = { type: "isString", check: (value: any) => { + if (value === null || value === undefined) return; if (typeof value !== "string" && !(value instanceof String)) { return {}; }