Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

fast-clone

codeandcats57.5kMIT1.5.13TypeScript support: included

Extremely fast deep cloning function

clone, copy, deep, object, date, fast, fastest, quick, efficient

readme

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.

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

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. 😸

changelog

Change Log

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

1.5.13 (2019-03-09)

Bug Fixes

  • package: update dependencies to address vulnerabilities (766fc2a)

1.5.12 (2019-03-09)

1.5.11 (2019-03-09)

1.5.10 (2019-03-09)

1.5.9 (2019-03-09)

1.5.8 (2019-03-09)

1.5.7 (2019-03-09)

1.5.6 (2019-03-09)

1.5.4 (2019-03-09)