const isClassRegex = /^class\s|^function\s+[A-Z]/ ; const isConventionalClassRegex = /^function\s+[A-Z]/ ; const isNativeClassRegex = /^class\s/ ; /** Determines if the passed value is of a specific type */ export type TypeTester = ( value : any ) => boolean ; /**
 * The interface for a type mapping (key => function) to use for  getType .
 export * The key represents the name of the type. The function represents the  TypeTester .
 * The map should be ordered by testing preference, with more specific tests first.
 * If a test returns true, it is selected, and the key is returned as the type.
  export interface TypeMap { [ type ] : TypeTester ; } /** Get the object type string */ export function getObjectType ( value ? ) { return Object . prototype . toString . call ( value ) ; } /** Checks to see if a value is an object */ export function isObject ( value ? ) { return value !== null && typeof value === 'object' ; } /** Checks to see if a value is an object and only an object */ export function isPlainObject ( value ? ) { return isObject ( value ) && value . __proto__ === Object . prototype ; } /**
 * Is ES6+ class */ export function isNativeClass ( value ? ) { return ( typeof value === 'function' && isNativeClassRegex . test ( value . toString ( ) ) ) ; } /**
 * Is Conventional Class
 export * Looks for function with capital first letter MyClass
 * First letter is the 9th character
 * If changed, isClass must also be updated */ export function isConventionalClass ( value ? ) { return ( typeof value === 'function' && isConventionalClassRegex . test ( value . toString ( ) ) ) ; } export function isClass ( value ? ) { return typeof value === 'function' && isClassRegex . test ( value . toString ( ) ) ; } /** Checks to see if a value is an error */ export function isError ( value ? ) { return value instanceof Error ; } /** Checks to see if a value is a date */ export function isDate ( value ? ) { return getObjectType ( value ) === '[object Date]' ; } /** Checks to see if a value is an arguments object */ export function isArguments ( value ? ) { return getObjectType ( value ) === '[object Arguments]' ; } /**
 export * Checks to see if a value is a function but not an asynchronous function */ export function isSyncFunction ( value ? ) { return getObjectType ( value ) === '[object Function]' ; } /** Checks to see if a value is an asynchronous function */ export function isAsyncFunction ( value ? ) { return getObjectType ( value ) === '[object AsyncFunction]' ; } /** Checks to see if a value is a function */ export function isFunction ( value ? ) { return isSyncFunction ( value ) || isAsyncFunction ( value ) ; } /** Checks to see if a value is an regex */ export function isRegExp ( value ? ) { return getObjectType ( value ) === '[object RegExp]' ; } /** Checks to see if a value is an array */ export function isArray ( value ? ) { return ( ( typeof Array . isArray === 'function' && Array . isArray ( value ) ) || getObjectType ( value ) === '[object Array]' ) ; } /** Checks to see if a valule is a number */ export function isNumber ( value ? ) { return typeof value === 'number' || getObjectType ( value ) === '[object Number]' ; } /** Checks to see if a value is a string */ export function isString ( value ? ) { return typeof value === 'string' || getObjectType ( value ) === '[object String]' ; } /** Checks to see if a valule is a boolean */ export function isBoolean ( value ? ) { return ( value === true || value === false || getObjectType ( value ) === '[object Boolean]' ) ; } /** Checks to see if a value is null */ export function isNull ( value ? ) { return value === null ; } /** Checks to see if a value is undefined */ export function isUndefined ( value ? ) { return typeof value === 'undefined' ; } /** Checks to see if a value is a Map */ export function isMap ( value ? ) { return getObjectType ( value ) === '[object Map]' ; } /** Checks to see if a value is a WeakMap */ export function isWeakMap ( value ? ) { return getObjectType ( value ) === '[object WeakMap]' ; } /** Checks to see if a value is nullish */ export function isNullish ( value ? ) { return value == null ; } /**
 * Is empty array
 * Will throw if the value was not an array
 */ export function isEmptyArray ( value ) { if ( ! isArray ( value ) ) throw new Error ( 'value was not an array' ) ; return value . length === 0 ; } /**
 * Is empty plain object
 * Will throw if the value was not a plain object
 */ export function isEmptyPlainObject ( value ) { if ( ! isPlainObject ( value ) ) throw new Error ( 'value was not a plain object' ) ; for ( const key in value ) { if ( value . hasOwnProperty ( key ) ) { return false ; } } return true ; } /**
 * Is empty map
 * Will throw if the value was not a map
 */ export function isEmptyMap ( value ) { if ( ! isMap ( value ) ) throw new Error ( 'value was not a map' ) ; for ( const key of value ) { return false ; } return true ; } /**
 * Is empty weak map
 * Will throw if the value was not a weak map
 */ export function isEmptyWeakMap ( value ) { if ( ! isWeakMap ( value ) ) throw new Error ( 'value was not a weak map' ) ; for ( const key of value ) { return false ; } return true ; } /**
 * Is empty keys
 */ export function isEmptyKeys ( value ) { return Object . keys ( value ) . length === 0 ; } /**
 * The default  TypeMap for  getType .
 export * AsyncFunction and SyncFunction are missing, as they are more specific types that people can detect afterwards.
 *  readonly export const typeMap = Object . freeze ( { array : isArray , boolean : isBoolean , date : isDate , error : isError , class : isClass , function : isFunction , null : isNull , number : isNumber , regexp : isRegExp , string : isString , undefined : isUndefined , map : isMap , weakmap : isWeakMap , object : isObject , } as TypeMap ) ; /**
 * Cycle through the passed  TypeMap testing the value, returning the first type that passes, otherwise `null`.
 *  param value param customTypeMap defaults to  typeMap export function getType ( value , customTypeMap = typeMap ) { for ( const key in customTypeMap ) { if ( customTypeMap . hasOwnProperty ( key ) ) { if ( customTypeMap [ key ] ( value ) ) { return key ; } } } return null ; }