Get support for soyuka/fclone

If you're new to LTH, please see our FAQ for more information on what it is we do.

Support Options

Unfortunately, there are currently no active helpers for this repository on the platform. Until they become available, we reccomend the following actions:

View Open Issues

Take a look to see if anyone else has experienced the same issue as you and if they managed to solve it.

Open an Issue

Make sure to read any relevant guidelines for opening issues on this repo before posting a new issue.

Sponsor directly

Check out the page and see if there are any options to sponsor this project or it's developers directly.

soyuka/fclone

FClone

Clone objects by dropping circular references

Build Status

This module clones a Javascript object in safe mode (eg: drops circular values) recursively. Circular values are replaced with a string: '[Circular]'.

Ideas from tracker1/safe-clone-deep. I improved the workflow a bit by:

  • refactoring the code (complete rewrite)
  • fixing node 6+
  • micro optimizations
  • use of Array.isArray and Buffer.isBuffer

Node 0.10 compatible, distributed files are translated to es2015.

Installation

npm install fclone
# or
bower install fclone

Usage

const fclone = require('fclone');

let a = {c: 'hello'};
a.b = a;

let o = fclone(a);

console.log(o);
// outputs: { c: 'hello', b: '[Circular]' }

//JSON.stringify is now safe
console.log(JSON.stringify(o));

Benchmarks

Some benchs:

# Clone
fclone (not a string) x 14,121 ops/sec ±0.75% (89 runs sampled)
clone (not a string) x 9,293 ops/sec ±0.93% (90 runs sampled)
deepcopy (not a string) x 5,375 ops/sec ±0.73% (92 runs sampled)
rfdc x 12,786 ops/sec ±1.31% (91 runs sampled)

# Stringify
fclone + json.stringify x 8,289 ops/sec ±0.74% (90 runs sampled)
fast-safe-stringify x 8,241 ops/sec ±0.48% (92 runs sampled)
util.inspect (outputs a string) x 2,115 ops/sec ±0.84% (89 runs sampled)
jsan x 5,090 ops/sec ±0.65% (92 runs sampled)
circularjson x 4,471 ops/sec ±0.67% (92 runs sampled)
json-stringify-safe x 7,150 ops/sec ±0.97% (91 runs sampled)
Fastest is fclone (not a string)
Our Mission

We want to make open source more sustainable. The entire platform was born from this and everything we do is in aid of this.

Interesting Articles

Thank you for checking out LiveTechHelper |
2025 © lth-dev incorporated

p-e622a1a2