clone-deep
Advanced tools
Comparing version 3.0.1 to 4.0.0
38
index.js
@@ -7,11 +7,5 @@ 'use strict'; | ||
var isObject = require('is-plain-object'); | ||
var clone = require('shallow-clone'); | ||
var typeOf = require('kind-of'); | ||
var forOwn = require('for-own'); | ||
const clone = require('shallow-clone'); | ||
const typeOf = require('kind-of'); | ||
/** | ||
* Recursively clone native types. | ||
*/ | ||
function cloneDeep(val, instanceClone) { | ||
@@ -29,20 +23,20 @@ switch (typeOf(val)) { | ||
function cloneObjectDeep(obj, instanceClone) { | ||
if (isObject(obj) || (instanceClone === true && typeOf(obj) === 'object')) { | ||
var res = {}; | ||
forOwn(obj, function(val, key) { | ||
this[key] = cloneDeep(val, instanceClone); | ||
}, res); | ||
function cloneObjectDeep(val, instanceClone) { | ||
if (typeof instanceClone === 'function') { | ||
return instanceClone(val); | ||
} | ||
if (typeOf(val) === 'object') { | ||
const res = new val.constructor(); | ||
for (const key in val) { | ||
res[key] = cloneDeep(val[key], instanceClone); | ||
} | ||
return res; | ||
} | ||
if (typeof instanceClone === 'function') { | ||
return instanceClone(obj); | ||
} | ||
return obj; | ||
return val; | ||
} | ||
function cloneArrayDeep(arr, instanceClone) { | ||
var res = []; | ||
for (var i = 0; i < arr.length; i++) { | ||
res[i] = cloneDeep(arr[i], instanceClone); | ||
function cloneArrayDeep(val, instanceClone) { | ||
const res = new val.constructor(val.length); | ||
for (let i = 0; i < val.length; i++) { | ||
res[i] = cloneDeep(val[i], instanceClone); | ||
} | ||
@@ -49,0 +43,0 @@ return res; |
{ | ||
"name": "clone-deep", | ||
"description": "Recursively (deep) clone JavaScript native types, like Object, Array, RegExp, Date as well as primitives.", | ||
"version": "3.0.1", | ||
"version": "4.0.0", | ||
"homepage": "https://github.com/jonschlinkert/clone-deep", | ||
@@ -23,6 +23,4 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)", | ||
"dependencies": { | ||
"for-own": "^1.0.0", | ||
"is-plain-object": "^2.0.4", | ||
"kind-of": "^6.0.2", | ||
"shallow-clone": "^2.0.2" | ||
"shallow-clone": "^3.0.0" | ||
}, | ||
@@ -36,5 +34,8 @@ "devDependencies": { | ||
"assign", | ||
"buffer", | ||
"clamped", | ||
"clone", | ||
"clone-array", | ||
"clone-array-deep", | ||
"clone-buffer", | ||
"clone-date", | ||
@@ -54,4 +55,3 @@ "clone-deep", | ||
"shallow", | ||
"util", | ||
"utility" | ||
"symbol" | ||
], | ||
@@ -58,0 +58,0 @@ "verb": { |
@@ -61,3 +61,2 @@ # 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) | ||
<details> | ||
@@ -83,3 +82,3 @@ <summary><strong>Building docs</strong></summary> | ||
* [kind-of](https://www.npmjs.com/package/kind-of): Get the native type of a value. | [homepage](https://github.com/jonschlinkert/kind-of "Get the native type of a value.") | ||
* [shallow-clone](https://www.npmjs.com/package/shallow-clone): Make a shallow clone of an object, array or primitive. | [homepage](https://github.com/jonschlinkert/shallow-clone "Make a shallow clone of an object, array or primitive.") | ||
* [shallow-clone](https://www.npmjs.com/package/shallow-clone): Creates a shallow clone of any JavaScript value. | [homepage](https://github.com/jonschlinkert/shallow-clone "Creates a shallow clone of any JavaScript value.") | ||
@@ -90,5 +89,5 @@ ### Author | ||
* [linkedin/in/jonschlinkert](https://linkedin.com/in/jonschlinkert) | ||
* [github/jonschlinkert](https://github.com/jonschlinkert) | ||
* [twitter/jonschlinkert](https://twitter.com/jonschlinkert) | ||
* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert) | ||
* [GitHub Profile](https://github.com/jonschlinkert) | ||
* [Twitter Profile](https://twitter.com/jonschlinkert) | ||
@@ -102,2 +101,2 @@ ### License | ||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on January 19, 2018._ | ||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on April 10, 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
2
7393
41
98
+ Addedshallow-clone@3.0.1(transitive)
- Removedfor-own@^1.0.0
- Removedis-plain-object@^2.0.4
- Removedfor-in@1.0.2(transitive)
- Removedfor-own@1.0.0(transitive)
- Removedis-extendable@1.0.1(transitive)
- Removedis-plain-object@2.0.4(transitive)
- Removedisobject@3.0.1(transitive)
- Removedmixin-object@3.0.0(transitive)
- Removedshallow-clone@2.0.2(transitive)
Updatedshallow-clone@^3.0.0