0.1.0 • Published 3 years ago

nano-copy v0.1.0

Weekly downloads
8
License
MIT
Repository
github
Last release
3 years ago

nano-copy

Superfast, super small (1,461 bytes minimized, 709 gzipped) JavaScript object deep copy. Comparable to fast-copy in speed across multiple test runs.

Usage

npm install nano-copy
const nanoCopy = require("nano-copy");

or

<script src="./browser/nano-copy.min.js" type="application/javascript"></script>

Clone Types Supported

Built-in Classes

[ArrayBuffer,BigInt,Blob,Boolean,Buffer,DataView,Date,Error,Int8Array,Int16Array,Int32Array,Map,Number,RegExp,Set,String,Uint8Array,Uint16Array,Uint32Array]

Blob, Buffer and DataView are platform dependent and are included or excluded accordingly.

Custom constructors assuming:

1) There is a static from method on the class constructor that creates a deep copy.

Or

2) Object.create(Object.getPrototypeOf(source)) plus interating over all entries in the source and assigning their copies to the newly created object is correct.

Direct Copy, i.e. the same instance will be in the copy

Types returned by typeof plus,

[Boolean,Error,Number,Promise,String,Symbol,WeakMap,WeakSet]

Not Currently Supported

1) Non-enumerable properties

API

const copy = nanoCopy(source);

Or, to copy non-standard properties on Arrays and other built-in classes pass an optional argument. Note, there is a negative performance impact on long arrays.

const copy = nanoCopy(source,{nonStandard:true);

Benchmarks

Note, ALL JavaScript benchmarks in a browser or Node.js or Deno should be taken with a grain of salt when packages are within 10 ro 15% of each other due to browser, operating system, and garbage collection driven impacts.

simple object.

NameOps / sec
nano-copy3,022,398
fast-copy2,442,471
lodash.cloneDeep1,028,148
clone996,120
fast-clone650,103
deepclone576,936
ramda562,043

complex object.

NameOps / sec
nano-copy77,088
ramda68,791
deepclone66,892
fast-copy66,825
fast-clone44,917
clone33,022
lodash.cloneDeep24,610

circular object

NameOps / sec
nano-copy1,464,237
fast-copy955,628
deepclone620,598
ramda598,227
lodash.cloneDeep480,912
clone471,526
fast-clone0

averages

NameOps / sec
nano-copy1,607.397
fast-copy1,231.544
lodash.cloneDeep562.028
clone445.612
deepclone389.008
ramda382.105
fast-clone323.623

Release History (Reverse Chronological Order)

2020-12-13 v0.1.0 Added support for non-standard properties on Arrays and clonable objects.

2020-12-10 v0.0.4b Documentation fixes.

2020-12-10 v0.0.3b Fixed node export. Added benchee benchmarks.

2020-12-10 v0.0.2b Replaced Object.entries(data) with for(const key in data). Faster and gets inherited properties.

2020-12-09 v0.0.1b Initial public release (BETA)