JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 16333
  • Score
    100M100P100Q129375F
  • License MIT

Extremely fast deep cloning function

Package Exports

  • fast-clone

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (fast-clone) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

The fastest deep cloning function on NPM that supports the following types:

  • Objects (POJOs, null, undefined)
  • Arrays
  • Dates
  • Regular Expressions
  • Strings
  • Numbers (NaN, Positive Intinity, Negative Intinity)
  • Booleans

Speed Comparison

Average runtime of various NPM clone libraries on a large complex object loaded from a 1.61 MB json file.

Library Time
clone 1,229 ms
snapshot 213 ms
deepClone 208 ms
angular.copy 195 ms
lodash.cloneDeep 187 ms
fast-clone 72 ms

Installation

npm install fast-clone --save

Usage

Can be used in Node.js or you can use in Browser either using Browserfy/Webpack or the global clone function.

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

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

var 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']

Got an Issue or Feature Suggestion?

Then create an issue on GitHub and I'll fix/add it asap. :)

Or fork the repo and shoot me a pull request