Socket
Socket
Sign inDemoInstall

rfdc

Package Overview
Dependencies
0
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    rfdc

Really Fast Deep Clone


Version published
Weekly downloads
12M
decreased by-26.58%
Maintainers
1
Install size
9.51 kB
Created
Weekly downloads
 

Package description

What is rfdc?

The rfdc (Really Fast Deep Clone) npm package is a module that provides a very fast deep cloning function for copying complex data structures in JavaScript. It is optimized for performance and can handle various types of data including objects, arrays, dates, and more.

What are rfdc's main functionalities?

Deep cloning objects

This feature allows you to create a deep clone of an object, meaning that all nested objects and arrays are also recursively cloned.

{"const rfdc = require('rfdc')();
const obj = { a: 1, b: { c: 2 } };
const clone = rfdc(obj);
console.log(clone); // { a: 1, b: { c: 2 } }"}

Deep cloning arrays

This feature allows you to create a deep clone of an array, including cloning all nested arrays and objects within it.

{"const rfdc = require('rfdc')();
const arr = [1, [2, 3], [4, 5]];
const clone = rfdc(arr);
console.log(clone); // [1, [2, 3], [4, 5]]"}

Customizing clone behavior

This feature allows you to customize the cloning behavior, such as whether to preserve the prototype chain or handle circular references.

{"const rfdc = require('rfdc')({ proto: false, circles: false });
const obj = { a: 1 };
obj.b = obj;
// Throws an error because 'circles: false' does not allow circular references.
const clone = rfdc(obj);"}

Other packages similar to rfdc

Readme

Source

rfdc

Really Fast Deep Clone

Usage

const clone = require('rfdc')()
clone({a: 1, b: {c: 2}}) // => {a: 1, b: {c: 2}}

API

require('rfdc')(opts = { proto: false }) => clone(obj) => obj2

proto option

It's faster to allow enumerable properties on the prototype to be copied into the cloned object (not onto it's prototype, directly onto the object).

To explain by way of code:

require('rfdc')({ proto: false })(Object.create({a: 1})) // => {}
require('rfdc')({ proto: true })(Object.create({a: 1})) // => {a: 1}

If this behavior is acceptable, set proto to true for an additional 15% performance boost (see benchmarks).

Benchmarks

npm run bench
benchDeepCopy*100: 624.535ms
benchLodashCloneDeep*100: 1740.670ms
benchRfdc*100: 547.896ms
benchRfdcProto*100: 467.896ms

Tests

npm test
52 passing (287.896ms)
Coverage
npm run cov 
----------|----------|----------|----------|----------|-------------------|
File      |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files |      100 |      100 |      100 |      100 |                   |
 index.js |      100 |      100 |      100 |      100 |                   |
----------|----------|----------|----------|----------|-------------------|

License

MIT

Keywords

FAQs

Last updated on 19 May 2018

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