bunshin-clone 1.0.5 → 1.0.7

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,7 +1,5 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  // src/index.ts
6
4
  var EMPTY_OPTIONS = {};
7
5
  var { hasOwnProperty: HAS_OWN } = Object.prototype;
@@ -9,7 +7,7 @@ var { toString: OBJECT_TO_STRING } = Object.prototype;
9
7
  function bunshinClone(source, options) {
10
8
  return clone(source, options ?? EMPTY_OPTIONS, /* @__PURE__ */ new WeakMap());
11
9
  }
12
- function clone(node, options = EMPTY_OPTIONS, ref = /* @__PURE__ */ new WeakMap()) {
10
+ function clone(node, options, ref) {
13
11
  if (!isObject(node)) {
14
12
  return node;
15
13
  }
@@ -72,17 +70,16 @@ function clone(node, options = EMPTY_OPTIONS, ref = /* @__PURE__ */ new WeakMap(
72
70
  return result;
73
71
  }
74
72
  if (ArrayBuffer.isView(node)) {
73
+ const { buffer, byteOffset, byteLength } = node;
75
74
  if (node instanceof DataView) {
76
- const result = new DataView(
77
- node.buffer.slice(0),
78
- node.byteOffset,
79
- node.byteLength
80
- );
75
+ const result = new DataView(buffer.slice(0), byteOffset, byteLength);
81
76
  ref.set(node, result);
82
77
  return result;
83
78
  } else {
84
79
  const Ctor = node.constructor;
85
- const result = new Ctor(node);
80
+ const result = new Ctor(
81
+ buffer.slice(byteOffset, byteOffset + byteLength)
82
+ );
86
83
  ref.set(node, result);
87
84
  return result;
88
85
  }
@@ -144,7 +141,10 @@ function cloneError(value, options, ref) {
144
141
  result.name = name;
145
142
  }
146
143
  if (!options.preserveDescriptors && "cause" in value) {
147
- result.cause = clone(result.cause, options, ref);
144
+ const cause = value.cause;
145
+ if (cause !== void 0) {
146
+ result.cause = clone(cause, options, ref);
147
+ }
148
148
  }
149
149
  if (value.stack) {
150
150
  result.stack = value.stack;
@@ -195,13 +195,11 @@ function isUnsafeKey(key) {
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.5
198
+ * @version 1.0.7
199
199
  * @author Yusuke Kamiyamane
200
200
  * @license MIT
201
201
  * @copyright Copyright (c) 2026 Yusuke Kamiyamane
202
202
  * @see {@link https://github.com/y14e/bunshin-clone}
203
203
  */
204
204
 
205
- exports.clone = clone;
206
- exports.cloneWithDescriptors = cloneWithDescriptors;
207
- exports.default = bunshinClone;
205
+ module.exports = bunshinClone;
package/dist/index.d.cts CHANGED
@@ -3,7 +3,7 @@
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.5
6
+ * @version 1.0.7
7
7
  * @author Yusuke Kamiyamane
8
8
  * @license MIT
9
9
  * @copyright Copyright (c) 2026 Yusuke Kamiyamane
@@ -13,10 +13,6 @@ interface BunshinCloneOptions {
13
13
  readonly preserveDescriptors?: boolean;
14
14
  readonly strictDescriptors?: boolean;
15
15
  }
16
- type Ref = WeakMap<object, unknown>;
17
- type AnyObject = Record<PropertyKey, unknown>;
18
16
  declare function bunshinClone<T>(source: T, options?: BunshinCloneOptions): T;
19
- declare function clone<T>(node: T, options?: BunshinCloneOptions, ref?: Ref): T;
20
- declare function cloneWithDescriptors(node: AnyObject, options: BunshinCloneOptions, ref: Ref): AnyObject;
21
17
 
22
- export { type BunshinCloneOptions, clone, cloneWithDescriptors, bunshinClone as default };
18
+ export { type BunshinCloneOptions, bunshinClone as default };
package/dist/index.d.ts CHANGED
@@ -3,7 +3,7 @@
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.5
6
+ * @version 1.0.7
7
7
  * @author Yusuke Kamiyamane
8
8
  * @license MIT
9
9
  * @copyright Copyright (c) 2026 Yusuke Kamiyamane
@@ -13,10 +13,6 @@ interface BunshinCloneOptions {
13
13
  readonly preserveDescriptors?: boolean;
14
14
  readonly strictDescriptors?: boolean;
15
15
  }
16
- type Ref = WeakMap<object, unknown>;
17
- type AnyObject = Record<PropertyKey, unknown>;
18
16
  declare function bunshinClone<T>(source: T, options?: BunshinCloneOptions): T;
19
- declare function clone<T>(node: T, options?: BunshinCloneOptions, ref?: Ref): T;
20
- declare function cloneWithDescriptors(node: AnyObject, options: BunshinCloneOptions, ref: Ref): AnyObject;
21
17
 
22
- export { type BunshinCloneOptions, clone, cloneWithDescriptors, bunshinClone as default };
18
+ export { type BunshinCloneOptions, bunshinClone as default };
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ var { toString: OBJECT_TO_STRING } = Object.prototype;
5
5
  function bunshinClone(source, options) {
6
6
  return clone(source, options ?? EMPTY_OPTIONS, /* @__PURE__ */ new WeakMap());
7
7
  }
8
- function clone(node, options = EMPTY_OPTIONS, ref = /* @__PURE__ */ new WeakMap()) {
8
+ function clone(node, options, ref) {
9
9
  if (!isObject(node)) {
10
10
  return node;
11
11
  }
@@ -68,17 +68,16 @@ function clone(node, options = EMPTY_OPTIONS, ref = /* @__PURE__ */ new WeakMap(
68
68
  return result;
69
69
  }
70
70
  if (ArrayBuffer.isView(node)) {
71
+ const { buffer, byteOffset, byteLength } = node;
71
72
  if (node instanceof DataView) {
72
- const result = new DataView(
73
- node.buffer.slice(0),
74
- node.byteOffset,
75
- node.byteLength
76
- );
73
+ const result = new DataView(buffer.slice(0), byteOffset, byteLength);
77
74
  ref.set(node, result);
78
75
  return result;
79
76
  } else {
80
77
  const Ctor = node.constructor;
81
- const result = new Ctor(node);
78
+ const result = new Ctor(
79
+ buffer.slice(byteOffset, byteOffset + byteLength)
80
+ );
82
81
  ref.set(node, result);
83
82
  return result;
84
83
  }
@@ -140,7 +139,10 @@ function cloneError(value, options, ref) {
140
139
  result.name = name;
141
140
  }
142
141
  if (!options.preserveDescriptors && "cause" in value) {
143
- result.cause = clone(result.cause, options, ref);
142
+ const cause = value.cause;
143
+ if (cause !== void 0) {
144
+ result.cause = clone(cause, options, ref);
145
+ }
144
146
  }
145
147
  if (value.stack) {
146
148
  result.stack = value.stack;
@@ -191,11 +193,11 @@ function isUnsafeKey(key) {
191
193
  * High-performance deep clone utility with descriptor support.
192
194
  * Supports circular ref and complex built-in types.
193
195
  *
194
- * @version 1.0.5
196
+ * @version 1.0.7
195
197
  * @author Yusuke Kamiyamane
196
198
  * @license MIT
197
199
  * @copyright Copyright (c) 2026 Yusuke Kamiyamane
198
200
  * @see {@link https://github.com/y14e/bunshin-clone}
199
201
  */
200
202
 
201
- export { clone, cloneWithDescriptors, bunshinClone as default };
203
+ export { bunshinClone as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bunshin-clone",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "High-performance deep clone utility with descriptor support",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",