bunshin-clone 1.8.6 → 1.8.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
@@ -11,13 +11,14 @@ function clone(value, settings, refs) {
11
11
  if (refs.has(value)) {
12
12
  return refs.get(value);
13
13
  }
14
- if (settings.preserveDescriptors && isPlainObject(value)) {
14
+ const isClonePlainObject = isPlainObject(value);
15
+ if (settings.preserveDescriptors && isClonePlainObject) {
15
16
  return cloneWithDescriptors(value, settings, refs);
16
17
  }
17
18
  if (Array.isArray(value)) {
18
19
  return cloneArray(value, settings, refs);
19
20
  }
20
- if (isPlainObject(value)) {
21
+ if (isClonePlainObject) {
21
22
  return clonePlainObject(value, settings, refs);
22
23
  }
23
24
  if (value instanceof Map) {
@@ -116,7 +117,7 @@ function cloneWithDescriptors(object, settings, refs) {
116
117
  return result;
117
118
  }
118
119
  function cloneArray(array, settings, refs) {
119
- if (array.every((item) => !isObject(item))) {
120
+ if (isPrimitiveArray(array)) {
120
121
  const result2 = array.slice();
121
122
  refs.set(array, result2);
122
123
  return result2;
@@ -246,6 +247,9 @@ function isPlainObject(value) {
246
247
  const proto = Object.getPrototypeOf(value);
247
248
  return proto === Object.prototype || proto === null;
248
249
  }
250
+ function isPrimitiveArray(array) {
251
+ return array.every((item) => !isObject(item));
252
+ }
249
253
  function isUnsafeKey(key) {
250
254
  return typeof key === "string" && (key === "__proto__" || key === "prototype" || key === "constructor");
251
255
  }
@@ -284,4 +288,5 @@ exports.bunshinClone = bunshinClone;
284
288
  exports.forEachOwnKey = forEachOwnKey;
285
289
  exports.isObject = isObject;
286
290
  exports.isPlainObject = isPlainObject;
291
+ exports.isPrimitiveArray = isPrimitiveArray;
287
292
  exports.isUnsafeKey = isUnsafeKey;
package/dist/index.d.cts CHANGED
@@ -10,6 +10,7 @@ declare function bunshinClone<T>(value: T, options?: Partial<BunshinCloneOptions
10
10
  declare function forEachOwnKey(object: PlainObject, callback: (key: string | symbol) => void): void;
11
11
  declare function isObject(value: unknown): value is object;
12
12
  declare function isPlainObject(value: unknown): value is PlainObject;
13
+ declare function isPrimitiveArray(array: unknown[]): boolean;
13
14
  declare function isUnsafeKey(key: PropertyKey): boolean;
14
15
 
15
- export { type BunshinCloneOptions, bunshinClone, forEachOwnKey, isObject, isPlainObject, isUnsafeKey };
16
+ export { type BunshinCloneOptions, type PlainObject, bunshinClone, forEachOwnKey, isObject, isPlainObject, isPrimitiveArray, isUnsafeKey };
package/dist/index.d.ts CHANGED
@@ -10,6 +10,7 @@ declare function bunshinClone<T>(value: T, options?: Partial<BunshinCloneOptions
10
10
  declare function forEachOwnKey(object: PlainObject, callback: (key: string | symbol) => void): void;
11
11
  declare function isObject(value: unknown): value is object;
12
12
  declare function isPlainObject(value: unknown): value is PlainObject;
13
+ declare function isPrimitiveArray(array: unknown[]): boolean;
13
14
  declare function isUnsafeKey(key: PropertyKey): boolean;
14
15
 
15
- export { type BunshinCloneOptions, bunshinClone, forEachOwnKey, isObject, isPlainObject, isUnsafeKey };
16
+ export { type BunshinCloneOptions, type PlainObject, bunshinClone, forEachOwnKey, isObject, isPlainObject, isPrimitiveArray, isUnsafeKey };
package/dist/index.js CHANGED
@@ -9,13 +9,14 @@ function clone(value, settings, refs) {
9
9
  if (refs.has(value)) {
10
10
  return refs.get(value);
11
11
  }
12
- if (settings.preserveDescriptors && isPlainObject(value)) {
12
+ const isClonePlainObject = isPlainObject(value);
13
+ if (settings.preserveDescriptors && isClonePlainObject) {
13
14
  return cloneWithDescriptors(value, settings, refs);
14
15
  }
15
16
  if (Array.isArray(value)) {
16
17
  return cloneArray(value, settings, refs);
17
18
  }
18
- if (isPlainObject(value)) {
19
+ if (isClonePlainObject) {
19
20
  return clonePlainObject(value, settings, refs);
20
21
  }
21
22
  if (value instanceof Map) {
@@ -114,7 +115,7 @@ function cloneWithDescriptors(object, settings, refs) {
114
115
  return result;
115
116
  }
116
117
  function cloneArray(array, settings, refs) {
117
- if (array.every((item) => !isObject(item))) {
118
+ if (isPrimitiveArray(array)) {
118
119
  const result2 = array.slice();
119
120
  refs.set(array, result2);
120
121
  return result2;
@@ -244,6 +245,9 @@ function isPlainObject(value) {
244
245
  const proto = Object.getPrototypeOf(value);
245
246
  return proto === Object.prototype || proto === null;
246
247
  }
248
+ function isPrimitiveArray(array) {
249
+ return array.every((item) => !isObject(item));
250
+ }
247
251
  function isUnsafeKey(key) {
248
252
  return typeof key === "string" && (key === "__proto__" || key === "prototype" || key === "constructor");
249
253
  }
@@ -278,4 +282,4 @@ function resolveOptions(options) {
278
282
  };
279
283
  }
280
284
 
281
- export { bunshinClone, forEachOwnKey, isObject, isPlainObject, isUnsafeKey };
285
+ export { bunshinClone, forEachOwnKey, isObject, isPlainObject, isPrimitiveArray, isUnsafeKey };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bunshin-clone",
3
- "version": "1.8.6",
3
+ "version": "1.8.7",
4
4
  "description": "High-performance deep clone utility with descriptor support",
5
5
  "keywords": [
6
6
  "array",