Gathering detailed insights and metrics for rfdc
Gathering detailed insights and metrics for rfdc
Gathering detailed insights and metrics for rfdc
Gathering detailed insights and metrics for rfdc
npm install rfdc
Typescript
Module System
Node Version
NPM Version
99.7
Supply Chain
100
Quality
78.2
Maintenance
100
Vulnerability
100
License
JavaScript (98.83%)
TypeScript (1.17%)
Total Downloads
2,784,160,482
Last Day
1,132,411
Last Week
23,689,041
Last Month
102,624,413
Last Year
1,051,399,340
MIT License
673 Stars
73 Commits
25 Forks
10 Watchers
3 Branches
15 Contributors
Updated on Jul 03, 2025
Minified
Minified + Gzipped
Latest Version
1.4.1
Package Id
rfdc@1.4.1
Unpacked Size
26.51 kB
Size
6.67 kB
File Count
9
NPM Version
10.7.0
Node Version
22.2.0
Published on
Jun 12, 2024
Cumulative downloads
Total Downloads
Last Day
-3.7%
1,132,411
Compared to previous day
Last Week
-7.8%
23,689,041
Compared to previous week
Last Month
1.6%
102,624,413
Compared to previous month
Last Year
43.3%
1,051,399,340
Compared to previous year
Really Fast Deep Clone
1const clone = require('rfdc')() 2clone({a: 1, b: {c: 2}}) // => {a: 1, b: {c: 2}}
require('rfdc')(opts = { proto: false, circles: false, constructorHandlers: [] }) => clone(obj) => obj2
proto
optionCopy prototype properties as well as own properties into the new object.
It's marginally 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:
1require('rfdc')({ proto: false })(Object.create({a: 1})) // => {} 2require('rfdc')({ proto: true })(Object.create({a: 1})) // => {a: 1}
Setting proto
to true
will provide an additional 2% performance boost.
circles
optionKeeping track of circular references will slow down performance with an
additional 25% overhead. Even if an object doesn't have any circular references,
the tracking overhead is the cost. By default if an object with a circular
reference is passed to rfdc
, it will throw (similar to how JSON.stringify
would throw).
Use the circles
option to detect and preserve circular references in the
object. If performance is important, try removing the circular reference from
the object (set to undefined
) and then add it back manually after cloning
instead of using this option.
constructorHandlers
optionSometimes consumers may want to add custom clone behaviour for particular classes
(for example RegExp
or ObjectId
, which aren't supported out-of-the-box).
This can be done by passing constructorHandlers
, which takes an array of tuples,
where the first item is the class to match, and the second item is a function that
takes the input and returns a cloned output:
1const clone = require('rfdc')({ 2 constructorHandlers: [ 3 [RegExp, (o) => new RegExp(o)], 4 ] 5}) 6 7clone({r: /foo/}) // => {r: /foo/}
NOTE: For performance reasons, the handlers will only match an instance of the exact class (not a subclass). Subclasses will need to be added separately if they also need special clone behaviour.
default
importIt is also possible to directly import the clone function with all options set to their default:
1const clone = require("rfdc/default") 2clone({a: 1, b: {c: 2}}) // => {a: 1, b: {c: 2}}
rfdc
clones all JSON types:
Object
Array
Number
String
null
With additional support for:
Date
(copied)undefined
(copied)Buffer
(copied)TypedArray
(copied)Map
(copied)Set
(copied)Function
(referenced)AsyncFunction
(referenced)GeneratorFunction
(referenced)arguments
(copied to a normal object)All other types have output values that match the output
of JSON.parse(JSON.stringify(o))
.
For instance:
1const rfdc = require('rfdc')() 2const err = Error() 3err.code = 1 4JSON.parse(JSON.stringify(e)) // {code: 1} 5rfdc(e) // {code: 1} 6 7JSON.parse(JSON.stringify({rx: /foo/})) // {rx: {}} 8rfdc({rx: /foo/}) // {rx: {}}
1npm run bench
benchDeepCopy*100: 671.675ms
benchLodashCloneDeep*100: 1.574s
benchCloneDeep*100: 936.792ms
benchFastCopy*100: 822.668ms
benchFastestJsonCopy*100: 363.898ms // See note below
benchPlainObjectClone*100: 556.635ms
benchNanoCopy*100: 770.234ms
benchRamdaClone*100: 2.695s
benchJsonParseJsonStringify*100: 2.290s // JSON.parse(JSON.stringify(obj))
benchRfdc*100: 412.818ms
benchRfdcProto*100: 424.076ms
benchRfdcCircles*100: 443.357ms
benchRfdcCirclesProto*100: 465.053ms
It is true that fastest-json-copy may be faster, BUT it has such huge limitations that it is rarely useful. For example, it treats things like Date
and Map
instances the same as empty {}
. It can't handle circular references. plain-object-clone is also really limited in capability.
1npm test
169 passing (342.514ms)
1npm run cov
----------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files | 100 | 100 | 100 | 100 | |
index.js | 100 | 100 | 100 | 100 | |
----------|----------|----------|----------|----------|-------------------|
__proto__
own property copyingrfdc
works the same way as Object.assign
when it comes to copying ['__proto__']
(e.g. when
an object has an own property key called 'proto'). It results in the target object
prototype object being set per the value of the ['__proto__']
own property.
For detailed write-up on how a way to handle this security-wise see https://www.fastify.io/docs/latest/Guides/Prototype-Poisoning/.
MIT
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 8/21 approved changesets -- score normalized to 3
Reason
dependency not pinned by hash detected -- score normalized to 2
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
1 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-06-30
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More