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

deepcopy

v2.1.0

Published

deep copy data

Downloads

1,390,784

Readme

deepcopy.js

test npm version Try deepcopy on RunKit renovate

deep copy data

Installation

npm

$ npm install deepcopy

Usage

node.js

JavaScript

const deepcopy = require('deepcopy');

TypeScript

import * as deepcopy from 'deepcopy';

browser

<script src="deepcopy.min.js"></script>

Example

basic usage:

const src = {
  desserts: [
    { name: 'cake'      },
    { name: 'ice cream' },
    { name: 'pudding'   }
  ]
};

const dist = deepcopy(src);

src.desserts = null;

console.log(src);   // { desserts: null }
console.log(dist);  // { desserts: [ { name: 'cake' }, { name: 'ice cream' }, { name: 'pudding' } ] }

customize deepcopy:

function MyClass(id) {
  this._id = id;
}

const src = {
  myClasses: [
    new MyClass(1),
    new MyClass(2),
    new MyClass(3)
  ]
};

const dest = deepcopy(base, {
  customizer(value) {
    if (target.constructor === MyClass) {
      return new MyClass(target._id);
    }
  }
});

src.myClasses = null;

console.log(src);   // { myClasses: null }
console.log(dest);  // { myClasses: [ MyClass { _id: 1 }, MyClass { _id: 2 }, MyClass { _id: 3 } ] }

Functions

deepcopy(value[, options])

  • value
    • *
      • target value
  • options
    • Object|Function
      • Object - pass options
      • Function - use as customize function
  • return
    • * - copied value

Supported types and copy operation

|type |operation | | |:-----------------|:-----------|:-------------------------| |ArrayBuffer |deep copy | | |Boolean |deep copy | | |Buffer |deep copy |node.js only | |DataView |deep copy | | |Date |deep copy | | |Number |deep copy | | |RegExp |deep copy | | |String |deep copy | | |Float32Array |deep copy | | |Float64Array |deep copy | | |Int16Array |deep copy | | |Int32Array |deep copy | | |Int8Array |deep copy | | |Uint16Array |deep copy | | |Uint32Array |deep copy | | |Uint8Array |deep copy | | |Uint8ClampedArray |deep copy | | |boolean |deep copy | | |null |deep copy | | |number |deep copy | | |string |deep copy | | |symbol |deep copy | | |undefined |deep copy | | |Arguments |deep copy |recursively, copy as Array| |Array |deep copy |recursively | |Map |deep copy |recursively | |Object |deep copy |recursively | |Set |deep copy |recursively | |Array Iterator |shallow copy| | |Map Iterator |shallow copy| | |Promise |shallow copy| | |Set Iterator |shallow copy| | |String Iterator |shallow copy| | |function |shallow copy| | |global |shallow copy|window, global, self, etc.| |WeakMap |shallow copy| | |WeakSet |shallow copy| |

Contributors

License

The MIT license.