UNPKG

@olton/latte

Version:

Simple test framework for JavaScript and TypeScript with DOM supports

26 lines (25 loc) 636 B
export const stringify = (obj) => { const safer = () => { const seen = new WeakSet() return (key, value) => { if (typeof value === 'object' && value !== null) { if (seen.has(value)) { return } seen.add(value) } return value } } return JSON.stringify(obj, safer()) } export const safeStringify = (obj) => { const seen = new WeakSet(); return JSON.stringify(obj, (key, value) => { if (typeof value === 'object' && value !== null) { if (seen.has(value)) return '[Circular]'; seen.add(value); } return value; }); }