clone-deep
Advanced tools
Comparing version 4.0.0 to 4.0.1
@@ -9,2 +9,3 @@ 'use strict'; | ||
const typeOf = require('kind-of'); | ||
const isPlainObject = require('is-plain-object'); | ||
@@ -27,5 +28,5 @@ function cloneDeep(val, instanceClone) { | ||
} | ||
if (typeOf(val) === 'object') { | ||
if (instanceClone || isPlainObject(val)) { | ||
const res = new val.constructor(); | ||
for (const key in val) { | ||
for (let key in val) { | ||
res[key] = cloneDeep(val[key], instanceClone); | ||
@@ -32,0 +33,0 @@ } |
{ | ||
"name": "clone-deep", | ||
"description": "Recursively (deep) clone JavaScript native types, like Object, Array, RegExp, Date as well as primitives.", | ||
"version": "4.0.0", | ||
"version": "4.0.1", | ||
"homepage": "https://github.com/jonschlinkert/clone-deep", | ||
@@ -17,3 +17,3 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)", | ||
"engines": { | ||
"node": ">=8" | ||
"node": ">=6" | ||
}, | ||
@@ -24,2 +24,3 @@ "scripts": { | ||
"dependencies": { | ||
"is-plain-object": "^2.0.4", | ||
"kind-of": "^6.0.2", | ||
@@ -29,4 +30,4 @@ "shallow-clone": "^3.0.0" | ||
"devDependencies": { | ||
"gulp-format-md": "^1.0.0", | ||
"mocha": "^3.5.3" | ||
"gulp-format-md": "^2.0.0", | ||
"mocha": "^5.2.0" | ||
}, | ||
@@ -44,2 +45,3 @@ "keywords": [ | ||
"clone-deep", | ||
"clone-map", | ||
"clone-object", | ||
@@ -50,2 +52,3 @@ "clone-object-deep", | ||
"clone-regexp", | ||
"clone-set", | ||
"date", | ||
@@ -57,2 +60,4 @@ "deep", | ||
"object", | ||
"regex", | ||
"regexp", | ||
"shallow", | ||
@@ -59,0 +64,0 @@ "symbol" |
@@ -18,15 +18,14 @@ # clone-deep [![NPM version](https://img.shields.io/npm/v/clone-deep.svg?style=flat)](https://www.npmjs.com/package/clone-deep) [![NPM monthly downloads](https://img.shields.io/npm/dm/clone-deep.svg?style=flat)](https://npmjs.org/package/clone-deep) [![NPM total downloads](https://img.shields.io/npm/dt/clone-deep.svg?style=flat)](https://npmjs.org/package/clone-deep) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/clone-deep.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/clone-deep) | ||
```js | ||
var cloneDeep = require('clone-deep'); | ||
const cloneDeep = require('clone-deep'); | ||
var obj = {a: 'b'}; | ||
var arr = [obj]; | ||
var copy = cloneDeep(arr); | ||
let obj = { a: 'b' }; | ||
let arr = [obj]; | ||
let copy = cloneDeep(arr); | ||
obj.c = 'd'; | ||
console.log(copy); | ||
//=> [{a: 'b'}] | ||
//=> [{ a: 'b' }] | ||
console.log(arr); | ||
//=> [{a: 'b', c: 'd'}] | ||
//=> [{ a: 'b', c: 'd' }] | ||
``` | ||
@@ -36,7 +35,9 @@ | ||
The `instanceClone` function is invoked to clone objects that are not "plain" objects (as defined by [isPlainObject](#isPlainObject)`isPlainObject`) if it is provided. If `instanceClone` is not specified, it will not attempt to clone non-plain objects, and will copy the object reference. | ||
The last argument specifies whether or not to clone instances (objects that are from a custom class or are not created by the `Object` constructor. This value may be `true` or the function use for cloning instances. | ||
When an `instanceClone` function is provided, it will be invoked to clone objects that are not "plain" objects (as defined by [isPlainObject](#isPlainObject)`isPlainObject`). If `instanceClone` is not specified, this library will not attempt to clone non-plain objects, and will simply copy the object reference. | ||
## Attribution | ||
Based on [mout's](https://github.com/mout/mout) implementation of deepClone. | ||
Initially based on [mout's](https://github.com/mout/mout) implementation of deepClone. | ||
@@ -85,2 +86,9 @@ ## About | ||
### Contributors | ||
| **Commits** | **Contributor** | | ||
| --- | --- | | ||
| 46 | [jonschlinkert](https://github.com/jonschlinkert) | | ||
| 2 | [yujunlong2000](https://github.com/yujunlong2000) | | ||
### Author | ||
@@ -90,5 +98,5 @@ | ||
* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert) | ||
* [GitHub Profile](https://github.com/jonschlinkert) | ||
* [Twitter Profile](https://twitter.com/jonschlinkert) | ||
* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert) | ||
@@ -102,2 +110,2 @@ ### License | ||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on April 10, 2018._ | ||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on November 21, 2018._ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8000
42
106
3
+ Addedis-plain-object@^2.0.4
+ Addedis-plain-object@2.0.4(transitive)
+ Addedisobject@3.0.1(transitive)