h-clone
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

h-clone

a simple and morden deep clone tool.

because h-clone use history api to make a structure date copy, so it only support modern brower env. ie10+ maybe?

usage

import clone from 'h-clone'
 
const target = {
    name: 'tom',
    age: 12,
    boy: true,
    info: {
        add: 'xxx'
    }
};
 
const copy = clone(target);

support type

  • All primitive types, however, not symbols
  • Boolean object
  • String object
  • Date
  • RegExp
  • Blob
  • File
  • FileList
  • ArrayBuffer
  • ArrayBufferView
  • ImageBitmap
  • ImageData
  • Array
  • Object
  • Map
  • Set

tips:

  1. The lastIndex field of RegExp objects is not preserved.
  2. Property descriptors, setters, and getters (as well as similar metadata-like features) are not duplicated. For example, if an object is marked read-only using a property descriptor, it will be read-write in the duplicate, since that's the default condition.
  3. The prototype chain does not get walked and duplicated.
  4. Error and Function objects cannot be duplicated by the structured clone algorithm; attempting to do so will throw a DATA_CLONE_ERR exception.
  5. Attempting to clone DOM nodes will likewise throw a DATA_CLONE_ERR exception.

but, most of our use case, it's enough!

lisence

MIT

/h-clone/

    Package Sidebar

    Install

    npm i h-clone

    Weekly Downloads

    0

    Version

    1.0.1

    License

    MIT

    Unpacked Size

    4.11 kB

    Total Files

    9

    Last publish

    Collaborators

    • huangteng