fast-clone
Extremely fast deep cloning function
Last updated 7 years ago by codeandcats .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install fast-clone 
SYNC missed versions from official npm registry.

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

Current Tags

  • 1.5.13                                ...           latest (7 years ago)

17 Versions

  • 1.5.13                                ...           7 years ago
  • 1.5.12                                ...           7 years ago
  • 1.5.9                                ...           7 years ago
  • 1.5.8                                ...           7 years ago
  • 1.5.7                                ...           7 years ago
  • 1.5.6                                ...           7 years ago
  • 1.5.3                                ...           8 years ago
  • 1.5.2                                ...           8 years ago
  • 1.5.1                                ...           8 years ago
  • 1.4.2                                ...           10 years ago
  • 1.4.0                                ...           10 years ago
  • 1.3.0                                ...           10 years ago
  • 1.2.0                                ...           10 years ago
  • 1.1.0                                ...           10 years ago
  • 1.0.2                                ...           10 years ago
  • 1.0.1                                ...           10 years ago
  • 1.0.0                                ...           10 years ago
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 2
Last Month 3
Dependencies (0)
None
Dev Dependencies (0)
None
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |