Socket
Socket
Sign inDemoInstall

fclone

Package Overview
Dependencies
8
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    fclone

Clone objects by dropping circular references


Version published
Weekly downloads
1.3M
decreased by-8.49%
Maintainers
1
Install size
12.7 kB
Created
Weekly downloads
 

Readme

Source

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:

fclone x 17,081 ops/sec ±0.71% (79 runs sampled)
fclone + json.stringify x 9,433 ops/sec ±0.91% (81 runs sampled)
util.inspect (outputs a string) x 2,498 ops/sec ±0.77% (90 runs sampled)
jsan x 5,379 ops/sec ±0.82% (91 runs sampled)
circularjson x 4,719 ops/sec ±1.16% (91 runs sampled)
deepcopy x 5,478 ops/sec ±0.77% (86 runs sampled)
json-stringify-safe x 5,828 ops/sec ±1.30% (84 runs sampled)
clone x 8,713 ops/sec ±0.68% (88 runs sampled)
Fastest is util.format (outputs a string)

Keywords

FAQs

Last updated on 23 Jan 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc