npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

deep-copy-all

v1.3.4

Published

deep copy JavaScript data of any type

Downloads

3,701

Readme

deep-copy-all

A fast, compact, and robust method to deep copy all JavaScript data types

GitHub top language GitHub package.json version codebeat badge David NPM Downloads NPM License Twitter

deep-copy-all JavaScript object deep cloner is:

  • fast – ranking highly on common benchmark speed tests

  • compact – about 5k (minified)

  • robust – correctly handling all standard JavaScript data types, as well as custom types

Install

$ npm install deep-copy-all

Usage

Node.js

const deepCopy = require('deep-copy-all');
/* ... */
copy = deepCopy(source);

HTML file:

<script src="dist/deepCopyAll.browser.js"></script>
<script>
  /* ... */
  let copy = deepCopy(source);
</script>

Comparison

The accuracy of deep-copy-all compares well against other deep copying packages.

Legend:     ☑️ - deep copy     🚧 - shallow copy     🗑️ - data loss     ⚠️ - Error

data type | JSON.* | ce | d-c | dc | cl | f-c | deep-copy-all ----------------- | ------ | --- | --- | --- | --- | --- | ------------- Array | ☑️ | ☑️ |☑️|☑️|☑️|☑️|☑️ ArrayBuffer | 🗑️ | 🗑️ |🗑️|☑️|🗑️|☑️|☑️ BigInt | ⚠️ | ☑️ |☑️|☑️|☑️|☑️|☑️ BigInt64Array | ⚠️ | 🗑️ |🗑️|🚧|☑️|☑️|☑️ BigUint64Array | ⚠️ | 🗑️ |🗑️|🚧|☑️|☑️|☑️ Buffer | 🗑️ | 🗑️ |🗑️|☑️|☑️|☑️|☑️ Date | 🗑️ | ☑️ |☑️|☑️|☑️|☑️|☑️ Error | 🗑️ | 🗑️ |🗑️|🚧|☑️|🚧|☑️ Float32Array | 🗑️ | 🗑️ |🗑️|☑️|☑️|☑️|☑️ Float64Array | 🗑️ | 🗑️ |🗑️|☑️|☑️|☑️|☑️ Int8Array | 🗑️ | 🗑️ |🗑️|☑️|☑️|☑️|☑️ Int8Array | 🗑️ | 🗑️ |🗑️|☑️|☑️|☑️|☑️ Int32Array | 🗑️ | 🗑️ |🗑️|☑️|☑️|☑️|☑️ Map | 🗑️ | 🗑️ |🗑️|☑️|☑️|☑️|☑️ Object | ☑️ | ☑️ |☑️|☑️|☑️|☑️|☑️ RegExp | 🗑️ | 🗑️ |🗑️|☑️|☑️|☑️|☑️ Set | 🗑️ | 🗑️ |🗑️|☑️|☑️|☑️|☑️ Uint8Array | 🗑️ | 🗑️ |🗑️|☑️|☑️|☑️|☑️ Uint8ClampedArray | 🗑️ | 🗑️ |🗑️|☑️|☑️|☑️|☑️ Uint16Array | 🗑️ | 🗑️ |🗑️|☑️|☑️|☑️|☑️ Uint32Array | 🗑️ | 🗑️ |🗑️|☑️|☑️|☑️|☑️ WeakMap | 🗑️ | 🗑️ |🗑️|🚧|⚠️|🚧|🚧 WeakSet | 🗑️ | 🗑️ |🗑️|🚧|⚠️|🚧|🚧 enumerable:false | 🗑️ | 🗑️ |🗑️|🗑️|🗑️|🗑️|☑️ custom Array | 🗑️ | 🗑️ |🗑️|🗑️|🗑️|☑️|☑️ custom Object | 🗑️ | 🗑️ |🗑️|🗑️|☑️|☑️|☑️ circular Object | ⚠️ | ☑️ |⚠️|☑️|☑️|🗑️|☑️

JSON.* - JSON.parse(JSON.stringify()) ce - cloneextend d-c - deep-copy dc - deepcopy cl - clone f-c - fast-copy


deepCopy()

Perform deep copy of a JavaScript object or array.

Syntax

deepCopy(source [, options])

Parameters

source     The item to copy.

options     {Object} [optional] - Modifies copying behavior.

options properties:

    goDeep        {Boolean} [optional] - Perform deep copy if true (default).        Set to false to perform shallow copy.

    includeNonEnumerable        {Boolean} [optional] - Copies non-enumerable properties if true.        Skips non-enumerable properties if false (default).

    detectCircular        {Boolean} [optional] - Detect circular references if true (default).        May be set to false if source has no circular references.

    maxDepth        {number} [optional] - The maximum depth to copy, default is 20 levels.

Return value

The copied data.


Performance

The following data types — passed directly to deepCopy or embedded within another object — have been verified to be copied correctly:

  • Array
  • ArrayBuffer
  • Buffer (node.js)
  • Date
  • Error
  • RegExp
  • Int8Array
  • Uint8Array
  • Uint8ClampedArray
  • Int16Array
  • Uint16Array
  • Int32Array
  • Uint32Array
  • Float32Array
  • Float64Array
  • BigInt64Array
  • BigUint64Array
  • Map
  • Set
  • Object
  • custom Array
  • custom Object

Primtive data types are not deep copied. Instead, their values are copied:

  • Number
  • String
  • Boolean
  • undefined
  • BigInt
  • Symbol
  • null

The following object types are not deep copied, as no way has been found to copy them. They are copied by reference only:

  • Function
  • WeakMap
  • WeakSet

Benchmark

In a standard benchmark test of 14 commonly used deep copy modules, deep-copy-all was 4th fastest.