h-clone
a simple and morden deep clone tool
Last updated a month ago by huangteng .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install h-clone 
SYNC missed versions from official npm registry.

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

Current Tags

  • 1.0.1                                ...           latest (a month ago)

2 Versions

  • 1.0.1                                ...           a month ago
  • 1.0.0                                ...           a month ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 28
Dependencies (5)
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |