bunshin-clone 1.6.1 → 1.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +16 -2
- package/dist/index.js +16 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -18,6 +18,11 @@ function clone(value, settings, refs) {
|
|
|
18
18
|
return cloneWithDescriptors(value, settings, refs);
|
|
19
19
|
}
|
|
20
20
|
if (Array.isArray(value)) {
|
|
21
|
+
if (isShallowClonableArray(value)) {
|
|
22
|
+
const result2 = value.slice();
|
|
23
|
+
refs.set(value, result2);
|
|
24
|
+
return result2;
|
|
25
|
+
}
|
|
21
26
|
const { length } = value;
|
|
22
27
|
const result = new Array(length);
|
|
23
28
|
refs.set(value, result);
|
|
@@ -30,9 +35,10 @@ function clone(value, settings, refs) {
|
|
|
30
35
|
const result = Object.create(Object.getPrototypeOf(value));
|
|
31
36
|
refs.set(value, result);
|
|
32
37
|
for (const key of Reflect.ownKeys(value)) {
|
|
33
|
-
if (
|
|
34
|
-
|
|
38
|
+
if (isUnsafeKey(key) || !IS_ENUMERABLE.call(value, key)) {
|
|
39
|
+
continue;
|
|
35
40
|
}
|
|
41
|
+
result[key] = clone(value[key], settings, refs);
|
|
36
42
|
}
|
|
37
43
|
return result;
|
|
38
44
|
}
|
|
@@ -203,6 +209,14 @@ function createErrorInstance(error, settings, refs) {
|
|
|
203
209
|
result.name = name;
|
|
204
210
|
return result;
|
|
205
211
|
}
|
|
212
|
+
function isShallowClonableArray(array) {
|
|
213
|
+
for (let i = 0, l = array.length; i < l; i++) {
|
|
214
|
+
if (isObject(array[i])) {
|
|
215
|
+
return false;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return true;
|
|
219
|
+
}
|
|
206
220
|
function forEachOwnKey(object, callback) {
|
|
207
221
|
for (const key of Object.keys(object)) {
|
|
208
222
|
callback(key);
|
package/dist/index.js
CHANGED
|
@@ -16,6 +16,11 @@ function clone(value, settings, refs) {
|
|
|
16
16
|
return cloneWithDescriptors(value, settings, refs);
|
|
17
17
|
}
|
|
18
18
|
if (Array.isArray(value)) {
|
|
19
|
+
if (isShallowClonableArray(value)) {
|
|
20
|
+
const result2 = value.slice();
|
|
21
|
+
refs.set(value, result2);
|
|
22
|
+
return result2;
|
|
23
|
+
}
|
|
19
24
|
const { length } = value;
|
|
20
25
|
const result = new Array(length);
|
|
21
26
|
refs.set(value, result);
|
|
@@ -28,9 +33,10 @@ function clone(value, settings, refs) {
|
|
|
28
33
|
const result = Object.create(Object.getPrototypeOf(value));
|
|
29
34
|
refs.set(value, result);
|
|
30
35
|
for (const key of Reflect.ownKeys(value)) {
|
|
31
|
-
if (
|
|
32
|
-
|
|
36
|
+
if (isUnsafeKey(key) || !IS_ENUMERABLE.call(value, key)) {
|
|
37
|
+
continue;
|
|
33
38
|
}
|
|
39
|
+
result[key] = clone(value[key], settings, refs);
|
|
34
40
|
}
|
|
35
41
|
return result;
|
|
36
42
|
}
|
|
@@ -201,6 +207,14 @@ function createErrorInstance(error, settings, refs) {
|
|
|
201
207
|
result.name = name;
|
|
202
208
|
return result;
|
|
203
209
|
}
|
|
210
|
+
function isShallowClonableArray(array) {
|
|
211
|
+
for (let i = 0, l = array.length; i < l; i++) {
|
|
212
|
+
if (isObject(array[i])) {
|
|
213
|
+
return false;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return true;
|
|
217
|
+
}
|
|
204
218
|
function forEachOwnKey(object, callback) {
|
|
205
219
|
for (const key of Object.keys(object)) {
|
|
206
220
|
callback(key);
|