bunshin-clone 1.8.5 → 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) {
@@ -42,9 +43,10 @@ function clone(value, settings, refs) {
42
43
  return result;
43
44
  }
44
45
  if (value instanceof RegExp) {
45
- const result = new RegExp(value.source, value.flags);
46
+ const { source, flags, lastIndex } = value;
47
+ const result = new RegExp(source, flags);
46
48
  refs.set(value, result);
47
- result.lastIndex = value.lastIndex;
49
+ result.lastIndex = lastIndex;
48
50
  return result;
49
51
  }
50
52
  if (value instanceof ArrayBuffer) {
@@ -63,7 +65,8 @@ function clone(value, settings, refs) {
63
65
  return cloneError(value, settings, refs);
64
66
  }
65
67
  if (value instanceof Blob) {
66
- const result = value.slice(0, value.size, value.type);
68
+ const { size, type } = value;
69
+ const result = value.slice(0, size, type);
67
70
  refs.set(value, result);
68
71
  return result;
69
72
  }
@@ -114,7 +117,7 @@ function cloneWithDescriptors(object, settings, refs) {
114
117
  return result;
115
118
  }
116
119
  function cloneArray(array, settings, refs) {
117
- if (array.every((item) => !isObject(item))) {
120
+ if (isPrimitiveArray(array)) {
118
121
  const result2 = array.slice();
119
122
  refs.set(array, result2);
120
123
  return result2;
@@ -244,6 +247,9 @@ function isPlainObject(value) {
244
247
  const proto = Object.getPrototypeOf(value);
245
248
  return proto === Object.prototype || proto === null;
246
249
  }
250
+ function isPrimitiveArray(array) {
251
+ return array.every((item) => !isObject(item));
252
+ }
247
253
  function isUnsafeKey(key) {
248
254
  return typeof key === "string" && (key === "__proto__" || key === "prototype" || key === "constructor");
249
255
  }
@@ -282,4 +288,5 @@ exports.bunshinClone = bunshinClone;
282
288
  exports.forEachOwnKey = forEachOwnKey;
283
289
  exports.isObject = isObject;
284
290
  exports.isPlainObject = isPlainObject;
291
+ exports.isPrimitiveArray = isPrimitiveArray;
285
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) {
@@ -40,9 +41,10 @@ function clone(value, settings, refs) {
40
41
  return result;
41
42
  }
42
43
  if (value instanceof RegExp) {
43
- const result = new RegExp(value.source, value.flags);
44
+ const { source, flags, lastIndex } = value;
45
+ const result = new RegExp(source, flags);
44
46
  refs.set(value, result);
45
- result.lastIndex = value.lastIndex;
47
+ result.lastIndex = lastIndex;
46
48
  return result;
47
49
  }
48
50
  if (value instanceof ArrayBuffer) {
@@ -61,7 +63,8 @@ function clone(value, settings, refs) {
61
63
  return cloneError(value, settings, refs);
62
64
  }
63
65
  if (value instanceof Blob) {
64
- const result = value.slice(0, value.size, value.type);
66
+ const { size, type } = value;
67
+ const result = value.slice(0, size, type);
65
68
  refs.set(value, result);
66
69
  return result;
67
70
  }
@@ -112,7 +115,7 @@ function cloneWithDescriptors(object, settings, refs) {
112
115
  return result;
113
116
  }
114
117
  function cloneArray(array, settings, refs) {
115
- if (array.every((item) => !isObject(item))) {
118
+ if (isPrimitiveArray(array)) {
116
119
  const result2 = array.slice();
117
120
  refs.set(array, result2);
118
121
  return result2;
@@ -242,6 +245,9 @@ function isPlainObject(value) {
242
245
  const proto = Object.getPrototypeOf(value);
243
246
  return proto === Object.prototype || proto === null;
244
247
  }
248
+ function isPrimitiveArray(array) {
249
+ return array.every((item) => !isObject(item));
250
+ }
245
251
  function isUnsafeKey(key) {
246
252
  return typeof key === "string" && (key === "__proto__" || key === "prototype" || key === "constructor");
247
253
  }
@@ -276,4 +282,4 @@ function resolveOptions(options) {
276
282
  };
277
283
  }
278
284
 
279
- 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.5",
3
+ "version": "1.8.7",
4
4
  "description": "High-performance deep clone utility with descriptor support",
5
5
  "keywords": [
6
6
  "array",
@@ -60,9 +60,9 @@
60
60
  ],
61
61
  "scripts": {
62
62
  "bench": "bun tsup & npm run bench:install & npm run bench:run & npm run bench:uninstall",
63
- "bench:install": "npm i bunshin-clone-npm@npm:bunshin-clone klona lodash.clonedeep @types/lodash.clonedeep rfdc tinybench",
63
+ "bench:install": "npm i bunshin-clone-npm@npm:bunshin-clone lodash.clonedeep @types/lodash.clonedeep tinybench",
64
64
  "bench:run": "node ./benchmark/run.ts",
65
- "bench:uninstall": "npm un bunshin-clone-npm klona lodash.clonedeep @types/lodash.clonedeep rfdc tinybench",
65
+ "bench:uninstall": "npm un bunshin-clone-npm lodash.clonedeep @types/lodash.clonedeep tinybench",
66
66
  "build": "tsup",
67
67
  "lint": "tsc --noEmit",
68
68
  "prepublishOnly": "npm run build",