bunshin-clone 1.0.11 → 1.0.13
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/README.md +29 -24
- package/dist/index.cjs +37 -37
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +37 -37
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Bunshin Clone
|
|
2
2
|
|
|
3
|
-
High-performance deep clone utility with descriptor support.
|
|
3
|
+
High-performance deep clone utility with descriptor support. Handles circular ref and complex built-in types.
|
|
4
4
|
|
|
5
5
|
* Fast (no unnecessary overhead)
|
|
6
6
|
* Deep clone (no structural sharing)
|
|
@@ -20,39 +20,30 @@ npm i bunshin-clone
|
|
|
20
20
|
// npm
|
|
21
21
|
import bunshinClone from 'bunshin-clone';
|
|
22
22
|
|
|
23
|
-
//
|
|
23
|
+
// CDNs
|
|
24
|
+
import bunshinClone from 'https://esm.sh/bunshin-clone'
|
|
25
|
+
// or
|
|
24
26
|
import bunshinClone from 'https://cdn.jsdelivr.net/npm/bunshin-clone/+esm';
|
|
27
|
+
// or
|
|
28
|
+
import bunshinClone from 'https://unpkg.com/bunshin-clone/dist/index.js';
|
|
25
29
|
```
|
|
26
30
|
|
|
27
31
|
## Usage
|
|
28
32
|
|
|
29
33
|
```ts
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
console.log(result);
|
|
37
|
-
// { foo: 1, nested: { x: 1 } }
|
|
38
|
-
|
|
39
|
-
console.log(result === source); // false
|
|
40
|
-
console.log(result.nested === source.nested); // false
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
## API
|
|
44
|
-
|
|
45
|
-
```ts
|
|
46
|
-
bunshinClone(target)
|
|
47
|
-
bunshinClone(target, options)
|
|
34
|
+
bunshinClone(source, options);
|
|
35
|
+
// => T
|
|
36
|
+
//
|
|
37
|
+
// source: T
|
|
38
|
+
// options (optional): BunshinCloneOptions
|
|
48
39
|
```
|
|
49
40
|
|
|
50
|
-
|
|
41
|
+
### 🪄 Options
|
|
51
42
|
|
|
52
43
|
```ts
|
|
53
|
-
BunshinCloneOptions {
|
|
54
|
-
preserveDescriptors: false
|
|
55
|
-
strictDescriptors: false
|
|
44
|
+
interface BunshinCloneOptions {
|
|
45
|
+
preserveDescriptors?: boolean; // (default: false)
|
|
46
|
+
strictDescriptors?: boolean; // (default: false)
|
|
56
47
|
}
|
|
57
48
|
```
|
|
58
49
|
|
|
@@ -96,6 +87,20 @@ bunshinClone(obj, { strictDescriptors: true });
|
|
|
96
87
|
|
|
97
88
|
---
|
|
98
89
|
|
|
90
|
+
## Example
|
|
91
|
+
|
|
92
|
+
```ts
|
|
93
|
+
const source = { foo: 1, nested: { x: 1 } };
|
|
94
|
+
|
|
95
|
+
const result = bunshinClone(source);
|
|
96
|
+
|
|
97
|
+
console.log(result);
|
|
98
|
+
// { foo: 1, nested: { x: 1 } }
|
|
99
|
+
|
|
100
|
+
console.log(result === source); // false
|
|
101
|
+
console.log(result.nested === source.nested); // false
|
|
102
|
+
```
|
|
103
|
+
|
|
99
104
|
## Supported Types
|
|
100
105
|
|
|
101
106
|
bunshin-clone correctly handles:
|
package/dist/index.cjs
CHANGED
|
@@ -6,89 +6,89 @@ var { hasOwnProperty: HAS_OWN } = Object.prototype;
|
|
|
6
6
|
function bunshinClone(source, options) {
|
|
7
7
|
return clone(source, options ?? EMPTY_OPTIONS, /* @__PURE__ */ new WeakMap());
|
|
8
8
|
}
|
|
9
|
-
function clone(node, options,
|
|
9
|
+
function clone(node, options, refs) {
|
|
10
10
|
if (!isObject(node)) {
|
|
11
11
|
return node;
|
|
12
12
|
}
|
|
13
|
-
const
|
|
14
|
-
if (
|
|
15
|
-
return
|
|
13
|
+
const ref = refs.get(node);
|
|
14
|
+
if (ref !== void 0) {
|
|
15
|
+
return ref;
|
|
16
16
|
}
|
|
17
17
|
if (options.preserveDescriptors && isPlainObject(node)) {
|
|
18
|
-
return cloneWithDescriptors(node, options,
|
|
18
|
+
return cloneWithDescriptors(node, options, refs);
|
|
19
19
|
}
|
|
20
20
|
if (Array.isArray(node)) {
|
|
21
21
|
const result = [];
|
|
22
|
-
|
|
22
|
+
refs.set(node, result);
|
|
23
23
|
for (let i = 0, l = node.length; i < l; i++) {
|
|
24
|
-
result[i] = clone(node[i], options,
|
|
24
|
+
result[i] = clone(node[i], options, refs);
|
|
25
25
|
}
|
|
26
26
|
return result;
|
|
27
27
|
}
|
|
28
28
|
if (isPlainObject(node)) {
|
|
29
29
|
const result = Object.create(Object.getPrototypeOf(node));
|
|
30
|
-
|
|
30
|
+
refs.set(node, result);
|
|
31
31
|
for (const key in node) {
|
|
32
32
|
if (!HAS_OWN.call(node, key) || isUnsafeKey(key)) {
|
|
33
33
|
continue;
|
|
34
34
|
}
|
|
35
|
-
result[key] = clone(node[key], options,
|
|
35
|
+
result[key] = clone(node[key], options, refs);
|
|
36
36
|
}
|
|
37
37
|
return result;
|
|
38
38
|
}
|
|
39
39
|
if (node instanceof Map) {
|
|
40
40
|
const result = /* @__PURE__ */ new Map();
|
|
41
|
-
|
|
41
|
+
refs.set(node, result);
|
|
42
42
|
for (const [key, value] of node) {
|
|
43
|
-
result.set(clone(key, options,
|
|
43
|
+
result.set(clone(key, options, refs), clone(value, options, refs));
|
|
44
44
|
}
|
|
45
45
|
return result;
|
|
46
46
|
}
|
|
47
47
|
if (node instanceof Set) {
|
|
48
48
|
const result = /* @__PURE__ */ new Set();
|
|
49
|
-
|
|
49
|
+
refs.set(node, result);
|
|
50
50
|
for (const item of node) {
|
|
51
|
-
result.add(clone(item, options,
|
|
51
|
+
result.add(clone(item, options, refs));
|
|
52
52
|
}
|
|
53
53
|
return result;
|
|
54
54
|
}
|
|
55
55
|
if (node instanceof Date) {
|
|
56
56
|
const result = new Date(node.getTime());
|
|
57
|
-
|
|
57
|
+
refs.set(node, result);
|
|
58
58
|
return result;
|
|
59
59
|
}
|
|
60
60
|
if (node instanceof RegExp) {
|
|
61
61
|
const result = new RegExp(node.source, node.flags);
|
|
62
|
-
|
|
62
|
+
refs.set(node, result);
|
|
63
63
|
result.lastIndex = node.lastIndex;
|
|
64
64
|
return result;
|
|
65
65
|
}
|
|
66
66
|
if (node instanceof ArrayBuffer) {
|
|
67
67
|
const result = node.slice(0);
|
|
68
|
-
|
|
68
|
+
refs.set(node, result);
|
|
69
69
|
return result;
|
|
70
70
|
}
|
|
71
71
|
if (ArrayBuffer.isView(node)) {
|
|
72
72
|
const { buffer, byteOffset, byteLength } = node;
|
|
73
73
|
if (node instanceof DataView) {
|
|
74
74
|
const result = new DataView(buffer.slice(0), byteOffset, byteLength);
|
|
75
|
-
|
|
75
|
+
refs.set(node, result);
|
|
76
76
|
return result;
|
|
77
77
|
} else {
|
|
78
78
|
const Ctor = node.constructor;
|
|
79
79
|
const result = new Ctor(
|
|
80
80
|
buffer.slice(byteOffset, byteOffset + byteLength)
|
|
81
81
|
);
|
|
82
|
-
|
|
82
|
+
refs.set(node, result);
|
|
83
83
|
return result;
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
if (node instanceof Error || typeof DOMException !== "undefined" && node instanceof DOMException) {
|
|
87
|
-
return cloneError(node, options,
|
|
87
|
+
return cloneError(node, options, refs);
|
|
88
88
|
}
|
|
89
89
|
if (typeof Blob !== "undefined" && node instanceof Blob) {
|
|
90
90
|
const result = node.slice(0, node.size, node.type);
|
|
91
|
-
|
|
91
|
+
refs.set(node, result);
|
|
92
92
|
return result;
|
|
93
93
|
}
|
|
94
94
|
if (typeof ImageData !== "undefined" && node instanceof ImageData) {
|
|
@@ -97,29 +97,29 @@ function clone(node, options, ref) {
|
|
|
97
97
|
node.width,
|
|
98
98
|
node.height
|
|
99
99
|
);
|
|
100
|
-
|
|
100
|
+
refs.set(node, result);
|
|
101
101
|
return result;
|
|
102
102
|
}
|
|
103
103
|
if (typeof URL !== "undefined" && node instanceof URL) {
|
|
104
104
|
const result = new URL(node.href);
|
|
105
|
-
|
|
105
|
+
refs.set(node, result);
|
|
106
106
|
return result;
|
|
107
107
|
}
|
|
108
108
|
if (typeof URLSearchParams !== "undefined" && node instanceof URLSearchParams) {
|
|
109
109
|
const result = new URLSearchParams();
|
|
110
|
-
|
|
110
|
+
refs.set(node, result);
|
|
111
111
|
for (const [key, value] of node) {
|
|
112
112
|
result.append(key, value);
|
|
113
113
|
}
|
|
114
114
|
return result;
|
|
115
115
|
}
|
|
116
|
-
|
|
116
|
+
refs.set(node, node);
|
|
117
117
|
return node;
|
|
118
118
|
}
|
|
119
|
-
function cloneError(value, options,
|
|
119
|
+
function cloneError(value, options, refs) {
|
|
120
120
|
if (value instanceof DOMException) {
|
|
121
121
|
const result2 = new DOMException(value.message, value.name);
|
|
122
|
-
|
|
122
|
+
refs.set(value, result2);
|
|
123
123
|
return result2;
|
|
124
124
|
}
|
|
125
125
|
const name = value.name || "Error";
|
|
@@ -148,7 +148,7 @@ function cloneError(value, options, ref) {
|
|
|
148
148
|
result = new Error(message);
|
|
149
149
|
result.name = name;
|
|
150
150
|
}
|
|
151
|
-
|
|
151
|
+
refs.set(value, result);
|
|
152
152
|
if (value.stack) {
|
|
153
153
|
try {
|
|
154
154
|
result.stack = value.stack;
|
|
@@ -156,16 +156,16 @@ function cloneError(value, options, ref) {
|
|
|
156
156
|
}
|
|
157
157
|
}
|
|
158
158
|
if ("cause" in value && value.cause !== void 0) {
|
|
159
|
-
result.cause = clone(value.cause, options,
|
|
159
|
+
result.cause = clone(value.cause, options, refs);
|
|
160
160
|
}
|
|
161
161
|
for (const key of Object.keys(value)) {
|
|
162
|
-
result[key] = clone(value[key], options,
|
|
162
|
+
result[key] = clone(value[key], options, refs);
|
|
163
163
|
}
|
|
164
164
|
return result;
|
|
165
165
|
}
|
|
166
|
-
function cloneWithDescriptors(node, options,
|
|
166
|
+
function cloneWithDescriptors(node, options, refs) {
|
|
167
167
|
const result = Object.create(Object.getPrototypeOf(node));
|
|
168
|
-
|
|
168
|
+
refs.set(node, result);
|
|
169
169
|
const descs = Object.getOwnPropertyDescriptors(node);
|
|
170
170
|
forEachOwnKey(descs, (key) => {
|
|
171
171
|
if (isUnsafeKey(key)) {
|
|
@@ -173,7 +173,7 @@ function cloneWithDescriptors(node, options, ref) {
|
|
|
173
173
|
}
|
|
174
174
|
const desc = { ...descs[key] };
|
|
175
175
|
if ("value" in desc) {
|
|
176
|
-
desc.value = clone(desc.value, options,
|
|
176
|
+
desc.value = clone(desc.value, options, refs);
|
|
177
177
|
}
|
|
178
178
|
try {
|
|
179
179
|
Object.defineProperty(result, key, desc);
|
|
@@ -185,13 +185,13 @@ function cloneWithDescriptors(node, options, ref) {
|
|
|
185
185
|
});
|
|
186
186
|
return result;
|
|
187
187
|
}
|
|
188
|
-
function forEachOwnKey(object,
|
|
188
|
+
function forEachOwnKey(object, fn) {
|
|
189
189
|
for (const key of Object.keys(object)) {
|
|
190
|
-
|
|
190
|
+
fn(key);
|
|
191
191
|
}
|
|
192
192
|
const symbols = Object.getOwnPropertySymbols(object);
|
|
193
193
|
for (let i = 0, l = symbols.length; i < l; i++) {
|
|
194
|
-
|
|
194
|
+
fn(symbols[i]);
|
|
195
195
|
}
|
|
196
196
|
}
|
|
197
197
|
function isObject(value) {
|
|
@@ -210,9 +210,9 @@ function isUnsafeKey(key) {
|
|
|
210
210
|
/**
|
|
211
211
|
* Bunshin Clone
|
|
212
212
|
* High-performance deep clone utility with descriptor support.
|
|
213
|
-
*
|
|
213
|
+
* Handles circular ref and complex built-in types.
|
|
214
214
|
*
|
|
215
|
-
* @version 1.0.
|
|
215
|
+
* @version 1.0.13
|
|
216
216
|
* @author Yusuke Kamiyamane
|
|
217
217
|
* @license MIT
|
|
218
218
|
* @copyright Copyright (c) 2026 Yusuke Kamiyamane
|
package/dist/index.d.cts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Bunshin Clone
|
|
3
3
|
* High-performance deep clone utility with descriptor support.
|
|
4
|
-
*
|
|
4
|
+
* Handles circular ref and complex built-in types.
|
|
5
5
|
*
|
|
6
|
-
* @version 1.0.
|
|
6
|
+
* @version 1.0.13
|
|
7
7
|
* @author Yusuke Kamiyamane
|
|
8
8
|
* @license MIT
|
|
9
9
|
* @copyright Copyright (c) 2026 Yusuke Kamiyamane
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Bunshin Clone
|
|
3
3
|
* High-performance deep clone utility with descriptor support.
|
|
4
|
-
*
|
|
4
|
+
* Handles circular ref and complex built-in types.
|
|
5
5
|
*
|
|
6
|
-
* @version 1.0.
|
|
6
|
+
* @version 1.0.13
|
|
7
7
|
* @author Yusuke Kamiyamane
|
|
8
8
|
* @license MIT
|
|
9
9
|
* @copyright Copyright (c) 2026 Yusuke Kamiyamane
|
package/dist/index.js
CHANGED
|
@@ -4,89 +4,89 @@ var { hasOwnProperty: HAS_OWN } = Object.prototype;
|
|
|
4
4
|
function bunshinClone(source, options) {
|
|
5
5
|
return clone(source, options ?? EMPTY_OPTIONS, /* @__PURE__ */ new WeakMap());
|
|
6
6
|
}
|
|
7
|
-
function clone(node, options,
|
|
7
|
+
function clone(node, options, refs) {
|
|
8
8
|
if (!isObject(node)) {
|
|
9
9
|
return node;
|
|
10
10
|
}
|
|
11
|
-
const
|
|
12
|
-
if (
|
|
13
|
-
return
|
|
11
|
+
const ref = refs.get(node);
|
|
12
|
+
if (ref !== void 0) {
|
|
13
|
+
return ref;
|
|
14
14
|
}
|
|
15
15
|
if (options.preserveDescriptors && isPlainObject(node)) {
|
|
16
|
-
return cloneWithDescriptors(node, options,
|
|
16
|
+
return cloneWithDescriptors(node, options, refs);
|
|
17
17
|
}
|
|
18
18
|
if (Array.isArray(node)) {
|
|
19
19
|
const result = [];
|
|
20
|
-
|
|
20
|
+
refs.set(node, result);
|
|
21
21
|
for (let i = 0, l = node.length; i < l; i++) {
|
|
22
|
-
result[i] = clone(node[i], options,
|
|
22
|
+
result[i] = clone(node[i], options, refs);
|
|
23
23
|
}
|
|
24
24
|
return result;
|
|
25
25
|
}
|
|
26
26
|
if (isPlainObject(node)) {
|
|
27
27
|
const result = Object.create(Object.getPrototypeOf(node));
|
|
28
|
-
|
|
28
|
+
refs.set(node, result);
|
|
29
29
|
for (const key in node) {
|
|
30
30
|
if (!HAS_OWN.call(node, key) || isUnsafeKey(key)) {
|
|
31
31
|
continue;
|
|
32
32
|
}
|
|
33
|
-
result[key] = clone(node[key], options,
|
|
33
|
+
result[key] = clone(node[key], options, refs);
|
|
34
34
|
}
|
|
35
35
|
return result;
|
|
36
36
|
}
|
|
37
37
|
if (node instanceof Map) {
|
|
38
38
|
const result = /* @__PURE__ */ new Map();
|
|
39
|
-
|
|
39
|
+
refs.set(node, result);
|
|
40
40
|
for (const [key, value] of node) {
|
|
41
|
-
result.set(clone(key, options,
|
|
41
|
+
result.set(clone(key, options, refs), clone(value, options, refs));
|
|
42
42
|
}
|
|
43
43
|
return result;
|
|
44
44
|
}
|
|
45
45
|
if (node instanceof Set) {
|
|
46
46
|
const result = /* @__PURE__ */ new Set();
|
|
47
|
-
|
|
47
|
+
refs.set(node, result);
|
|
48
48
|
for (const item of node) {
|
|
49
|
-
result.add(clone(item, options,
|
|
49
|
+
result.add(clone(item, options, refs));
|
|
50
50
|
}
|
|
51
51
|
return result;
|
|
52
52
|
}
|
|
53
53
|
if (node instanceof Date) {
|
|
54
54
|
const result = new Date(node.getTime());
|
|
55
|
-
|
|
55
|
+
refs.set(node, result);
|
|
56
56
|
return result;
|
|
57
57
|
}
|
|
58
58
|
if (node instanceof RegExp) {
|
|
59
59
|
const result = new RegExp(node.source, node.flags);
|
|
60
|
-
|
|
60
|
+
refs.set(node, result);
|
|
61
61
|
result.lastIndex = node.lastIndex;
|
|
62
62
|
return result;
|
|
63
63
|
}
|
|
64
64
|
if (node instanceof ArrayBuffer) {
|
|
65
65
|
const result = node.slice(0);
|
|
66
|
-
|
|
66
|
+
refs.set(node, result);
|
|
67
67
|
return result;
|
|
68
68
|
}
|
|
69
69
|
if (ArrayBuffer.isView(node)) {
|
|
70
70
|
const { buffer, byteOffset, byteLength } = node;
|
|
71
71
|
if (node instanceof DataView) {
|
|
72
72
|
const result = new DataView(buffer.slice(0), byteOffset, byteLength);
|
|
73
|
-
|
|
73
|
+
refs.set(node, result);
|
|
74
74
|
return result;
|
|
75
75
|
} else {
|
|
76
76
|
const Ctor = node.constructor;
|
|
77
77
|
const result = new Ctor(
|
|
78
78
|
buffer.slice(byteOffset, byteOffset + byteLength)
|
|
79
79
|
);
|
|
80
|
-
|
|
80
|
+
refs.set(node, result);
|
|
81
81
|
return result;
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
if (node instanceof Error || typeof DOMException !== "undefined" && node instanceof DOMException) {
|
|
85
|
-
return cloneError(node, options,
|
|
85
|
+
return cloneError(node, options, refs);
|
|
86
86
|
}
|
|
87
87
|
if (typeof Blob !== "undefined" && node instanceof Blob) {
|
|
88
88
|
const result = node.slice(0, node.size, node.type);
|
|
89
|
-
|
|
89
|
+
refs.set(node, result);
|
|
90
90
|
return result;
|
|
91
91
|
}
|
|
92
92
|
if (typeof ImageData !== "undefined" && node instanceof ImageData) {
|
|
@@ -95,29 +95,29 @@ function clone(node, options, ref) {
|
|
|
95
95
|
node.width,
|
|
96
96
|
node.height
|
|
97
97
|
);
|
|
98
|
-
|
|
98
|
+
refs.set(node, result);
|
|
99
99
|
return result;
|
|
100
100
|
}
|
|
101
101
|
if (typeof URL !== "undefined" && node instanceof URL) {
|
|
102
102
|
const result = new URL(node.href);
|
|
103
|
-
|
|
103
|
+
refs.set(node, result);
|
|
104
104
|
return result;
|
|
105
105
|
}
|
|
106
106
|
if (typeof URLSearchParams !== "undefined" && node instanceof URLSearchParams) {
|
|
107
107
|
const result = new URLSearchParams();
|
|
108
|
-
|
|
108
|
+
refs.set(node, result);
|
|
109
109
|
for (const [key, value] of node) {
|
|
110
110
|
result.append(key, value);
|
|
111
111
|
}
|
|
112
112
|
return result;
|
|
113
113
|
}
|
|
114
|
-
|
|
114
|
+
refs.set(node, node);
|
|
115
115
|
return node;
|
|
116
116
|
}
|
|
117
|
-
function cloneError(value, options,
|
|
117
|
+
function cloneError(value, options, refs) {
|
|
118
118
|
if (value instanceof DOMException) {
|
|
119
119
|
const result2 = new DOMException(value.message, value.name);
|
|
120
|
-
|
|
120
|
+
refs.set(value, result2);
|
|
121
121
|
return result2;
|
|
122
122
|
}
|
|
123
123
|
const name = value.name || "Error";
|
|
@@ -146,7 +146,7 @@ function cloneError(value, options, ref) {
|
|
|
146
146
|
result = new Error(message);
|
|
147
147
|
result.name = name;
|
|
148
148
|
}
|
|
149
|
-
|
|
149
|
+
refs.set(value, result);
|
|
150
150
|
if (value.stack) {
|
|
151
151
|
try {
|
|
152
152
|
result.stack = value.stack;
|
|
@@ -154,16 +154,16 @@ function cloneError(value, options, ref) {
|
|
|
154
154
|
}
|
|
155
155
|
}
|
|
156
156
|
if ("cause" in value && value.cause !== void 0) {
|
|
157
|
-
result.cause = clone(value.cause, options,
|
|
157
|
+
result.cause = clone(value.cause, options, refs);
|
|
158
158
|
}
|
|
159
159
|
for (const key of Object.keys(value)) {
|
|
160
|
-
result[key] = clone(value[key], options,
|
|
160
|
+
result[key] = clone(value[key], options, refs);
|
|
161
161
|
}
|
|
162
162
|
return result;
|
|
163
163
|
}
|
|
164
|
-
function cloneWithDescriptors(node, options,
|
|
164
|
+
function cloneWithDescriptors(node, options, refs) {
|
|
165
165
|
const result = Object.create(Object.getPrototypeOf(node));
|
|
166
|
-
|
|
166
|
+
refs.set(node, result);
|
|
167
167
|
const descs = Object.getOwnPropertyDescriptors(node);
|
|
168
168
|
forEachOwnKey(descs, (key) => {
|
|
169
169
|
if (isUnsafeKey(key)) {
|
|
@@ -171,7 +171,7 @@ function cloneWithDescriptors(node, options, ref) {
|
|
|
171
171
|
}
|
|
172
172
|
const desc = { ...descs[key] };
|
|
173
173
|
if ("value" in desc) {
|
|
174
|
-
desc.value = clone(desc.value, options,
|
|
174
|
+
desc.value = clone(desc.value, options, refs);
|
|
175
175
|
}
|
|
176
176
|
try {
|
|
177
177
|
Object.defineProperty(result, key, desc);
|
|
@@ -183,13 +183,13 @@ function cloneWithDescriptors(node, options, ref) {
|
|
|
183
183
|
});
|
|
184
184
|
return result;
|
|
185
185
|
}
|
|
186
|
-
function forEachOwnKey(object,
|
|
186
|
+
function forEachOwnKey(object, fn) {
|
|
187
187
|
for (const key of Object.keys(object)) {
|
|
188
|
-
|
|
188
|
+
fn(key);
|
|
189
189
|
}
|
|
190
190
|
const symbols = Object.getOwnPropertySymbols(object);
|
|
191
191
|
for (let i = 0, l = symbols.length; i < l; i++) {
|
|
192
|
-
|
|
192
|
+
fn(symbols[i]);
|
|
193
193
|
}
|
|
194
194
|
}
|
|
195
195
|
function isObject(value) {
|
|
@@ -208,9 +208,9 @@ function isUnsafeKey(key) {
|
|
|
208
208
|
/**
|
|
209
209
|
* Bunshin Clone
|
|
210
210
|
* High-performance deep clone utility with descriptor support.
|
|
211
|
-
*
|
|
211
|
+
* Handles circular ref and complex built-in types.
|
|
212
212
|
*
|
|
213
|
-
* @version 1.0.
|
|
213
|
+
* @version 1.0.13
|
|
214
214
|
* @author Yusuke Kamiyamane
|
|
215
215
|
* @license MIT
|
|
216
216
|
* @copyright Copyright (c) 2026 Yusuke Kamiyamane
|