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 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.8';
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.8/+esm';
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.8';
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 key in node) {
32
- if (!HAS_OWN.call(node, key) || isUnsafeKey(key)) {
31
+ for (const k in node) {
32
+ if (!HAS_OWN.call(node, k) || isUnsafeKey(k)) {
33
33
  continue;
34
34
  }
35
- result[key] = clone(node[key], options, refs);
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 [key, value] of node) {
43
- result.set(clone(key, options, refs), clone(value, options, refs));
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 item of node) {
51
- result.add(clone(item, options, refs));
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 result = new ImageData(
93
- new Uint8ClampedArray(node.data),
94
- node.width,
95
- node.height,
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 [key, value] of node) {
110
- result.append(key, value);
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(value.message, value.name);
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 (value.stack) {
147
+ if (stack) {
151
148
  try {
152
- result.stack = value.stack;
149
+ result.stack = stack;
153
150
  } catch {
154
151
  }
155
152
  }
156
- if ("cause" in value && value.cause !== void 0) {
157
- result.cause = clone(value.cause, options, refs);
153
+ if ("cause" in value && cause !== void 0) {
154
+ result.cause = clone(cause, options, refs);
158
155
  }
159
- for (const key of Object.keys(value)) {
160
- result[key] = clone(value[key], options, refs);
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, (key) => {
169
- if (isUnsafeKey(key)) {
165
+ forEachOwnKey(descs, (k) => {
166
+ if (isUnsafeKey(k)) {
170
167
  return;
171
168
  }
172
- const desc = { ...descs[key] };
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, key, desc);
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 key of Object.keys(object)) {
188
- fn(key);
184
+ for (const k of Object.keys(object)) {
185
+ fn(k);
189
186
  }
190
- for (const symbol of Object.getOwnPropertySymbols(object)) {
191
- fn(symbol);
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.8
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
@@ -3,7 +3,7 @@
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.2.8
6
+ * @version 1.2.9
7
7
  * @author Yusuke Kamiyamane
8
8
  * @license MIT
9
9
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.d.ts CHANGED
@@ -3,7 +3,7 @@
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.2.8
6
+ * @version 1.2.9
7
7
  * @author Yusuke Kamiyamane
8
8
  * @license MIT
9
9
  * @copyright Copyright (c) Yusuke Kamiyamane
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 key in node) {
30
- if (!HAS_OWN.call(node, key) || isUnsafeKey(key)) {
29
+ for (const k in node) {
30
+ if (!HAS_OWN.call(node, k) || isUnsafeKey(k)) {
31
31
  continue;
32
32
  }
33
- result[key] = clone(node[key], options, refs);
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 [key, value] of node) {
41
- result.set(clone(key, options, refs), clone(value, options, refs));
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 item of node) {
49
- result.add(clone(item, options, refs));
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 result = new ImageData(
91
- new Uint8ClampedArray(node.data),
92
- node.width,
93
- node.height,
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 [key, value] of node) {
108
- result.append(key, value);
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(value.message, value.name);
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 (value.stack) {
145
+ if (stack) {
149
146
  try {
150
- result.stack = value.stack;
147
+ result.stack = stack;
151
148
  } catch {
152
149
  }
153
150
  }
154
- if ("cause" in value && value.cause !== void 0) {
155
- result.cause = clone(value.cause, options, refs);
151
+ if ("cause" in value && cause !== void 0) {
152
+ result.cause = clone(cause, options, refs);
156
153
  }
157
- for (const key of Object.keys(value)) {
158
- result[key] = clone(value[key], options, refs);
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, (key) => {
167
- if (isUnsafeKey(key)) {
163
+ forEachOwnKey(descs, (k) => {
164
+ if (isUnsafeKey(k)) {
168
165
  return;
169
166
  }
170
- const desc = { ...descs[key] };
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, key, desc);
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 key of Object.keys(object)) {
186
- fn(key);
182
+ for (const k of Object.keys(object)) {
183
+ fn(k);
187
184
  }
188
- for (const symbol of Object.getOwnPropertySymbols(object)) {
189
- fn(symbol);
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.8
207
+ * @version 1.2.9
211
208
  * @author Yusuke Kamiyamane
212
209
  * @license MIT
213
210
  * @copyright Copyright (c) Yusuke Kamiyamane
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bunshin-clone",
3
- "version": "1.2.8",
3
+ "version": "1.2.9",
4
4
  "description": "High-performance deep clone utility with descriptor support",
5
5
  "keywords": [
6
6
  "array",