bunshin-clone 1.8.0 → 1.8.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 -16
- package/dist/index.js +7 -16
- package/package.json +4 -1
package/dist/index.cjs
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
// src/index.ts
|
|
4
|
-
|
|
5
|
-
var { hasOwnProperty: HAS_OWN, propertyIsEnumerable: IS_ENUMERABLE } = Object.prototype;
|
|
6
|
-
function bunshinClone(value, options = EMPTY_OPTIONS, refs = /* @__PURE__ */ new WeakMap()) {
|
|
4
|
+
function bunshinClone(value, options = {}, refs = /* @__PURE__ */ new WeakMap()) {
|
|
7
5
|
return clone(value, resolveOptions(options), refs);
|
|
8
6
|
}
|
|
9
7
|
function clone(value, settings, refs) {
|
|
10
8
|
if (!isObject(value)) {
|
|
11
9
|
return value;
|
|
12
10
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return ref;
|
|
11
|
+
if (refs.has(value)) {
|
|
12
|
+
return refs.get(value);
|
|
16
13
|
}
|
|
17
14
|
if (settings.preserveDescriptors && isPlainObject(value)) {
|
|
18
15
|
return cloneWithDescriptors(value, settings, refs);
|
|
@@ -36,14 +33,14 @@ function clone(value, settings, refs) {
|
|
|
36
33
|
refs.set(value, result);
|
|
37
34
|
if (!settings.preserveSymbolKeys) {
|
|
38
35
|
for (const key in value) {
|
|
39
|
-
if (isUnsafeKey(key) || !
|
|
36
|
+
if (isUnsafeKey(key) || !Object.hasOwn(value, key)) {
|
|
40
37
|
continue;
|
|
41
38
|
}
|
|
42
39
|
result[key] = clone(value[key], settings, refs);
|
|
43
40
|
}
|
|
44
41
|
} else {
|
|
45
42
|
for (const key of Reflect.ownKeys(value)) {
|
|
46
|
-
if (isUnsafeKey(key) || !
|
|
43
|
+
if (isUnsafeKey(key) || !Object.propertyIsEnumerable.call(value, key)) {
|
|
47
44
|
continue;
|
|
48
45
|
}
|
|
49
46
|
result[key] = clone(value[key], settings, refs);
|
|
@@ -140,8 +137,7 @@ function clone(value, settings, refs) {
|
|
|
140
137
|
return value;
|
|
141
138
|
}
|
|
142
139
|
function cloneBuffer(buffer, refs) {
|
|
143
|
-
|
|
144
|
-
if (ref !== void 0) {
|
|
140
|
+
if (refs.has(buffer)) {
|
|
145
141
|
return refs.get(buffer);
|
|
146
142
|
}
|
|
147
143
|
const result = buffer.slice(0);
|
|
@@ -237,12 +233,7 @@ function isPlainObject(value) {
|
|
|
237
233
|
return proto === Object.prototype || proto === null;
|
|
238
234
|
}
|
|
239
235
|
function isShallowArray(array) {
|
|
240
|
-
|
|
241
|
-
if (isObject(array[i])) {
|
|
242
|
-
return false;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
return true;
|
|
236
|
+
return array.every((item) => !isObject(item));
|
|
246
237
|
}
|
|
247
238
|
function isUnsafeKey(key) {
|
|
248
239
|
return typeof key === "string" && (key === "__proto__" || key === "prototype" || key === "constructor");
|
package/dist/index.js
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
|
|
3
|
-
var { hasOwnProperty: HAS_OWN, propertyIsEnumerable: IS_ENUMERABLE } = Object.prototype;
|
|
4
|
-
function bunshinClone(value, options = EMPTY_OPTIONS, refs = /* @__PURE__ */ new WeakMap()) {
|
|
2
|
+
function bunshinClone(value, options = {}, refs = /* @__PURE__ */ new WeakMap()) {
|
|
5
3
|
return clone(value, resolveOptions(options), refs);
|
|
6
4
|
}
|
|
7
5
|
function clone(value, settings, refs) {
|
|
8
6
|
if (!isObject(value)) {
|
|
9
7
|
return value;
|
|
10
8
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return ref;
|
|
9
|
+
if (refs.has(value)) {
|
|
10
|
+
return refs.get(value);
|
|
14
11
|
}
|
|
15
12
|
if (settings.preserveDescriptors && isPlainObject(value)) {
|
|
16
13
|
return cloneWithDescriptors(value, settings, refs);
|
|
@@ -34,14 +31,14 @@ function clone(value, settings, refs) {
|
|
|
34
31
|
refs.set(value, result);
|
|
35
32
|
if (!settings.preserveSymbolKeys) {
|
|
36
33
|
for (const key in value) {
|
|
37
|
-
if (isUnsafeKey(key) || !
|
|
34
|
+
if (isUnsafeKey(key) || !Object.hasOwn(value, key)) {
|
|
38
35
|
continue;
|
|
39
36
|
}
|
|
40
37
|
result[key] = clone(value[key], settings, refs);
|
|
41
38
|
}
|
|
42
39
|
} else {
|
|
43
40
|
for (const key of Reflect.ownKeys(value)) {
|
|
44
|
-
if (isUnsafeKey(key) || !
|
|
41
|
+
if (isUnsafeKey(key) || !Object.propertyIsEnumerable.call(value, key)) {
|
|
45
42
|
continue;
|
|
46
43
|
}
|
|
47
44
|
result[key] = clone(value[key], settings, refs);
|
|
@@ -138,8 +135,7 @@ function clone(value, settings, refs) {
|
|
|
138
135
|
return value;
|
|
139
136
|
}
|
|
140
137
|
function cloneBuffer(buffer, refs) {
|
|
141
|
-
|
|
142
|
-
if (ref !== void 0) {
|
|
138
|
+
if (refs.has(buffer)) {
|
|
143
139
|
return refs.get(buffer);
|
|
144
140
|
}
|
|
145
141
|
const result = buffer.slice(0);
|
|
@@ -235,12 +231,7 @@ function isPlainObject(value) {
|
|
|
235
231
|
return proto === Object.prototype || proto === null;
|
|
236
232
|
}
|
|
237
233
|
function isShallowArray(array) {
|
|
238
|
-
|
|
239
|
-
if (isObject(array[i])) {
|
|
240
|
-
return false;
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
return true;
|
|
234
|
+
return array.every((item) => !isObject(item));
|
|
244
235
|
}
|
|
245
236
|
function isUnsafeKey(key) {
|
|
246
237
|
return typeof key === "string" && (key === "__proto__" || key === "prototype" || key === "constructor");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bunshin-clone",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.1",
|
|
4
4
|
"description": "High-performance deep clone utility with descriptor support",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"array",
|
|
@@ -73,5 +73,8 @@
|
|
|
73
73
|
},
|
|
74
74
|
"allowScripts": {
|
|
75
75
|
"esbuild": true
|
|
76
|
+
},
|
|
77
|
+
"dependencies": {
|
|
78
|
+
"bunshin-clone-npm": "npm:bunshin-clone@^1.8.0"
|
|
76
79
|
}
|
|
77
80
|
}
|