deep-copy-ts
TypeScript icon, indicating that this package has built-in type declarations

0.5.4 • Public • Published

NPM Build Status

deep-copy-ts

A deep-copy (a.k.a. clone) utility function for TypeScript, based on ts-deepcopy. Explore it in CodeSandbox.

Installation

npm i deep-copy-ts

Usage

import { deepCopy } from "deep-copy-ts";

const obj = {
  // Primitive value
  a: 1,
  b: "b",
  c: {
    a: [{ a: "caa1" }, { a: "caa2" }],
  },
  d: null,
  e: undefined,
  f: true,
  // Reference value
  g: [1, 2, 3],
  h: () => {
    return "h";
  },
  i: {
    a: 1,
    b: "i.b",
    c: "",
    d: null,
    e: undefined,
    f: true,
    g: [1, 2, 3],
    h: () => {
      return "i.h";
    },
    i: { a: 1 },
  },
  j: new Date(),
  k: new DataView(new ArrayBuffer(16), 0),
  l: new RegExp("ab+c", "i"),
  m: new ArrayBuffer(16),
  n: new Float32Array(new ArrayBuffer(16), 0),
  o: new Float64Array(new ArrayBuffer(16), 0),
  p: new Int8Array(new ArrayBuffer(16), 0),
  q: new Int16Array(new ArrayBuffer(16), 0),
  r: new Int32Array(new ArrayBuffer(16), 0),
  s: new Uint8Array(new ArrayBuffer(16), 0),
  t: new Uint16Array(new ArrayBuffer(16), 0),
  u: new Uint32Array(new ArrayBuffer(16), 0),
  v: new Uint8ClampedArray(new ArrayBuffer(16), 0),
  // not supported in Safari yet
  w: new BigInt64Array(new ArrayBuffer(16), 0),
  x: new BigUint64Array(new ArrayBuffer(16), 0),
};

const obj2 = deepCopy(obj);
console.log("obj2: " + JSON.stringify(obj2, null, 2));
console.log("obj2.h: " + obj2.h);

Developing

npm i
npm start

Publishing

npm run dry-run       # To check all files that will be send to npm
npm run patch-release # or minor-release/major-release

Readme

Keywords

none

Package Sidebar

Install

npm i deep-copy-ts

Weekly Downloads

2,746

Version

0.5.4

License

MIT

Unpacked Size

15 kB

Total Files

20

Last publish

Collaborators

  • erikvullings