bunshin-clone 1.0.10 → 1.0.12

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
@@ -1,6 +1,6 @@
1
1
  # Bunshin Clone
2
2
 
3
- High-performance deep clone utility with descriptor support. Supports circular references and complex built-in types.
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
- // CDN
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
- import bunshinClone from 'bunshin-clone';
31
-
32
- const source = { foo: 1, nested: { x: 1 } };
33
-
34
- const result = bunshinClone(source);
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
- ## Options
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
@@ -168,9 +168,6 @@ function cloneWithDescriptors(node, options, ref) {
168
168
  ref.set(node, result);
169
169
  const descs = Object.getOwnPropertyDescriptors(node);
170
170
  forEachOwnKey(descs, (key) => {
171
- if (!key) {
172
- return;
173
- }
174
171
  if (isUnsafeKey(key)) {
175
172
  return;
176
173
  }
@@ -188,17 +185,13 @@ function cloneWithDescriptors(node, options, ref) {
188
185
  });
189
186
  return result;
190
187
  }
191
- function forEachOwnKey(object, callback) {
188
+ function forEachOwnKey(object, fn) {
192
189
  for (const key of Object.keys(object)) {
193
- callback(key);
190
+ fn(key);
194
191
  }
195
192
  const symbols = Object.getOwnPropertySymbols(object);
196
193
  for (let i = 0, l = symbols.length; i < l; i++) {
197
- const symbol = symbols[i];
198
- if (!symbol) {
199
- continue;
200
- }
201
- callback(symbol);
194
+ fn(symbols[i]);
202
195
  }
203
196
  }
204
197
  function isObject(value) {
@@ -217,9 +210,9 @@ function isUnsafeKey(key) {
217
210
  /**
218
211
  * Bunshin Clone
219
212
  * High-performance deep clone utility with descriptor support.
220
- * Supports circular ref and complex built-in types.
213
+ * Handles circular ref and complex built-in types.
221
214
  *
222
- * @version 1.0.10
215
+ * @version 1.0.12
223
216
  * @author Yusuke Kamiyamane
224
217
  * @license MIT
225
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
- * Supports circular ref and complex built-in types.
4
+ * Handles circular ref and complex built-in types.
5
5
  *
6
- * @version 1.0.10
6
+ * @version 1.0.12
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
- * Supports circular ref and complex built-in types.
4
+ * Handles circular ref and complex built-in types.
5
5
  *
6
- * @version 1.0.10
6
+ * @version 1.0.12
7
7
  * @author Yusuke Kamiyamane
8
8
  * @license MIT
9
9
  * @copyright Copyright (c) 2026 Yusuke Kamiyamane
package/dist/index.js CHANGED
@@ -166,9 +166,6 @@ function cloneWithDescriptors(node, options, ref) {
166
166
  ref.set(node, result);
167
167
  const descs = Object.getOwnPropertyDescriptors(node);
168
168
  forEachOwnKey(descs, (key) => {
169
- if (!key) {
170
- return;
171
- }
172
169
  if (isUnsafeKey(key)) {
173
170
  return;
174
171
  }
@@ -186,17 +183,13 @@ function cloneWithDescriptors(node, options, ref) {
186
183
  });
187
184
  return result;
188
185
  }
189
- function forEachOwnKey(object, callback) {
186
+ function forEachOwnKey(object, fn) {
190
187
  for (const key of Object.keys(object)) {
191
- callback(key);
188
+ fn(key);
192
189
  }
193
190
  const symbols = Object.getOwnPropertySymbols(object);
194
191
  for (let i = 0, l = symbols.length; i < l; i++) {
195
- const symbol = symbols[i];
196
- if (!symbol) {
197
- continue;
198
- }
199
- callback(symbol);
192
+ fn(symbols[i]);
200
193
  }
201
194
  }
202
195
  function isObject(value) {
@@ -215,9 +208,9 @@ function isUnsafeKey(key) {
215
208
  /**
216
209
  * Bunshin Clone
217
210
  * High-performance deep clone utility with descriptor support.
218
- * Supports circular ref and complex built-in types.
211
+ * Handles circular ref and complex built-in types.
219
212
  *
220
- * @version 1.0.10
213
+ * @version 1.0.12
221
214
  * @author Yusuke Kamiyamane
222
215
  * @license MIT
223
216
  * @copyright Copyright (c) 2026 Yusuke Kamiyamane
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bunshin-clone",
3
- "version": "1.0.10",
3
+ "version": "1.0.12",
4
4
  "description": "High-performance deep clone utility with descriptor support",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",