bunshin-clone 1.0.3 → 1.0.5

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
@@ -6,10 +6,10 @@ Object.defineProperty(exports, '__esModule', { value: true });
6
6
  var EMPTY_OPTIONS = {};
7
7
  var { hasOwnProperty: HAS_OWN } = Object.prototype;
8
8
  var { toString: OBJECT_TO_STRING } = Object.prototype;
9
- function bunshinClone(source, options, ref) {
10
- return clone(source, options ?? EMPTY_OPTIONS, ref ?? /* @__PURE__ */ new WeakMap());
9
+ function bunshinClone(source, options) {
10
+ return clone(source, options ?? EMPTY_OPTIONS, /* @__PURE__ */ new WeakMap());
11
11
  }
12
- function clone(node, options, ref) {
12
+ function clone(node, options = EMPTY_OPTIONS, ref = /* @__PURE__ */ new WeakMap()) {
13
13
  if (!isObject(node)) {
14
14
  return node;
15
15
  }
@@ -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;
@@ -195,12 +195,13 @@ 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.3
198
+ * @version 1.0.5
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;
205
206
  exports.cloneWithDescriptors = cloneWithDescriptors;
206
207
  exports.default = 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.3
6
+ * @version 1.0.5
7
7
  * @author Yusuke Kamiyamane
8
8
  * @license MIT
9
9
  * @copyright Copyright (c) 2026 Yusuke Kamiyamane
@@ -15,7 +15,8 @@ interface BunshinCloneOptions {
15
15
  }
16
16
  type Ref = WeakMap<object, unknown>;
17
17
  type AnyObject = Record<PropertyKey, unknown>;
18
- declare function bunshinClone(source: unknown, options?: BunshinCloneOptions, ref?: Ref): unknown;
18
+ declare function bunshinClone<T>(source: T, options?: BunshinCloneOptions): T;
19
+ declare function clone<T>(node: T, options?: BunshinCloneOptions, ref?: Ref): T;
19
20
  declare function cloneWithDescriptors(node: AnyObject, options: BunshinCloneOptions, ref: Ref): AnyObject;
20
21
 
21
- export { type BunshinCloneOptions, cloneWithDescriptors, bunshinClone as default };
22
+ export { type BunshinCloneOptions, clone, cloneWithDescriptors, 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.3
6
+ * @version 1.0.5
7
7
  * @author Yusuke Kamiyamane
8
8
  * @license MIT
9
9
  * @copyright Copyright (c) 2026 Yusuke Kamiyamane
@@ -15,7 +15,8 @@ interface BunshinCloneOptions {
15
15
  }
16
16
  type Ref = WeakMap<object, unknown>;
17
17
  type AnyObject = Record<PropertyKey, unknown>;
18
- declare function bunshinClone(source: unknown, options?: BunshinCloneOptions, ref?: Ref): unknown;
18
+ declare function bunshinClone<T>(source: T, options?: BunshinCloneOptions): T;
19
+ declare function clone<T>(node: T, options?: BunshinCloneOptions, ref?: Ref): T;
19
20
  declare function cloneWithDescriptors(node: AnyObject, options: BunshinCloneOptions, ref: Ref): AnyObject;
20
21
 
21
- export { type BunshinCloneOptions, cloneWithDescriptors, bunshinClone as default };
22
+ export { type BunshinCloneOptions, clone, cloneWithDescriptors, bunshinClone as default };
package/dist/index.js CHANGED
@@ -2,10 +2,10 @@
2
2
  var EMPTY_OPTIONS = {};
3
3
  var { hasOwnProperty: HAS_OWN } = Object.prototype;
4
4
  var { toString: OBJECT_TO_STRING } = Object.prototype;
5
- function bunshinClone(source, options, ref) {
6
- return clone(source, options ?? EMPTY_OPTIONS, ref ?? /* @__PURE__ */ new WeakMap());
5
+ function bunshinClone(source, options) {
6
+ return clone(source, options ?? EMPTY_OPTIONS, /* @__PURE__ */ new WeakMap());
7
7
  }
8
- function clone(node, options, ref) {
8
+ function clone(node, options = EMPTY_OPTIONS, ref = /* @__PURE__ */ new WeakMap()) {
9
9
  if (!isObject(node)) {
10
10
  return node;
11
11
  }
@@ -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;
@@ -191,11 +191,11 @@ function isUnsafeKey(key) {
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.3
194
+ * @version 1.0.5
195
195
  * @author Yusuke Kamiyamane
196
196
  * @license MIT
197
197
  * @copyright Copyright (c) 2026 Yusuke Kamiyamane
198
198
  * @see {@link https://github.com/y14e/bunshin-clone}
199
199
  */
200
200
 
201
- export { cloneWithDescriptors, bunshinClone as default };
201
+ export { clone, cloneWithDescriptors, bunshinClone as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bunshin-clone",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "High-performance deep clone utility with descriptor support",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",