From 54aab99bfaeb6cff8a6ed93a6f48d14617b59017 Mon Sep 17 00:00:00 2001 From: luci Date: Tue, 29 Nov 2022 22:44:12 +0800 Subject: [PATCH] chore(is): add some type guard --- src/is.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/is.ts b/src/is.ts index 322f179..79eb574 100644 --- a/src/is.ts +++ b/src/is.ts @@ -6,6 +6,10 @@ export const isFunction = (val: any): val is T => typeof va export const isNumber = (val: any): val is number => typeof val === 'number' export const isString = (val: unknown): val is string => typeof val === 'string' export const isObject = (val: any): val is object => toString(val) === '[object Object]' +export const isUndefined = (val: any): val is undefined => toString(val) === '[object Undefined]' +export const isNull = (val: any): val is null => toString(val) === '[object Null]' +export const isRegExp = (val: any): val is RegExp => toString(val) === '[object RegExp]' +export const isDate = (val: any): val is Date => toString(val) === '[object Date]' // @ts-ignore export const isWindow = (val: any): boolean => typeof window !== 'undefined' && toString(val) === '[object Window]'