UNPKG

bobflux-monitor

Version:

Component for time travelling in bobflux/fun-model application state history.

23 lines (17 loc) 686 B
export function allToString(obj?: Object[] | Date | Object | string | null): string { if (obj === null) return 'null'; if (obj === undefined) return 'undefined'; if (Array.isArray(obj)) return `[${(<Object[]>obj).map(item => allToString(item))}]`; if (obj instanceof Date) { return `new Date(${(<Date>obj).getTime()})`; } if (typeof obj === 'object') { return `{ ${Object.keys(obj).map(key => `${key}: ${allToString((<{ [key: string]: string }>obj)[key])}`).join(', ')} }`; } if (typeof obj === 'string') return `'${obj}'`; return (<{ toString: Function }>obj).toString(); }