bunshin-clone 1.2.11 → 1.2.13

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
@@ -13,11 +13,11 @@ npm i bunshin-clone
13
13
  import { bunshinClone } from 'bunshin-clone';
14
14
 
15
15
  // CDNs
16
- import { bunshinClone } from 'https://esm.sh/bunshin-clone@1.2.11';
16
+ import { bunshinClone } from 'https://esm.sh/bunshin-clone@1.2.13';
17
17
  // or
18
- import { bunshinClone } from 'https://cdn.jsdelivr.net/npm/bunshin-clone@1.2.11/+esm';
18
+ import { bunshinClone } from 'https://cdn.jsdelivr.net/npm/bunshin-clone@1.2.13/+esm';
19
19
  // or
20
- import { bunshinClone } from 'https://esm.unpkg.com/bunshin-clone@1.2.11';
20
+ import { bunshinClone } from 'https://esm.unpkg.com/bunshin-clone@1.2.13';
21
21
  ```
22
22
 
23
23
  ## 📦 APIs
package/dist/index.cjs CHANGED
@@ -80,7 +80,7 @@ function clone(node, options, refs) {
80
80
  refs.set(node, result);
81
81
  return result;
82
82
  }
83
- if (node instanceof Error || node instanceof DOMException) {
83
+ if (node instanceof DOMException || node instanceof Error) {
84
84
  return cloneError(node, options, refs);
85
85
  }
86
86
  if (node instanceof Blob) {
@@ -154,7 +154,7 @@ function cloneError(value, options, refs) {
154
154
  result.cause = clone(cause, options, refs);
155
155
  }
156
156
  for (const key of Object.keys(value)) {
157
- result[key] = clone(value[key], options, refs);
157
+ Reflect.set(result, key, clone(Reflect.get(value, key), options, refs));
158
158
  }
159
159
  return result;
160
160
  }
@@ -180,19 +180,19 @@ function cloneWithDescriptors(node, options, refs) {
180
180
  });
181
181
  return result;
182
182
  }
183
- function forEachOwnKey(object, fn) {
183
+ function forEachOwnKey(object, callback) {
184
184
  for (const key of Object.keys(object)) {
185
- fn(key);
185
+ callback(key);
186
186
  }
187
187
  for (const symbol of Object.getOwnPropertySymbols(object)) {
188
- fn(symbol);
188
+ callback(symbol);
189
189
  }
190
190
  }
191
191
  function isObject(value) {
192
192
  return typeof value === "object" && value !== null;
193
193
  }
194
194
  function isPlainObject(value) {
195
- if (value === null || typeof value !== "object") {
195
+ if (typeof value !== "object" || value === null) {
196
196
  return false;
197
197
  }
198
198
  const proto = Object.getPrototypeOf(value);
@@ -206,7 +206,7 @@ function isUnsafeKey(key) {
206
206
  * High-performance deep clone utility with descriptor support.
207
207
  * Handles circular ref and complex built-in types.
208
208
  *
209
- * @version 1.2.11
209
+ * @version 1.2.13
210
210
  * @author Yusuke Kamiyamane
211
211
  * @license MIT
212
212
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -214,3 +214,7 @@ function isUnsafeKey(key) {
214
214
  */
215
215
 
216
216
  exports.bunshinClone = bunshinClone;
217
+ exports.forEachOwnKey = forEachOwnKey;
218
+ exports.isObject = isObject;
219
+ exports.isPlainObject = isPlainObject;
220
+ exports.isUnsafeKey = isUnsafeKey;
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.11
6
+ * @version 1.2.13
7
7
  * @author Yusuke Kamiyamane
8
8
  * @license MIT
9
9
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -13,7 +13,12 @@ interface BunshinCloneOptions {
13
13
  preserveDescriptors: boolean;
14
14
  strictDescriptors: boolean;
15
15
  }
16
+ type Object$1 = Record<PropertyKey, unknown>;
16
17
  type Refs = WeakMap<object, unknown>;
17
18
  declare function bunshinClone<T>(source: T, options?: Partial<BunshinCloneOptions>, refs?: Refs): T;
19
+ declare function forEachOwnKey(object: Object$1, callback: (key: string | symbol) => void): void;
20
+ declare function isObject(value: unknown): value is Object$1;
21
+ declare function isPlainObject(value: unknown): boolean;
22
+ declare function isUnsafeKey(key: PropertyKey): boolean;
18
23
 
19
- export { type BunshinCloneOptions, bunshinClone };
24
+ export { type BunshinCloneOptions, bunshinClone, forEachOwnKey, isObject, isPlainObject, isUnsafeKey };
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.11
6
+ * @version 1.2.13
7
7
  * @author Yusuke Kamiyamane
8
8
  * @license MIT
9
9
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -13,7 +13,12 @@ interface BunshinCloneOptions {
13
13
  preserveDescriptors: boolean;
14
14
  strictDescriptors: boolean;
15
15
  }
16
+ type Object$1 = Record<PropertyKey, unknown>;
16
17
  type Refs = WeakMap<object, unknown>;
17
18
  declare function bunshinClone<T>(source: T, options?: Partial<BunshinCloneOptions>, refs?: Refs): T;
19
+ declare function forEachOwnKey(object: Object$1, callback: (key: string | symbol) => void): void;
20
+ declare function isObject(value: unknown): value is Object$1;
21
+ declare function isPlainObject(value: unknown): boolean;
22
+ declare function isUnsafeKey(key: PropertyKey): boolean;
18
23
 
19
- export { type BunshinCloneOptions, bunshinClone };
24
+ export { type BunshinCloneOptions, bunshinClone, forEachOwnKey, isObject, isPlainObject, isUnsafeKey };
package/dist/index.js CHANGED
@@ -78,7 +78,7 @@ function clone(node, options, refs) {
78
78
  refs.set(node, result);
79
79
  return result;
80
80
  }
81
- if (node instanceof Error || node instanceof DOMException) {
81
+ if (node instanceof DOMException || node instanceof Error) {
82
82
  return cloneError(node, options, refs);
83
83
  }
84
84
  if (node instanceof Blob) {
@@ -152,7 +152,7 @@ function cloneError(value, options, refs) {
152
152
  result.cause = clone(cause, options, refs);
153
153
  }
154
154
  for (const key of Object.keys(value)) {
155
- result[key] = clone(value[key], options, refs);
155
+ Reflect.set(result, key, clone(Reflect.get(value, key), options, refs));
156
156
  }
157
157
  return result;
158
158
  }
@@ -178,19 +178,19 @@ function cloneWithDescriptors(node, options, refs) {
178
178
  });
179
179
  return result;
180
180
  }
181
- function forEachOwnKey(object, fn) {
181
+ function forEachOwnKey(object, callback) {
182
182
  for (const key of Object.keys(object)) {
183
- fn(key);
183
+ callback(key);
184
184
  }
185
185
  for (const symbol of Object.getOwnPropertySymbols(object)) {
186
- fn(symbol);
186
+ callback(symbol);
187
187
  }
188
188
  }
189
189
  function isObject(value) {
190
190
  return typeof value === "object" && value !== null;
191
191
  }
192
192
  function isPlainObject(value) {
193
- if (value === null || typeof value !== "object") {
193
+ if (typeof value !== "object" || value === null) {
194
194
  return false;
195
195
  }
196
196
  const proto = Object.getPrototypeOf(value);
@@ -204,11 +204,11 @@ function isUnsafeKey(key) {
204
204
  * High-performance deep clone utility with descriptor support.
205
205
  * Handles circular ref and complex built-in types.
206
206
  *
207
- * @version 1.2.11
207
+ * @version 1.2.13
208
208
  * @author Yusuke Kamiyamane
209
209
  * @license MIT
210
210
  * @copyright Copyright (c) Yusuke Kamiyamane
211
211
  * @see {@link https://github.com/y14e/bunshin-clone}
212
212
  */
213
213
 
214
- export { bunshinClone };
214
+ export { bunshinClone, forEachOwnKey, isObject, isPlainObject, isUnsafeKey };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bunshin-clone",
3
- "version": "1.2.11",
3
+ "version": "1.2.13",
4
4
  "description": "High-performance deep clone utility with descriptor support",
5
5
  "keywords": [
6
6
  "array",