Miss any of our Open RFC calls?Watch the recordings here! »

graph-clone

1.2.2 • Public • Published

Graph Clone

This module offers a traversal mechanic for circular data JSON structures that allows you to clone or skip cloning on nodes and also apply optional transforms to encountered nodes.

Example usage

See test.js for best illustrating example. Below is a dead simple version but the test is more exhaustive

var w = require('graph-clone')
var stringify = require('json-stringify-safe')
var obj = {
  foo: {
    name: 'boris',
    bar: null 
  }
}
obj.foo.bar = obj
 
var copy = w(obj, () => true, (obj, key, val) => key === 'name' ? val + '!!!' : val)
 
console.log(stringify(copy))
 
// copy = {
//   foo: {
//      name: 'boris!!!',
//      bar: [ circular ]
//   }
// }

Install

npm i graph-clone

DownloadsWeekly Downloads

1

Version

1.2.2

License

MIT

Last publish

Collaborators

  • avatar