UNPKG

circular-structure-stringify

Version:

Fix around stringifying JSON with an error saying "Cannot convert Circular Structure to JSON"

19 lines (16 loc) 488 B
function CircularStructureStringify(object) { var cache = []; var str = JSON.stringify(object, function(key, value) { if (typeof value === 'object' && value !== null) { if (cache.indexOf(value) !== -1) { return; } cache.push(value); } return value; }, 4); cache = null; return str; }; module.exports = CircularStructureStringify;