export type AnyFunction = ( ... args : any [ ] ) => any ; export type AnyAsyncFunction = ( ... args : any [ ] ) => Promise < any > ; export type AnyClass = new ( ... args ) => any ; export type PlainObject = Record < string | number | symbol , any > ; type TypeGuard < A , B extends A > = ( payload : A ) => payload is B ; param { * } payload returns { string } export function getType ( payload ) { return Object . prototype . toString . call ( payload ) . slice ( 8 , - 1 ) ; } param { * } payload returns { payload is undefined } export function isUndefined ( payload ) { return getType ( payload ) === 'Undefined' ; } param { * } payload returns { payload is null } export function isNull ( payload ) { return getType ( payload ) === 'Null' ; } param { * } payload returns { payload is PlainObject } export function isPlainObject ( payload ) { if ( getType ( payload ) !== 'Object' ) return false ; return payload . constructor === Object && Object . getPrototypeOf ( payload ) === Object . prototype ; } param { * } payload returns { payload is PlainObject } export function isObject ( payload ) { return isPlainObject ( payload ) ; } param { * } payload returns { payload is { [ K in any ] : never } } export function isEmptyObject ( payload ) { return isPlainObject ( payload ) && Object . keys ( payload ) . length === 0 ; } param { * } payload returns { payload is PlainObject } export function isFullObject ( payload ) { return isPlainObject ( payload ) && Object . keys ( payload ) . length > 0 ; } param { * } payload returns { payload is PlainObject } export function isAnyObject ( payload ) { return getType ( payload ) === 'Object' ; } template T param { * } payload returns { payload is T } export function isObjectLike < T extends PlainObject > ( payload ) { return isAnyObject ( payload ) ; } param { * } payload returns { payload is AnyFunction } export function isFunction ( payload ) { return typeof payload === 'function' ; } param { any } payload returns { payload is any [ ] } export function isArray ( payload ) { return getType ( payload ) === 'Array' ; } param { * } payload returns { payload is any [ ] } export function isFullArray ( payload ) { return isArray ( payload ) && payload . length > 0 ; } param { * } payload returns { payload is [ ] } export function isEmptyArray ( payload ) { return isArray ( payload ) && payload . length === 0 ; } param { * } payload returns { payload is string } export function isString ( payload ) { return getType ( payload ) === 'String' ; } param { * } payload returns { payload is string } export function isFullString ( payload ) { return isString ( payload ) && payload !== '' ; } param { * } payload returns { payload is string } export function isEmptyString ( payload ) { return payload === '' ; } param { * } payload returns { payload is number } export function isNumber ( payload ) { return getType ( payload ) === 'Number' && ! isNaN ( payload ) ; } param { * } payload returns { payload is number } export function isPositiveNumber ( payload ) { return isNumber ( payload ) && payload > 0 ; } param { * } payload returns { payload is number } export function isNegativeNumber ( payload ) { return isNumber ( payload ) && payload < 0 ; } param { * } payload returns { payload is boolean } export function isBoolean ( payload ) { return getType ( payload ) === 'Boolean' ; } param { * } payload returns { payload is RegExp } export function isRegExp ( payload ) { return getType ( payload ) === 'RegExp' ; } param { * } payload returns { payload is Map < any , any > } export function isMap ( payload ) { return getType ( payload ) === 'Map' ; } param { * } payload returns { payload is WeakMap < any , any > } export function isWeakMap ( payload ) { return getType ( payload ) === 'WeakMap' ; } param { * } payload returns { payload is Set < any > } export function isSet ( payload ) { return getType ( payload ) === 'Set' ; } param { * } payload returns { payload is WeakSet < any > } export function isWeakSet ( payload ) { return getType ( payload ) === 'WeakSet' ; } param { * } payload returns { payload is symbol } export function isSymbol ( payload ) { return getType ( payload ) === 'Symbol' ; } param { * } payload returns { payload is Date } export function isDate ( payload ) { return getType ( payload ) === 'Date' && ! isNaN ( payload ) ; } param { * } payload returns { payload is Blob } export function isBlob ( payload ) { return getType ( payload ) === 'Blob' ; } param { * } payload returns { payload is File } export function isFile ( payload ) { return getType ( payload ) === 'File' ; } param { * } payload returns { payload is Promise < any > } export function isPromise ( payload ) { return getType ( payload ) === 'Promise' ; } param { * } payload returns { payload is Error } export function isError ( payload ) { return getType ( payload ) === 'Error' ; } param { * } payload returns { payload is typeof NaN } export function isNaNValue ( payload ) { return getType ( payload ) === 'Number' && isNaN ( payload ) ; } param { * } payload returns { ( payload export function isPrimitive ( payload ) { return ( isBoolean ( payload ) || isNull ( payload ) || isUndefined ( payload ) || isNumber ( payload ) || isString ( payload ) || isSymbol ( payload ) ) ; } param { * } payload returns { ( payload export const isNullOrUndefined = isOneOf ( isNull , isUndefined ) ; export function isOneOf < A , B extends A , C extends A > ( a , b ) ; export function isOneOf < A , B extends A , C extends A , D extends A > ( a , b , c ) ; export function isOneOf < A , B extends A , C extends A , D extends A , E extends A > ( a , b , c , d ) ; export function isOneOf < A , B extends A , C extends A , D extends A , E extends A , F extends A > ( a , b , c , d , e ) ; export function isOneOf ( a , b , c ? , d ? , e ? ) { return ( value ) => a ( value ) || b ( value ) || ( ! ! c && c ( value ) ) || ( ! ! d && d ( value ) ) || ( ! ! e && e ( value ) ) ; } template T param { * } payload param { T } type throws returns { payload is T } export function isType < T extends AnyFunction | AnyClass > ( payload , type ) { if ( ! ( type instanceof Function ) ) { throw new TypeError ( 'Type must be a function' ) ; } if ( ! Object . prototype . hasOwnProperty . call ( type , 'prototype' ) ) { throw new TypeError ( 'Type is not a class' ) ; } const name = ( type as any ) . name ; return getType ( payload ) === name || Boolean ( payload && payload . constructor === type ) ; }