bunshin-clone 1.2.8 → 1.2.9
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 +3 -3
- package/dist/index.cjs +30 -33
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +30 -33
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,11 +13,11 @@ npm i bunshin-clone
|
|
|
13
13
|
import { bunshinClone } from 'bunshin-clone';
|
|
14
14
|
|
|
15
15
|
// CDNs
|
|
16
|
-
import { bunshinClone } from 'https://esm.sh/bunshin-clone@1.2.
|
|
16
|
+
import { bunshinClone } from 'https://esm.sh/bunshin-clone@1.2.9';
|
|
17
17
|
// or
|
|
18
|
-
import { bunshinClone } from 'https://cdn.jsdelivr.net/npm/bunshin-clone@1.2.
|
|
18
|
+
import { bunshinClone } from 'https://cdn.jsdelivr.net/npm/bunshin-clone@1.2.9/+esm';
|
|
19
19
|
// or
|
|
20
|
-
import { bunshinClone } from 'https://esm.unpkg.com/bunshin-clone@1.2.
|
|
20
|
+
import { bunshinClone } from 'https://esm.unpkg.com/bunshin-clone@1.2.9';
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
## 📦 APIs
|
package/dist/index.cjs
CHANGED
|
@@ -28,27 +28,27 @@ function clone(node, options, refs) {
|
|
|
28
28
|
if (isPlainObject(node)) {
|
|
29
29
|
const result = Object.create(Object.getPrototypeOf(node));
|
|
30
30
|
refs.set(node, result);
|
|
31
|
-
for (const
|
|
32
|
-
if (!HAS_OWN.call(node,
|
|
31
|
+
for (const k in node) {
|
|
32
|
+
if (!HAS_OWN.call(node, k) || isUnsafeKey(k)) {
|
|
33
33
|
continue;
|
|
34
34
|
}
|
|
35
|
-
result[
|
|
35
|
+
result[k] = clone(node[k], 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
|
-
for (const [
|
|
43
|
-
result.set(clone(
|
|
42
|
+
for (const [k, v] of node) {
|
|
43
|
+
result.set(clone(k, options, refs), clone(v, 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
|
-
for (const
|
|
51
|
-
result.add(clone(
|
|
50
|
+
for (const i of node) {
|
|
51
|
+
result.add(clone(i, options, refs));
|
|
52
52
|
}
|
|
53
53
|
return result;
|
|
54
54
|
}
|
|
@@ -89,12 +89,10 @@ function clone(node, options, refs) {
|
|
|
89
89
|
return result;
|
|
90
90
|
}
|
|
91
91
|
if (typeof ImageData !== "undefined" && node instanceof ImageData) {
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
{ colorSpace: node.colorSpace }
|
|
97
|
-
);
|
|
92
|
+
const { data, width, height, colorSpace } = node;
|
|
93
|
+
const result = new ImageData(new Uint8ClampedArray(data), width, height, {
|
|
94
|
+
colorSpace
|
|
95
|
+
});
|
|
98
96
|
refs.set(node, result);
|
|
99
97
|
return result;
|
|
100
98
|
}
|
|
@@ -106,8 +104,8 @@ function clone(node, options, refs) {
|
|
|
106
104
|
if (node instanceof URLSearchParams) {
|
|
107
105
|
const result = new URLSearchParams();
|
|
108
106
|
refs.set(node, result);
|
|
109
|
-
for (const [
|
|
110
|
-
result.append(
|
|
107
|
+
for (const [k, v] of node) {
|
|
108
|
+
result.append(k, v);
|
|
111
109
|
}
|
|
112
110
|
return result;
|
|
113
111
|
}
|
|
@@ -115,13 +113,12 @@ function clone(node, options, refs) {
|
|
|
115
113
|
return node;
|
|
116
114
|
}
|
|
117
115
|
function cloneError(value, options, refs) {
|
|
116
|
+
const { name, message, cause, stack } = value;
|
|
118
117
|
if (value instanceof DOMException) {
|
|
119
|
-
const result2 = new DOMException(
|
|
118
|
+
const result2 = new DOMException(message, name);
|
|
120
119
|
refs.set(value, result2);
|
|
121
120
|
return result2;
|
|
122
121
|
}
|
|
123
|
-
const name = value.name || "Error";
|
|
124
|
-
const message = value.message || "";
|
|
125
122
|
let result;
|
|
126
123
|
switch (name) {
|
|
127
124
|
case "EvalError":
|
|
@@ -147,17 +144,17 @@ function cloneError(value, options, refs) {
|
|
|
147
144
|
result.name = name;
|
|
148
145
|
}
|
|
149
146
|
refs.set(value, result);
|
|
150
|
-
if (
|
|
147
|
+
if (stack) {
|
|
151
148
|
try {
|
|
152
|
-
result.stack =
|
|
149
|
+
result.stack = stack;
|
|
153
150
|
} catch {
|
|
154
151
|
}
|
|
155
152
|
}
|
|
156
|
-
if ("cause" in value &&
|
|
157
|
-
result.cause = clone(
|
|
153
|
+
if ("cause" in value && cause !== void 0) {
|
|
154
|
+
result.cause = clone(cause, options, refs);
|
|
158
155
|
}
|
|
159
|
-
for (const
|
|
160
|
-
result[
|
|
156
|
+
for (const k of Object.keys(value)) {
|
|
157
|
+
result[k] = clone(value[k], options, refs);
|
|
161
158
|
}
|
|
162
159
|
return result;
|
|
163
160
|
}
|
|
@@ -165,16 +162,16 @@ function cloneWithDescriptors(node, options, refs) {
|
|
|
165
162
|
const result = Object.create(Object.getPrototypeOf(node));
|
|
166
163
|
refs.set(node, result);
|
|
167
164
|
const descs = Object.getOwnPropertyDescriptors(node);
|
|
168
|
-
forEachOwnKey(descs, (
|
|
169
|
-
if (isUnsafeKey(
|
|
165
|
+
forEachOwnKey(descs, (k) => {
|
|
166
|
+
if (isUnsafeKey(k)) {
|
|
170
167
|
return;
|
|
171
168
|
}
|
|
172
|
-
const desc = { ...descs[
|
|
169
|
+
const desc = { ...descs[k] };
|
|
173
170
|
if ("value" in desc) {
|
|
174
171
|
desc.value = clone(desc.value, options, refs);
|
|
175
172
|
}
|
|
176
173
|
try {
|
|
177
|
-
Object.defineProperty(result,
|
|
174
|
+
Object.defineProperty(result, k, desc);
|
|
178
175
|
} catch (error) {
|
|
179
176
|
if (options.strictDescriptors) {
|
|
180
177
|
throw error;
|
|
@@ -184,11 +181,11 @@ function cloneWithDescriptors(node, options, refs) {
|
|
|
184
181
|
return result;
|
|
185
182
|
}
|
|
186
183
|
function forEachOwnKey(object, fn) {
|
|
187
|
-
for (const
|
|
188
|
-
fn(
|
|
184
|
+
for (const k of Object.keys(object)) {
|
|
185
|
+
fn(k);
|
|
189
186
|
}
|
|
190
|
-
for (const
|
|
191
|
-
fn(
|
|
187
|
+
for (const s of Object.getOwnPropertySymbols(object)) {
|
|
188
|
+
fn(s);
|
|
192
189
|
}
|
|
193
190
|
}
|
|
194
191
|
function isObject(value) {
|
|
@@ -209,7 +206,7 @@ function isUnsafeKey(key) {
|
|
|
209
206
|
* High-performance deep clone utility with descriptor support.
|
|
210
207
|
* Handles circular ref and complex built-in types.
|
|
211
208
|
*
|
|
212
|
-
* @version 1.2.
|
|
209
|
+
* @version 1.2.9
|
|
213
210
|
* @author Yusuke Kamiyamane
|
|
214
211
|
* @license MIT
|
|
215
212
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -26,27 +26,27 @@ function clone(node, options, refs) {
|
|
|
26
26
|
if (isPlainObject(node)) {
|
|
27
27
|
const result = Object.create(Object.getPrototypeOf(node));
|
|
28
28
|
refs.set(node, result);
|
|
29
|
-
for (const
|
|
30
|
-
if (!HAS_OWN.call(node,
|
|
29
|
+
for (const k in node) {
|
|
30
|
+
if (!HAS_OWN.call(node, k) || isUnsafeKey(k)) {
|
|
31
31
|
continue;
|
|
32
32
|
}
|
|
33
|
-
result[
|
|
33
|
+
result[k] = clone(node[k], 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
|
-
for (const [
|
|
41
|
-
result.set(clone(
|
|
40
|
+
for (const [k, v] of node) {
|
|
41
|
+
result.set(clone(k, options, refs), clone(v, 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
|
-
for (const
|
|
49
|
-
result.add(clone(
|
|
48
|
+
for (const i of node) {
|
|
49
|
+
result.add(clone(i, options, refs));
|
|
50
50
|
}
|
|
51
51
|
return result;
|
|
52
52
|
}
|
|
@@ -87,12 +87,10 @@ function clone(node, options, refs) {
|
|
|
87
87
|
return result;
|
|
88
88
|
}
|
|
89
89
|
if (typeof ImageData !== "undefined" && node instanceof ImageData) {
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
{ colorSpace: node.colorSpace }
|
|
95
|
-
);
|
|
90
|
+
const { data, width, height, colorSpace } = node;
|
|
91
|
+
const result = new ImageData(new Uint8ClampedArray(data), width, height, {
|
|
92
|
+
colorSpace
|
|
93
|
+
});
|
|
96
94
|
refs.set(node, result);
|
|
97
95
|
return result;
|
|
98
96
|
}
|
|
@@ -104,8 +102,8 @@ function clone(node, options, refs) {
|
|
|
104
102
|
if (node instanceof URLSearchParams) {
|
|
105
103
|
const result = new URLSearchParams();
|
|
106
104
|
refs.set(node, result);
|
|
107
|
-
for (const [
|
|
108
|
-
result.append(
|
|
105
|
+
for (const [k, v] of node) {
|
|
106
|
+
result.append(k, v);
|
|
109
107
|
}
|
|
110
108
|
return result;
|
|
111
109
|
}
|
|
@@ -113,13 +111,12 @@ function clone(node, options, refs) {
|
|
|
113
111
|
return node;
|
|
114
112
|
}
|
|
115
113
|
function cloneError(value, options, refs) {
|
|
114
|
+
const { name, message, cause, stack } = value;
|
|
116
115
|
if (value instanceof DOMException) {
|
|
117
|
-
const result2 = new DOMException(
|
|
116
|
+
const result2 = new DOMException(message, name);
|
|
118
117
|
refs.set(value, result2);
|
|
119
118
|
return result2;
|
|
120
119
|
}
|
|
121
|
-
const name = value.name || "Error";
|
|
122
|
-
const message = value.message || "";
|
|
123
120
|
let result;
|
|
124
121
|
switch (name) {
|
|
125
122
|
case "EvalError":
|
|
@@ -145,17 +142,17 @@ function cloneError(value, options, refs) {
|
|
|
145
142
|
result.name = name;
|
|
146
143
|
}
|
|
147
144
|
refs.set(value, result);
|
|
148
|
-
if (
|
|
145
|
+
if (stack) {
|
|
149
146
|
try {
|
|
150
|
-
result.stack =
|
|
147
|
+
result.stack = stack;
|
|
151
148
|
} catch {
|
|
152
149
|
}
|
|
153
150
|
}
|
|
154
|
-
if ("cause" in value &&
|
|
155
|
-
result.cause = clone(
|
|
151
|
+
if ("cause" in value && cause !== void 0) {
|
|
152
|
+
result.cause = clone(cause, options, refs);
|
|
156
153
|
}
|
|
157
|
-
for (const
|
|
158
|
-
result[
|
|
154
|
+
for (const k of Object.keys(value)) {
|
|
155
|
+
result[k] = clone(value[k], options, refs);
|
|
159
156
|
}
|
|
160
157
|
return result;
|
|
161
158
|
}
|
|
@@ -163,16 +160,16 @@ function cloneWithDescriptors(node, options, refs) {
|
|
|
163
160
|
const result = Object.create(Object.getPrototypeOf(node));
|
|
164
161
|
refs.set(node, result);
|
|
165
162
|
const descs = Object.getOwnPropertyDescriptors(node);
|
|
166
|
-
forEachOwnKey(descs, (
|
|
167
|
-
if (isUnsafeKey(
|
|
163
|
+
forEachOwnKey(descs, (k) => {
|
|
164
|
+
if (isUnsafeKey(k)) {
|
|
168
165
|
return;
|
|
169
166
|
}
|
|
170
|
-
const desc = { ...descs[
|
|
167
|
+
const desc = { ...descs[k] };
|
|
171
168
|
if ("value" in desc) {
|
|
172
169
|
desc.value = clone(desc.value, options, refs);
|
|
173
170
|
}
|
|
174
171
|
try {
|
|
175
|
-
Object.defineProperty(result,
|
|
172
|
+
Object.defineProperty(result, k, desc);
|
|
176
173
|
} catch (error) {
|
|
177
174
|
if (options.strictDescriptors) {
|
|
178
175
|
throw error;
|
|
@@ -182,11 +179,11 @@ function cloneWithDescriptors(node, options, refs) {
|
|
|
182
179
|
return result;
|
|
183
180
|
}
|
|
184
181
|
function forEachOwnKey(object, fn) {
|
|
185
|
-
for (const
|
|
186
|
-
fn(
|
|
182
|
+
for (const k of Object.keys(object)) {
|
|
183
|
+
fn(k);
|
|
187
184
|
}
|
|
188
|
-
for (const
|
|
189
|
-
fn(
|
|
185
|
+
for (const s of Object.getOwnPropertySymbols(object)) {
|
|
186
|
+
fn(s);
|
|
190
187
|
}
|
|
191
188
|
}
|
|
192
189
|
function isObject(value) {
|
|
@@ -207,7 +204,7 @@ function isUnsafeKey(key) {
|
|
|
207
204
|
* High-performance deep clone utility with descriptor support.
|
|
208
205
|
* Handles circular ref and complex built-in types.
|
|
209
206
|
*
|
|
210
|
-
* @version 1.2.
|
|
207
|
+
* @version 1.2.9
|
|
211
208
|
* @author Yusuke Kamiyamane
|
|
212
209
|
* @license MIT
|
|
213
210
|
* @copyright Copyright (c) Yusuke Kamiyamane
|