rfdc
Really Fast Deep Clone
Usage
const clone = require('rfdc')()
clone({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}))
If this behavior is acceptable, set
proto
to true
for an additional 25% 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