You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
louisafriederike b00d9f80ed | 8 months ago | |
---|---|---|
.. | ||
.npmignore | 8 months ago | |
LICENSE | 8 months ago | |
README.md | 8 months ago | |
index.js | 8 months ago | |
package.json | 8 months ago |
README.md
Circular
Tiny utility to safely stringify objects with circular references.
Usage
Replace all circular references with the string [Circular]
;
var circular = require('circular');
var obj = {}; var child = {parent: obj}; obj.child = child;
var str = JSON.stringify(obj, circular());
// => {"child":{"parent":"[Circular]"}}
If you prefer you can pass an alternative string to use:
var str = JSON.stringify(obj, circular('#ref'));
Or a function that returns a string:
function ref(value){return '' + value};
var str = JSON.stringify(obj, circular(ref));
As of version 1.0.4
you can also pass an additional boolean that will convert function references to strings, useful for converting javascript modules to couchdb
design documents.
var str = JSON.stringify(obj, circular(null, true));