Skip to content

Commit f8698cd

Browse files
authored
feat(is): add some type guard (#25)
1 parent 1b59af5 commit f8698cd

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/is.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ export const isFunction = <T extends Function> (val: any): val is T => typeof va
66
export const isNumber = (val: any): val is number => typeof val === 'number'
77
export const isString = (val: unknown): val is string => typeof val === 'string'
88
export const isObject = (val: any): val is object => toString(val) === '[object Object]'
9+
export const isUndefined = (val: any): val is undefined => toString(val) === '[object Undefined]'
10+
export const isNull = (val: any): val is null => toString(val) === '[object Null]'
11+
export const isRegExp = (val: any): val is RegExp => toString(val) === '[object RegExp]'
12+
export const isDate = (val: any): val is Date => toString(val) === '[object Date]'
913

1014
// @ts-ignore
1115
export const isWindow = (val: any): boolean => typeof window !== 'undefined' && toString(val) === '[object Window]'

0 commit comments

Comments
 (0)