bunshin-clone 1.1.0 → 1.2.0

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/dist/index.cjs CHANGED
@@ -1,11 +1,35 @@
1
1
  'use strict';
2
2
 
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
3
5
  // src/index.ts
4
6
  var EMPTY_OPTIONS = {};
5
7
  var { hasOwnProperty: HAS_OWN } = Object.prototype;
6
8
  function bunshinClone(source, options) {
7
9
  return clone(source, options ?? EMPTY_OPTIONS, /* @__PURE__ */ new WeakMap());
8
10
  }
11
+ function cloneWithDescriptors(node, options, refs) {
12
+ const result = Object.create(Object.getPrototypeOf(node));
13
+ refs.set(node, result);
14
+ const descs = Object.getOwnPropertyDescriptors(node);
15
+ forEachOwnKey(descs, (key) => {
16
+ if (isUnsafeKey(key)) {
17
+ return;
18
+ }
19
+ const desc = { ...descs[key] };
20
+ if ("value" in desc) {
21
+ desc.value = clone(desc.value, options, refs);
22
+ }
23
+ try {
24
+ Object.defineProperty(result, key, desc);
25
+ } catch (error) {
26
+ if (options.strictDescriptors) {
27
+ throw error;
28
+ }
29
+ }
30
+ });
31
+ return result;
32
+ }
9
33
  function clone(node, options, refs) {
10
34
  if (!isObject(node)) {
11
35
  return node;
@@ -160,28 +184,6 @@ function cloneError(value, options, refs) {
160
184
  }
161
185
  return result;
162
186
  }
163
- function cloneWithDescriptors(node, options, refs) {
164
- const result = Object.create(Object.getPrototypeOf(node));
165
- refs.set(node, result);
166
- const descs = Object.getOwnPropertyDescriptors(node);
167
- forEachOwnKey(descs, (key) => {
168
- if (isUnsafeKey(key)) {
169
- return;
170
- }
171
- const desc = { ...descs[key] };
172
- if ("value" in desc) {
173
- desc.value = clone(desc.value, options, refs);
174
- }
175
- try {
176
- Object.defineProperty(result, key, desc);
177
- } catch (error) {
178
- if (options.strictDescriptors) {
179
- throw error;
180
- }
181
- }
182
- });
183
- return result;
184
- }
185
187
  function forEachOwnKey(object, fn) {
186
188
  for (const key of Object.keys(object)) {
187
189
  fn(key);
@@ -209,11 +211,12 @@ function isUnsafeKey(key) {
209
211
  * High-performance deep clone utility with descriptor support.
210
212
  * Handles circular ref and complex built-in types.
211
213
  *
212
- * @version 1.1.0
214
+ * @version 1.2.0
213
215
  * @author Yusuke Kamiyamane
214
216
  * @license MIT
215
- * @copyright Copyright (c) 2026 Yusuke Kamiyamane
217
+ * @copyright Copyright (c) Yusuke Kamiyamane
216
218
  * @see {@link https://github.com/y14e/bunshin-clone}
217
219
  */
218
220
 
219
- module.exports = bunshinClone;
221
+ exports.cloneWithDescriptors = cloneWithDescriptors;
222
+ exports.default = bunshinClone;
package/dist/index.d.cts CHANGED
@@ -3,16 +3,19 @@
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.1.0
6
+ * @version 1.2.0
7
7
  * @author Yusuke Kamiyamane
8
8
  * @license MIT
9
- * @copyright Copyright (c) 2026 Yusuke Kamiyamane
9
+ * @copyright Copyright (c) Yusuke Kamiyamane
10
10
  * @see {@link https://github.com/y14e/bunshin-clone}
11
11
  */
12
12
  interface BunshinCloneOptions {
13
13
  readonly preserveDescriptors?: boolean;
14
14
  readonly strictDescriptors?: boolean;
15
15
  }
16
+ type Object$1 = Record<PropertyKey, unknown>;
17
+ type Refs = WeakMap<object, unknown>;
16
18
  declare function bunshinClone<T>(source: T, options?: BunshinCloneOptions): T;
19
+ declare function cloneWithDescriptors<T extends Object$1>(node: T, options: BunshinCloneOptions, refs: Refs): T;
17
20
 
18
- export { type BunshinCloneOptions, bunshinClone as default };
21
+ export { type BunshinCloneOptions, cloneWithDescriptors, bunshinClone as default };
package/dist/index.d.ts CHANGED
@@ -3,16 +3,19 @@
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.1.0
6
+ * @version 1.2.0
7
7
  * @author Yusuke Kamiyamane
8
8
  * @license MIT
9
- * @copyright Copyright (c) 2026 Yusuke Kamiyamane
9
+ * @copyright Copyright (c) Yusuke Kamiyamane
10
10
  * @see {@link https://github.com/y14e/bunshin-clone}
11
11
  */
12
12
  interface BunshinCloneOptions {
13
13
  readonly preserveDescriptors?: boolean;
14
14
  readonly strictDescriptors?: boolean;
15
15
  }
16
+ type Object$1 = Record<PropertyKey, unknown>;
17
+ type Refs = WeakMap<object, unknown>;
16
18
  declare function bunshinClone<T>(source: T, options?: BunshinCloneOptions): T;
19
+ declare function cloneWithDescriptors<T extends Object$1>(node: T, options: BunshinCloneOptions, refs: Refs): T;
17
20
 
18
- export { type BunshinCloneOptions, bunshinClone as default };
21
+ export { type BunshinCloneOptions, cloneWithDescriptors, bunshinClone as default };
package/dist/index.js CHANGED
@@ -4,6 +4,28 @@ var { hasOwnProperty: HAS_OWN } = Object.prototype;
4
4
  function bunshinClone(source, options) {
5
5
  return clone(source, options ?? EMPTY_OPTIONS, /* @__PURE__ */ new WeakMap());
6
6
  }
7
+ function cloneWithDescriptors(node, options, refs) {
8
+ const result = Object.create(Object.getPrototypeOf(node));
9
+ refs.set(node, result);
10
+ const descs = Object.getOwnPropertyDescriptors(node);
11
+ forEachOwnKey(descs, (key) => {
12
+ if (isUnsafeKey(key)) {
13
+ return;
14
+ }
15
+ const desc = { ...descs[key] };
16
+ if ("value" in desc) {
17
+ desc.value = clone(desc.value, options, refs);
18
+ }
19
+ try {
20
+ Object.defineProperty(result, key, desc);
21
+ } catch (error) {
22
+ if (options.strictDescriptors) {
23
+ throw error;
24
+ }
25
+ }
26
+ });
27
+ return result;
28
+ }
7
29
  function clone(node, options, refs) {
8
30
  if (!isObject(node)) {
9
31
  return node;
@@ -158,28 +180,6 @@ function cloneError(value, options, refs) {
158
180
  }
159
181
  return result;
160
182
  }
161
- function cloneWithDescriptors(node, options, refs) {
162
- const result = Object.create(Object.getPrototypeOf(node));
163
- refs.set(node, result);
164
- const descs = Object.getOwnPropertyDescriptors(node);
165
- forEachOwnKey(descs, (key) => {
166
- if (isUnsafeKey(key)) {
167
- return;
168
- }
169
- const desc = { ...descs[key] };
170
- if ("value" in desc) {
171
- desc.value = clone(desc.value, options, refs);
172
- }
173
- try {
174
- Object.defineProperty(result, key, desc);
175
- } catch (error) {
176
- if (options.strictDescriptors) {
177
- throw error;
178
- }
179
- }
180
- });
181
- return result;
182
- }
183
183
  function forEachOwnKey(object, fn) {
184
184
  for (const key of Object.keys(object)) {
185
185
  fn(key);
@@ -207,11 +207,11 @@ 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.1.0
210
+ * @version 1.2.0
211
211
  * @author Yusuke Kamiyamane
212
212
  * @license MIT
213
- * @copyright Copyright (c) 2026 Yusuke Kamiyamane
213
+ * @copyright Copyright (c) Yusuke Kamiyamane
214
214
  * @see {@link https://github.com/y14e/bunshin-clone}
215
215
  */
216
216
 
217
- export { bunshinClone as default };
217
+ export { cloneWithDescriptors, bunshinClone as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bunshin-clone",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "High-performance deep clone utility with descriptor support",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",