The fastest deep cloning function on NPM that supports the following types:
- Objects (POJOs, null, undefined)
- Arrays
- Dates
- Regular Expressions
- Strings
- Numbers (NaN, Positive Infinity, Negative Infinity)
- Booleans
Speed Comparison
Average runtime of various NPM clone libraries on a large complex object loaded from json files of varying sizes ranging from 3.5 MB to 15 MB.
Library | 7.15 MB |
---|---|
✔ fast-clone | 120 ms |
✘ deepClone | 138 ms |
✘ lodash.cloneDeep | 155 ms |
✘ snapshot | 1,127 ms |
✘ angular.copy | 1,942 ms |
✘ clone | 2,085 ms |
Installation
NPM
npm install fast-clone --save
Yarn
yarn add fast-clone
Usage
Fast-clone is a UMD module so you can use it in Node.js, or in Browser either using Browserfy/Webpack, or by using the global clone function if not using a module loader.
TypeScript
;
JavaScript
const clone = ;
; ; b.skills.push'That grabby thing she does with her legs'; console.loga.skillsconsole.logb.skills;
Output will be:
Contributing
Got an issue or a feature request? Log it.
Pull-requests are also welcome. 😸