README
util.obj-cycle
Monkey patched additional JSON functionality for cyclical objects
This module is a wrapper for cyclical object resolution using Douglas Crockford's JSON-js cycle code. It monkey patches two functions:
- JSON.decycle
- JSON.retrocycle
Installation
This module uses yarn to manage dependencies and run scripts for development.
To install as an application dependency with cli:
$ yarn add --dev util.obj-cycle
To build the app and run all tests:
$ yarn run all
Usage
To use this module, just use require to monkey patch it into the environment:
require('util.obj-cycle');
To remove the cycles from an object use JSON.decycle()
:
const i = {a: "x", ref: null};
const j = {b: "y", ref: null};
const k = {c: "z", ref: null};
i.ref = j;
j.ref = k;
k.ref = i;
let s: string = JSON.stringify(JSON.decycle(i));
/// s -> {"a":"x","ref":{"b":"y","ref":{"c":"z","ref":{"$ref":"