bunshin-clone 1.2.1 → 1.2.3

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
@@ -2,14 +2,6 @@
2
2
 
3
3
  High-performance deep clone utility with descriptor support. Handles circular ref and complex built-in types.
4
4
 
5
- * Fast (no unnecessary overhead)
6
- * Deep clone (no structural sharing)
7
- * Supports circular ref
8
- * Handles Map, Set, Array, TypedArray, Date, RegExp, etc.
9
- * Optional descriptor preservation
10
-
11
- ---
12
-
13
5
  ## Install
14
6
 
15
7
  ```bash
@@ -21,14 +13,14 @@ npm i bunshin-clone
21
13
  import bunshinClone from 'bunshin-clone';
22
14
 
23
15
  // CDNs
24
- import bunshinClone from 'https://esm.sh/bunshin-clone'
16
+ import bunshinClone from 'https://esm.sh/bunshin-clone@1.2.3';
25
17
  // or
26
- import bunshinClone from 'https://cdn.jsdelivr.net/npm/bunshin-clone/+esm';
18
+ import bunshinClone from 'https://cdn.jsdelivr.net/npm/bunshin-clone@1.2.3/+esm';
27
19
  // or
28
- import bunshinClone from 'https://unpkg.com/bunshin-clone/dist/index.js';
20
+ import bunshinClone from 'https://esm.unpkg.com/bunshin-clone@1.2.3';
29
21
  ```
30
22
 
31
- ## Usage
23
+ ## 📦 APIs
32
24
 
33
25
  ```ts
34
26
  bunshinClone(source, options);
@@ -38,56 +30,29 @@ bunshinClone(source, options);
38
30
  // options (optional): BunshinCloneOptions
39
31
  ```
40
32
 
41
- ### 🪄 Options
33
+ ## 🪄 Options
42
34
 
43
35
  ```ts
44
36
  interface BunshinCloneOptions {
45
- preserveDescriptors?: boolean; // (default: false)
46
- strictDescriptors?: boolean; // (default: false)
37
+ preserveDescriptors?: boolean; // default: false
38
+ strictDescriptors?: boolean; // default: false
47
39
  }
48
40
  ```
49
41
 
50
- **preserveDescriptors**
42
+ ### `preserveDescriptors`
51
43
 
52
- * `false`: use standard merge (faster, ignores property descriptors)
53
- * `true`: preserve property descriptors (getters/setters, etc.)
44
+ If `true`, preserves property descriptors (getters/setters, etc.).
54
45
 
55
- <details>
56
- <summary>Example</summary>
46
+ ### `strictDescriptors`
57
47
 
58
- ```ts
59
- const source = {};
60
- Object.defineProperty(source, 'x', {
61
- get: () => 42,
62
- enumerable: true,
63
- });
48
+ If `true`, throws if descriptor cannot be merged (e.g. non-configurable or non-writable)
64
49
 
65
- const result = bunshinClone(source, { preserveDescriptors: true });
66
-
67
- Object.getOwnPropertyDescriptor(result, 'x')?.get;
68
- // => function
69
- ```
70
- </details>
71
-
72
- **strictDescriptors**
73
-
74
- * `false`: skip incompatible descriptors
75
- * `true`: throw if descriptor cannot be merged (e.g. non-configurable or non-writable)
50
+ ## 📖 Details
76
51
 
77
52
  <details>
78
- <summary>Example</summary>
53
+ <summary>Read more</summary>
79
54
 
80
- ```ts
81
- Object.freeze(obj);
82
-
83
- bunshinClone(obj, { strictDescriptors: true });
84
- // => may throw TypeError
85
- ```
86
- </details>
87
-
88
- ---
89
-
90
- ## Example
55
+ ### Example
91
56
 
92
57
  ```ts
93
58
  const source = { foo: 1, nested: { x: 1 } };
@@ -101,7 +66,7 @@ console.log(result === source); // false
101
66
  console.log(result.nested === source.nested); // false
102
67
  ```
103
68
 
104
- ## Supported Types
69
+ ### Supported Types
105
70
 
106
71
  bunshin-clone correctly handles:
107
72
 
@@ -120,7 +85,7 @@ bunshin-clone correctly handles:
120
85
  * URL
121
86
  * URLSearchParams
122
87
 
123
- ## Circular ref
88
+ ### Circular ref
124
89
 
125
90
  ```ts
126
91
  const a: any = { x: 1 };
@@ -131,9 +96,9 @@ const result = bunshinClone(a);
131
96
  result.self === result; // true
132
97
  ```
133
98
 
134
- ## Descriptor Behavior
99
+ ### Descriptor Behavior
135
100
 
136
- ### Default (fast path)
101
+ #### Default (fast path)
137
102
 
138
103
  ```ts
139
104
  const source = {
@@ -148,7 +113,7 @@ result.x; // 42
148
113
  // getter is NOT preserved
149
114
  ```
150
115
 
151
- ### preserveDescriptors: true
116
+ #### preserveDescriptors: true
152
117
 
153
118
  ```ts
154
119
  const source = {};
@@ -165,7 +130,7 @@ Object.getOwnPropertyDescriptor(result, 'x')?.get;
165
130
  // => preserved
166
131
  ```
167
132
 
168
- ### Unsupported / Pass-through Types
133
+ #### Unsupported / Pass-through Types
169
134
 
170
135
  Some values are returned as-is:
171
136
 
@@ -180,9 +145,9 @@ const fn = () => {};
180
145
  bunshinClone(fn) === fn; // true
181
146
  ```
182
147
 
183
- ## Design Notes
148
+ ### Design Notes
184
149
 
185
- ### Deep clone (no structural sharing)
150
+ #### Deep clone (no structural sharing)
186
151
 
187
152
  Unlike merge utilities, bunshin-clone always produces a new structure:
188
153
 
@@ -195,12 +160,12 @@ result !== source; // true
195
160
  result.a !== source.a; // true
196
161
  ```
197
162
 
198
- ### Getter / Setter behavior
163
+ #### Getter / Setter behavior
199
164
 
200
165
  * Default: evaluated and converted to value
201
166
  * preserveDescriptors: preserved as-is
202
167
 
203
- ### Descriptor safety
168
+ #### Descriptor safety
204
169
 
205
170
  When `preserveDescriptors` is enabled:
206
171
 
@@ -208,14 +173,14 @@ When `preserveDescriptors` is enabled:
208
173
  * original object is never mutated
209
174
  * errors are controlled via `strictDescriptors`
210
175
 
211
- ## Performance
176
+ ### Performance
212
177
 
213
178
  * No proxy / no diffing
214
179
  * Minimal branching
215
180
  * Fast path for plain objects and arrays
216
181
  * Competitive with structuredClone in many cases
217
182
 
218
- ## Comparison
183
+ ### Comparison
219
184
 
220
185
  | Feature | Bunshin Clone | structuredClone | lodash.clonedeep |
221
186
  |---------------------|--------------|----------------|------------------|
@@ -227,3 +192,5 @@ When `preserveDescriptors` is enabled:
227
192
  | Prototype preserved | ✅ | ❌ | ⚠️ |
228
193
  | Custom control | ✅ | ❌ | ❌ |
229
194
  | Performance | ⚡ fast | ⚡ fast | 🐢 slower |
195
+
196
+ </details>
package/dist/index.cjs CHANGED
@@ -209,7 +209,7 @@ function isUnsafeKey(key) {
209
209
  * High-performance deep clone utility with descriptor support.
210
210
  * Handles circular ref and complex built-in types.
211
211
  *
212
- * @version 1.2.1
212
+ * @version 1.2.3
213
213
  * @author Yusuke Kamiyamane
214
214
  * @license MIT
215
215
  * @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.1
6
+ * @version 1.2.3
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.1
6
+ * @version 1.2.3
7
7
  * @author Yusuke Kamiyamane
8
8
  * @license MIT
9
9
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.js CHANGED
@@ -207,7 +207,7 @@ function isUnsafeKey(key) {
207
207
  * High-performance deep clone utility with descriptor support.
208
208
  * Handles circular ref and complex built-in types.
209
209
  *
210
- * @version 1.2.1
210
+ * @version 1.2.3
211
211
  * @author Yusuke Kamiyamane
212
212
  * @license MIT
213
213
  * @copyright Copyright (c) Yusuke Kamiyamane
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bunshin-clone",
3
- "version": "1.2.1",
3
+ "version": "1.2.3",
4
4
  "description": "High-performance deep clone utility with descriptor support",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",