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