Code Monkey home page Code Monkey logo

fclone's Introduction

FClone

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+
  • minor performance tweaks
  • use of Array.isArray and Buffer.isBuffer

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]' }

Benchmarks

Some benchs:

fclone x 13,342 ops/sec ±3.83% (79 runs sampled)
fclone + json.stringify x 7,311 ops/sec ±3.99% (77 runs sampled)
jsan x 4,419 ops/sec ±3.11% (86 runs sampled)
circularjson x 4,294 ops/sec ±0.82% (91 runs sampled)
deepcopy x 5,298 ops/sec ±0.76% (83 runs sampled)
json-stringify-safe x 5,201 ops/sec ±0.82% (84 runs sampled)
Fastest is fclone

fclone's People

Contributors

soyuka avatar tracker1 avatar johnius avatar

Stargazers

 avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.