// type NonNullable = T extends null | undefined ? never : T; const toString = Object.prototype.toString; const isType = (type: string | string[]) => (obj: unknown): obj is T => getType(obj) === `[object ${type}]`; export const getType = (obj: any) => toString.call(obj); export const isArr = Array.isArray; export const isValid = (val: any) => val !== null && val !== undefined; export const isFn = (val: any): val is Function => typeof val === 'function'; export const isPlainObj = isType('Object'); export const isStr = isType('String'); export const isBool = isType('Boolean'); export const isNum = isType('Number'); export const isMap = (val: any): val is Map => val && val instanceof Map; export const isSet = (val: any): val is Set => val && val instanceof Set; export const isWeakMap = (val: any): val is WeakMap => val && val instanceof WeakMap; export const isWeakSet = (val: any): val is WeakSet => val && val instanceof WeakSet; export const isNumberLike = (index: any): index is number => isNum(index) || /^\d+$/.test(index); export const isObj = (val: unknown): val is object => typeof val === 'object'; export const isRegExp = isType('RegExp'); export const isReactElement = (obj: any): boolean => obj && obj['$$typeof'] && obj['_owner']; export const isHTMLElement = (target: any): target is EventTarget => { return Object.prototype.toString.call(target).indexOf('HTML') > -1; };