1.0.2 • Published 2 years ago

quick-copy v1.0.2

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

quick-copy 1.0.0

This package provides the quickCopy() function, which is the fastest ES6 deep copier on NPM, handling all ES6 = ECMA-2015 data-types. The fast-copy package previously held the crown, and it documents its speed against other packages, so we just document how many times faster quick-copy is over fast-copy in the table below.

Object typeHow many times faster quick-copy is over fast-copy
Strings5.0 times faster
Numbers2.1 times faster
Booleans2.2 times faster
Dates1.12 times faster
RegExps1.29 times faster
Sets1.15 times faster
ArrayBuffers1.23 times faster
Buffers1.61 times faster
DataViews/Typed ArraysNA because only quick-copy is correct (*)
Errors1.27 times faster

(*) quick-copy will copy circular/duplicate ArrayBuffer references amongst typed-arrays and DataViews. Here quick-copy is faster only by a whisker. Also, with Numbers and Booleans, only quick-copy is correct.

All forms of quick-copy, copy WeakSets, WeakMaps, and Promises as is.

To copy property descriptors, non-enumerable properties, getters/setters, and properties of the data-types use quickCopy.all() rather than quickCopy(). For example, in copying a Boolean with property p, if you want the property p to be copied use quickCopy.all().

Circular/duplicate references are copied by both quickCopy(), and quickCopy.all(). quickCopy() will copy functions as is. quickCopy.all() will properly copy functions in addition to getters/setters. Like fast-copy, both quick-copies copy Errors as is. That's because copying errors properly will slow code down to a crawl since call stacks are traced.

Usage

    const {quickCopy} = require('quick-copy')
    
    const x = Object built from plain objects, plain functions, 
              ES6 data-types and Node's Buffer.  
              
    const y = quickCopy(x)          // y is a deep copy of x.
    
    const z = quickCopy.all(x)      // z is a deep copy of x.

    If property descriptors, non-enumerable properties, 
    getters/setters, and properties of the data-types are a factor, 
    then use quickCopy.all(). Otherwise you may use quickCopy()  

Configure your own Deep Copier

The quick-copy package also exports the quickCopyExt(x, params) function. quickCopyExt(x), without the second parameter, is exactly like quickCopy(x) except that it doesn't handle circular/duplicate references. So it is even faster than quickCopy(x).

Otherwise params has too many fields, so the idea is to use params only to configure your own deep copier. See Supplement.md, in the node-modules/quick-copy folder, for details.

Exports Summary

ExportDescription
quickCopy(x)Fastest ES6 deep copier on NPM.
quickCopy.all(x)Properly copies functions and getters/setters. Copies properties of the data-types. Copies property descriptors. Copies all properties, not just the enumerable ones. In its class also fastest on NPM.
quickCopyExt(x)Even faster than quickCopy since it doesn't handle circular/duplicate references.
quickCopyExt(x, params)Configure your own deep-copier. See Supplement.md.

P.S.

In addition to its speed, another reason to consider this package is its total iron-clad correctness: No other ES6 deep-copying package has passed this author's test suite.

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago