import type { Falsy , Primitive , UnknownRecord } from "./types" ; export function raise ( error ) { throw typeof error === "string" ? new Error ( error ) : error ; } export function toError ( value ) { return value instanceof Error ? value : new Error ( String ( value ) ) ; } export function getErrorInfo ( error ) { const { stack , message } = toError ( error ) ; return stack || message ; } export function includes < Value > ( array , value ) { return array . includes ( value as Value ) ; } export function hasKey < Subject > ( object , key ) { return key in object ; } export function isTruthy < T > ( value ) { return ! ! value ; } export function sleep ( ms ) { return new Promise ( ( resolve ) => setTimeout ( resolve , ms ) ) ; } /**
 * Checks at runtime if a value is a non-primitive,
 * while narrowing primitives out of the type
 */ export function isObject < T > ( value ) { return typeof value === "object" && value !== null ; } /**
 * Like  isObject , but accepts unknown,
 * and narrows it to a more usable UnknownRecord
  export function isAnyObject ( value ) { return isObject ( value ) ; } export function isString ( value ) { return typeof value === "string" ; } export function isNonNil < T > ( value ) { return value != null ; } export function last < T > ( array ) { return array [ array . length - 1 ] ; } export function isDeepEqual ( a , b ) { if ( Object . is ( a , b ) ) return true ; if ( a == null || b == null ) return false ; if ( typeof a !== "object" || typeof b !== "object" ) return false ; if ( Object . keys ( a ) . length !== Object . keys ( b ) . length ) return false ; for ( const key in a ) { if ( ! isDeepEqual ( a [ key ] , b [ key ] ) ) return false ; } return true ; }