Sha256: ac7e5288595d3eccf83992f11153bd19b9b4592db9c5cc3dafd2d4200c9b3c32
Contents?: true
Size: 954 Bytes
Versions: 32
Compression:
Stored size: 954 Bytes
Contents
module.exports = stringify; function getSerialize (fn, decycle) { var seen = [], keys = []; decycle = decycle || function(key, value) { return '[Circular ' + getPath(value, seen, keys) + ']' }; return function(key, value) { var ret = value; if (typeof value === 'object' && value) { if (seen.indexOf(value) !== -1) ret = decycle(key, value); else { seen.push(value); keys.push(key); } } if (fn) ret = fn(key, ret); return ret; } } function getPath (value, seen, keys) { var index = seen.indexOf(value); var path = [ keys[index] ]; for (index--; index >= 0; index--) { if (seen[index][ path[0] ] === value) { value = seen[index]; path.unshift(keys[index]); } } return '~' + path.join('.'); } function stringify(obj, fn, spaces, decycle) { return JSON.stringify(obj, getSerialize(fn, decycle), spaces); } stringify.getSerialize = getSerialize;
Version data entries
32 entries across 18 versions & 3 rubygems