allowed null and undefined
This commit is contained in:
@@ -7,6 +7,8 @@ import {
|
|||||||
|
|
||||||
Deno.test("isNumber (match)", async () => {
|
Deno.test("isNumber (match)", async () => {
|
||||||
const values = [
|
const values = [
|
||||||
|
undefined,
|
||||||
|
null,
|
||||||
0,
|
0,
|
||||||
1,
|
1,
|
||||||
2e64,
|
2e64,
|
||||||
@@ -21,8 +23,6 @@ Deno.test("isNumber (match)", async () => {
|
|||||||
|
|
||||||
Deno.test("isNumber (no match)", async () => {
|
Deno.test("isNumber (no match)", async () => {
|
||||||
const values = [
|
const values = [
|
||||||
undefined,
|
|
||||||
null,
|
|
||||||
NaN,
|
NaN,
|
||||||
"0",
|
"0",
|
||||||
true,
|
true,
|
||||||
@@ -39,6 +39,8 @@ Deno.test("isNumber (no match)", async () => {
|
|||||||
|
|
||||||
Deno.test("isInteger (match)", async () => {
|
Deno.test("isInteger (match)", async () => {
|
||||||
const values = [
|
const values = [
|
||||||
|
undefined,
|
||||||
|
null,
|
||||||
0,
|
0,
|
||||||
1,
|
1,
|
||||||
2e64,
|
2e64,
|
||||||
@@ -51,8 +53,6 @@ Deno.test("isInteger (match)", async () => {
|
|||||||
|
|
||||||
Deno.test("isInteger (no match)", async () => {
|
Deno.test("isInteger (no match)", async () => {
|
||||||
const values = [
|
const values = [
|
||||||
undefined,
|
|
||||||
null,
|
|
||||||
NaN,
|
NaN,
|
||||||
"0",
|
"0",
|
||||||
true,
|
true,
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { Validator, Args } from "../mod.ts";
|
|||||||
export const isNumber: Validator = {
|
export const isNumber: Validator = {
|
||||||
type: "isNumber",
|
type: "isNumber",
|
||||||
check: (value: any) => {
|
check: (value: any) => {
|
||||||
|
if (value === null || value === undefined) return;
|
||||||
if (!Number.isFinite(value)) {
|
if (!Number.isFinite(value)) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
@@ -15,6 +16,7 @@ export const isNumber: Validator = {
|
|||||||
export const isInteger: Validator = {
|
export const isInteger: Validator = {
|
||||||
type: "isInteger",
|
type: "isInteger",
|
||||||
check: (value: any) => {
|
check: (value: any) => {
|
||||||
|
if (value === null || value === undefined) return;
|
||||||
if (!Number.isInteger(value)) {
|
if (!Number.isInteger(value)) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import {
|
|||||||
|
|
||||||
Deno.test("isString (match)", async () => {
|
Deno.test("isString (match)", async () => {
|
||||||
const values = [
|
const values = [
|
||||||
|
undefined,
|
||||||
|
null,
|
||||||
"",
|
"",
|
||||||
"foo",
|
"foo",
|
||||||
new String(),
|
new String(),
|
||||||
@@ -19,8 +21,6 @@ Deno.test("isString (match)", async () => {
|
|||||||
|
|
||||||
Deno.test("isString (no match)", async () => {
|
Deno.test("isString (no match)", async () => {
|
||||||
const values = [
|
const values = [
|
||||||
undefined,
|
|
||||||
null,
|
|
||||||
0,
|
0,
|
||||||
1,
|
1,
|
||||||
true,
|
true,
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { Validator, Args } from "../mod.ts";
|
|||||||
export const isString: Validator = {
|
export const isString: Validator = {
|
||||||
type: "isString",
|
type: "isString",
|
||||||
check: (value: any) => {
|
check: (value: any) => {
|
||||||
|
if (value === null || value === undefined) return;
|
||||||
if (typeof value !== "string" && !(value instanceof String)) {
|
if (typeof value !== "string" && !(value instanceof String)) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user