0.0.9 • Published 4 years ago

util.obj-cycle v0.0.9

Weekly downloads
1,038
License
MIT
Repository
github
Last release
4 years ago

util.obj-cycle

Monkey patched additional JSON functionality for cyclical objects

build analysis code style: prettier testing NPM

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":"$"}}}}

The process can be reversed on the object with JSON.retrocycle:

	let obj = JSON.retrocycle(JSON.parse(s));

The functions can also be included directly without the monkey patching by using import:

import {decycle, retrocycle} from "util.obj-cycle";

This is the same underlying code. Just a differnt way to do the same thing.

0.0.9

4 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago