Comparing version 0.10.33 to 0.10.34
@@ -5,2 +5,12 @@ # Change Log | ||
<a name="0.10.34"></a> | ||
## [0.10.34](https://github.com/medikoo/es5-ext/compare/v0.10.33...v0.10.34) (2017-10-13) | ||
### Features | ||
* **copyDeep:** duplicate only recursive instances ([bba529a](https://github.com/medikoo/es5-ext/commit/bba529a)) | ||
<a name="0.10.33"></a> | ||
@@ -7,0 +17,0 @@ ## [0.10.33](https://github.com/medikoo/es5-ext/compare/v0.10.32...v0.10.33) (2017-10-13) |
@@ -6,32 +6,29 @@ "use strict"; | ||
, ensureValue = require("./valid-value") | ||
, isArray = Array.isArray | ||
, copy | ||
, copyItem; | ||
, isArray = Array.isArray; | ||
copyItem = function (value) { | ||
var index; | ||
if (!isPlainObject(value) && !isArray(value)) return value; | ||
index = this[0].indexOf(value); | ||
if (index === -1) return copy.call(this, value); | ||
return this[1][index]; | ||
}; | ||
var copyValue = function (value, ancestors, ancestorsCopy) { | ||
var mode; | ||
if (isPlainObject(value)) mode = "object"; | ||
else if (isArray(value)) mode = "array"; | ||
if (!mode) return value; | ||
copy = function (source) { | ||
var target = isArray(source) ? [] : {}; | ||
this[0].push(source); | ||
this[1].push(target); | ||
if (isArray(source)) { | ||
source.forEach(function (value, key) { | ||
target[key] = copyItem.call(this, value, key); | ||
}, this); | ||
var copy = ancestorsCopy[ancestors.indexOf(value)]; | ||
if (copy) return copy; | ||
copy = mode === "object" ? {} : []; | ||
ancestors.push(value); | ||
ancestorsCopy.push(copy); | ||
if (mode === "object") { | ||
forEach(value, function (item, key) { | ||
copy[key] = copyValue(item, ancestors, ancestorsCopy); | ||
}); | ||
} else { | ||
forEach( | ||
source, | ||
function (value, key) { | ||
target[key] = copyItem.call(this, value, key); | ||
}, | ||
this | ||
); | ||
value.forEach(function (item, index) { | ||
copy[index] = copyValue(item, ancestors, ancestorsCopy); | ||
}); | ||
} | ||
return target; | ||
ancestors.pop(); | ||
ancestorsCopy.pop(); | ||
return copy; | ||
}; | ||
@@ -42,3 +39,3 @@ | ||
if (obj !== source) return obj; | ||
return copy.call([[], []], obj); | ||
return copyValue(obj, [], []); | ||
}; |
{ | ||
"name": "es5-ext", | ||
"version": "0.10.33", | ||
"version": "0.10.34", | ||
"description": "ECMAScript extensions and shims", | ||
@@ -5,0 +5,0 @@ "author": "Mariusz Nowak <medyk@medikoo.com> (http://www.medikoo.com/)", |
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
507410
15747