Skip to content
This repository was archived by the owner on Jun 19, 2019. It is now read-only.

Repository files navigation

npm versionBuild StatusCoverage StatusGreenkeeper badge

DEPRECATION NOTICE

After a few years since it's creation, fast-clone is no longer the fastest cloning library on npm. Alternative packages have caught up and overtaken it. I had a last stab at optimising it while adding new features but alas optimising for performance further meant sacrificing features (and vice-versa). So I've decided to hand over the fast-clone npm namespace to a more worthy contender. rfdc (really fast deep clone) is exactly what it's initialism means: really fast.

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.

Library7.15 MB
fast-clone120 ms
✘ deepClone138 ms
✘ lodash.cloneDeep155 ms
✘ snapshot1,127 ms
✘ angular.copy1,942 ms
✘ clone2,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

importclone= require('fast-clone');

JavaScript

constclone=require('fast-clone');
consta={name: 'Natasha Rominov',age: 30,skills: ['Pistols','Espionage'],dateOfBirth: newDate('1986-05-21T00:00:00.000Z')};constb=clone(a);b.skills.push('That grabby thing she does with her legs');console.log(a.skills)console.log(b.skills);

Output will be:

['Pistols','Espionage']['Pistols','Espionage','That grabby thing she does with her legs']

Contributing

Got an issue or a feature request? Log it.

Pull-requests are also welcome. 😸

About

Extremely fast javascript deep cloning function

Resources

Code of conduct

Contributing

Stars

22 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages