bunshin-clone 1.6.0 → 1.6.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 +7 -4
- package/dist/index.js +7 -4
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
// src/index.ts
|
|
4
4
|
var EMPTY_OPTIONS = {};
|
|
5
|
+
var { propertyIsEnumerable: IS_ENUMERABLE } = Object.prototype;
|
|
5
6
|
function bunshinClone(value, options = EMPTY_OPTIONS, refs = /* @__PURE__ */ new WeakMap()) {
|
|
6
7
|
return clone(value, resolveOptions(options), refs);
|
|
7
8
|
}
|
|
@@ -9,8 +10,9 @@ function clone(value, settings, refs) {
|
|
|
9
10
|
if (!isObject(value)) {
|
|
10
11
|
return value;
|
|
11
12
|
}
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
const ref = refs.get(value);
|
|
14
|
+
if (ref !== void 0) {
|
|
15
|
+
return ref;
|
|
14
16
|
}
|
|
15
17
|
if (settings.preserveDescriptors && isPlainObject(value)) {
|
|
16
18
|
return cloneWithDescriptors(value, settings, refs);
|
|
@@ -28,7 +30,7 @@ function clone(value, settings, refs) {
|
|
|
28
30
|
const result = Object.create(Object.getPrototypeOf(value));
|
|
29
31
|
refs.set(value, result);
|
|
30
32
|
for (const key of Reflect.ownKeys(value)) {
|
|
31
|
-
if (!isUnsafeKey(key) &&
|
|
33
|
+
if (!isUnsafeKey(key) && IS_ENUMERABLE.call(value, key)) {
|
|
32
34
|
result[key] = clone(value[key], settings, refs);
|
|
33
35
|
}
|
|
34
36
|
}
|
|
@@ -123,7 +125,8 @@ function clone(value, settings, refs) {
|
|
|
123
125
|
return value;
|
|
124
126
|
}
|
|
125
127
|
function cloneBuffer(buffer, refs) {
|
|
126
|
-
|
|
128
|
+
const ref = refs.get(buffer);
|
|
129
|
+
if (ref !== void 0) {
|
|
127
130
|
return refs.get(buffer);
|
|
128
131
|
}
|
|
129
132
|
const result = buffer.slice(0);
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
var EMPTY_OPTIONS = {};
|
|
3
|
+
var { propertyIsEnumerable: IS_ENUMERABLE } = Object.prototype;
|
|
3
4
|
function bunshinClone(value, options = EMPTY_OPTIONS, refs = /* @__PURE__ */ new WeakMap()) {
|
|
4
5
|
return clone(value, resolveOptions(options), refs);
|
|
5
6
|
}
|
|
@@ -7,8 +8,9 @@ function clone(value, settings, refs) {
|
|
|
7
8
|
if (!isObject(value)) {
|
|
8
9
|
return value;
|
|
9
10
|
}
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
const ref = refs.get(value);
|
|
12
|
+
if (ref !== void 0) {
|
|
13
|
+
return ref;
|
|
12
14
|
}
|
|
13
15
|
if (settings.preserveDescriptors && isPlainObject(value)) {
|
|
14
16
|
return cloneWithDescriptors(value, settings, refs);
|
|
@@ -26,7 +28,7 @@ function clone(value, settings, refs) {
|
|
|
26
28
|
const result = Object.create(Object.getPrototypeOf(value));
|
|
27
29
|
refs.set(value, result);
|
|
28
30
|
for (const key of Reflect.ownKeys(value)) {
|
|
29
|
-
if (!isUnsafeKey(key) &&
|
|
31
|
+
if (!isUnsafeKey(key) && IS_ENUMERABLE.call(value, key)) {
|
|
30
32
|
result[key] = clone(value[key], settings, refs);
|
|
31
33
|
}
|
|
32
34
|
}
|
|
@@ -121,7 +123,8 @@ function clone(value, settings, refs) {
|
|
|
121
123
|
return value;
|
|
122
124
|
}
|
|
123
125
|
function cloneBuffer(buffer, refs) {
|
|
124
|
-
|
|
126
|
+
const ref = refs.get(buffer);
|
|
127
|
+
if (ref !== void 0) {
|
|
125
128
|
return refs.get(buffer);
|
|
126
129
|
}
|
|
127
130
|
const result = buffer.slice(0);
|