bunshin-clone 1.0.2 → 1.0.4

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,13 +1,15 @@
1
- # bunshin-clone
1
+ # Bunshin Clone
2
2
 
3
3
  High-performance deep clone utility with descriptor support. Supports circular references and complex built-in types.
4
4
 
5
5
  * ⚡ Fast (no unnecessary overhead)
6
6
  * ♻️ Deep clone (no structural sharing)
7
- * 🔁 Supports circular references
7
+ * 🔁 Supports circular ref
8
8
  * 🧠 Handles Map, Set, Array, TypedArray, Date, RegExp, etc.
9
9
  * 🧩 Optional descriptor preservation
10
10
 
11
+ ---
12
+
11
13
  ## Usage
12
14
 
13
15
  ```ts
@@ -45,6 +47,9 @@ interface BunshinCloneOptions {
45
47
  * `false` (default): use standard merge (faster, ignores property descriptors)
46
48
  * `true`: preserve property descriptors (getters/setters, etc.)
47
49
 
50
+ <details>
51
+ <summary>Example</summary>
52
+
48
53
  ```ts
49
54
  const source = {};
50
55
  Object.defineProperty(source, 'x', {
@@ -57,18 +62,23 @@ const result = bunshinClone(source, { preserveDescriptors: true });
57
62
  Object.getOwnPropertyDescriptor(result, 'x')?.get;
58
63
  // => function
59
64
  ```
65
+ </details>
60
66
 
61
67
  ### strictDescriptors
62
68
 
63
69
  * `false` (default): skip incompatible descriptors
64
70
  * `true`: throw if descriptor cannot be merged (e.g. non-configurable or non-writable)
65
71
 
72
+ <details>
73
+ <summary>Example</summary>
74
+
66
75
  ```ts
67
76
  Object.freeze(obj);
68
77
 
69
78
  bunshinClone(obj, { strictDescriptors: true });
70
79
  // => may throw TypeError
71
80
  ```
81
+ </details>
72
82
 
73
83
  ## Supported Types
74
84
 
@@ -186,7 +196,7 @@ When `preserveDescriptors` is enabled:
186
196
 
187
197
  ## Comparison
188
198
 
189
- | Feature | bunshin-clone | structuredClone | lodash.clonedeep |
199
+ | Feature | Bunshin Clone | structuredClone | lodash.clonedeep |
190
200
  |---------------------|--------------|----------------|------------------|
191
201
  | Circular refs | ✅ | ✅ | ✅ |
192
202
  | Map / Set | ✅ | ✅ | ⚠️ (partial) |
package/dist/index.cjs CHANGED
@@ -160,19 +160,19 @@ function cloneError(value, options, ref) {
160
160
  function cloneWithDescriptors(node, options, ref) {
161
161
  const result = Object.create(Object.getPrototypeOf(node));
162
162
  ref.set(node, result);
163
- const descriptors = Object.getOwnPropertyDescriptors(node);
164
- const keys = Reflect.ownKeys(descriptors);
163
+ const descs = Object.getOwnPropertyDescriptors(node);
164
+ const keys = Reflect.ownKeys(descs);
165
165
  for (let i = 0, l = keys.length; i < l; i++) {
166
166
  const key = keys[i];
167
167
  if (isUnsafeKey(key)) {
168
168
  continue;
169
169
  }
170
- const descriptor = { ...descriptors[key] };
171
- if ("value" in descriptor) {
172
- descriptor.value = clone(descriptor.value, options, ref);
170
+ const desc = { ...descs[key] };
171
+ if ("value" in desc) {
172
+ desc.value = clone(desc.value, options, ref);
173
173
  }
174
174
  try {
175
- Object.defineProperty(result, key, descriptor);
175
+ Object.defineProperty(result, key, desc);
176
176
  } catch (error) {
177
177
  if (options.strictDescriptors) {
178
178
  throw error;
@@ -191,11 +191,11 @@ function isUnsafeKey(key) {
191
191
  return typeof key === "string" && (key === "__proto__" || key === "prototype" || key === "constructor");
192
192
  }
193
193
  /**
194
- * bunshin-clone
194
+ * Bunshin Clone
195
195
  * High-performance deep clone utility with descriptor support.
196
196
  * Supports circular ref and complex built-in types.
197
197
  *
198
- * @version 1.0.2
198
+ * @version 1.0.4
199
199
  * @author Yusuke Kamiyamane
200
200
  * @license MIT
201
201
  * @copyright Copyright (c) 2026 Yusuke Kamiyamane
package/dist/index.d.cts CHANGED
@@ -1,9 +1,9 @@
1
1
  /**
2
- * bunshin-clone
2
+ * Bunshin Clone
3
3
  * High-performance deep clone utility with descriptor support.
4
4
  * Supports circular ref and complex built-in types.
5
5
  *
6
- * @version 1.0.2
6
+ * @version 1.0.4
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
- * bunshin-clone
2
+ * Bunshin Clone
3
3
  * High-performance deep clone utility with descriptor support.
4
4
  * Supports circular ref and complex built-in types.
5
5
  *
6
- * @version 1.0.2
6
+ * @version 1.0.4
7
7
  * @author Yusuke Kamiyamane
8
8
  * @license MIT
9
9
  * @copyright Copyright (c) 2026 Yusuke Kamiyamane
package/dist/index.js CHANGED
@@ -156,19 +156,19 @@ function cloneError(value, options, ref) {
156
156
  function cloneWithDescriptors(node, options, ref) {
157
157
  const result = Object.create(Object.getPrototypeOf(node));
158
158
  ref.set(node, result);
159
- const descriptors = Object.getOwnPropertyDescriptors(node);
160
- const keys = Reflect.ownKeys(descriptors);
159
+ const descs = Object.getOwnPropertyDescriptors(node);
160
+ const keys = Reflect.ownKeys(descs);
161
161
  for (let i = 0, l = keys.length; i < l; i++) {
162
162
  const key = keys[i];
163
163
  if (isUnsafeKey(key)) {
164
164
  continue;
165
165
  }
166
- const descriptor = { ...descriptors[key] };
167
- if ("value" in descriptor) {
168
- descriptor.value = clone(descriptor.value, options, ref);
166
+ const desc = { ...descs[key] };
167
+ if ("value" in desc) {
168
+ desc.value = clone(desc.value, options, ref);
169
169
  }
170
170
  try {
171
- Object.defineProperty(result, key, descriptor);
171
+ Object.defineProperty(result, key, desc);
172
172
  } catch (error) {
173
173
  if (options.strictDescriptors) {
174
174
  throw error;
@@ -187,11 +187,11 @@ function isUnsafeKey(key) {
187
187
  return typeof key === "string" && (key === "__proto__" || key === "prototype" || key === "constructor");
188
188
  }
189
189
  /**
190
- * bunshin-clone
190
+ * Bunshin Clone
191
191
  * High-performance deep clone utility with descriptor support.
192
192
  * Supports circular ref and complex built-in types.
193
193
  *
194
- * @version 1.0.2
194
+ * @version 1.0.4
195
195
  * @author Yusuke Kamiyamane
196
196
  * @license MIT
197
197
  * @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.2",
3
+ "version": "1.0.4",
4
4
  "description": "High-performance deep clone utility with descriptor support",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -25,8 +25,33 @@
25
25
  "lint": "tsc --noEmit"
26
26
  },
27
27
  "keywords": [
28
+ "array",
29
+ "buffer",
30
+ "circular-reference",
28
31
  "clone",
32
+ "clone-array",
33
+ "clone-array-deep",
34
+ "clone-buffer",
35
+ "clone-date",
36
+ "clone-deep",
37
+ "clone-map",
38
+ "clone-object",
39
+ "clone-object-deep",
40
+ "clone-regexp",
41
+ "clone-set",
42
+ "copy",
43
+ "copy-deep",
44
+ "date",
29
45
  "deep",
46
+ "deep-clone",
47
+ "deep-copy",
48
+ "descriptor",
49
+ "map",
50
+ "object",
51
+ "property-descriptor",
52
+ "regexp",
53
+ "set",
54
+ "structured-clone",
30
55
  "typescript"
31
56
  ],
32
57
  "author": "Yusuke Kamiyamane",