Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including fast-clone with all npm packages installed. Try it out:

var fastClone = require("fast-clone")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

fast-clone v1.5.13

Extremely fast deep cloning function

npm version Build Status Coverage Status Greenkeeper badge

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

import clone = require('fast-clone');

JavaScript

const clone = require('fast-clone');
const a = {
    name: 'Natasha Rominov',
    age: 30,
    skills: [
        'Pistols',
        'Espionage'
    ],
    dateOfBirth: new Date('1986-05-21T00:00:00.000Z')
};

const b = 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. 😸

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free