JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q38449F

Reliably and recursively clone javascript objects

Package Exports

  • lutils-clone

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (lutils-clone) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

clone lutils-clone

Reliably and recursively clone javascript objects

npm install lutils-clone

API

clone([mixed], [[options]])

Clones an object, recursively.

import clone from 'lutils-clone'

const test = new class Test {}

const obj = {
    a  : { b: 2 },
    fn : function() {}
    test,
}

const newObj = clone(obj)

newObj.a.b = 5        // 5
obj.a.b               // 2
newObj.a === obj.a    // false
newObj.test === test  // false
newObj.test.__proto__ === test.__proto__ // true
newObj.fn === obj.fn  // true

Advanced usage

Options

{
    // Decremented with each recursion for each nested object, halting the clone at 0
    // A halted clone will preserve references to any remaining values
    depth: 8,

    // Determines whether recursing will occur. When this type matches, it will be iterated over.
    types: { object: true, array: true }
    types: [ "object", "array" ] // Can also be an array of type strings
}