bunshin-clone 1.8.3 → 1.8.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/README.md CHANGED
@@ -55,7 +55,7 @@ If `true`, preserves symbol keys (slower).
55
55
 
56
56
  ### `strictDescriptors`
57
57
 
58
- If `true`, throws if descriptor cannot be merged (e.g. non-configurable or non-writable).
58
+ If `true`, throws if property descriptor cannot be copied (e.g. non-configurable or non-writable).
59
59
 
60
60
  ## 📖 Details
61
61
 
package/dist/index.cjs CHANGED
@@ -114,7 +114,7 @@ function cloneWithDescriptors(object, settings, refs) {
114
114
  return result;
115
115
  }
116
116
  function cloneArray(array, settings, refs) {
117
- if (isShallowArray(array)) {
117
+ if (array.every((item) => !isObject(item))) {
118
118
  const result2 = array.slice();
119
119
  refs.set(array, result2);
120
120
  return result2;
@@ -139,7 +139,7 @@ function clonePlainObject(object, settings, refs) {
139
139
  }
140
140
  } else {
141
141
  for (const key of Reflect.ownKeys(object)) {
142
- if (isUnsafeKey(key) || !Object.propertyIsEnumerable.call(object, key)) {
142
+ if (isUnsafeKey(key) || !Object.prototype.propertyIsEnumerable.call(object, key)) {
143
143
  continue;
144
144
  }
145
145
  result[key] = clone(object[key], settings, refs);
@@ -244,9 +244,6 @@ function isPlainObject(value) {
244
244
  const proto = Object.getPrototypeOf(value);
245
245
  return proto === Object.prototype || proto === null;
246
246
  }
247
- function isShallowArray(array) {
248
- return array.every((item) => !isObject(item));
249
- }
250
247
  function isUnsafeKey(key) {
251
248
  return typeof key === "string" && (key === "__proto__" || key === "prototype" || key === "constructor");
252
249
  }
@@ -285,5 +282,4 @@ exports.bunshinClone = bunshinClone;
285
282
  exports.forEachOwnKey = forEachOwnKey;
286
283
  exports.isObject = isObject;
287
284
  exports.isPlainObject = isPlainObject;
288
- exports.isShallowArray = isShallowArray;
289
285
  exports.isUnsafeKey = isUnsafeKey;
package/dist/index.d.cts CHANGED
@@ -10,7 +10,6 @@ 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 isShallowArray(array: unknown[]): boolean;
14
13
  declare function isUnsafeKey(key: PropertyKey): boolean;
15
14
 
16
- export { type BunshinCloneOptions, bunshinClone, forEachOwnKey, isObject, isPlainObject, isShallowArray, isUnsafeKey };
15
+ export { type BunshinCloneOptions, bunshinClone, forEachOwnKey, isObject, isPlainObject, isUnsafeKey };
package/dist/index.d.ts CHANGED
@@ -10,7 +10,6 @@ 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 isShallowArray(array: unknown[]): boolean;
14
13
  declare function isUnsafeKey(key: PropertyKey): boolean;
15
14
 
16
- export { type BunshinCloneOptions, bunshinClone, forEachOwnKey, isObject, isPlainObject, isShallowArray, isUnsafeKey };
15
+ export { type BunshinCloneOptions, bunshinClone, forEachOwnKey, isObject, isPlainObject, isUnsafeKey };
package/dist/index.js CHANGED
@@ -112,7 +112,7 @@ function cloneWithDescriptors(object, settings, refs) {
112
112
  return result;
113
113
  }
114
114
  function cloneArray(array, settings, refs) {
115
- if (isShallowArray(array)) {
115
+ if (array.every((item) => !isObject(item))) {
116
116
  const result2 = array.slice();
117
117
  refs.set(array, result2);
118
118
  return result2;
@@ -137,7 +137,7 @@ function clonePlainObject(object, settings, refs) {
137
137
  }
138
138
  } else {
139
139
  for (const key of Reflect.ownKeys(object)) {
140
- if (isUnsafeKey(key) || !Object.propertyIsEnumerable.call(object, key)) {
140
+ if (isUnsafeKey(key) || !Object.prototype.propertyIsEnumerable.call(object, key)) {
141
141
  continue;
142
142
  }
143
143
  result[key] = clone(object[key], settings, refs);
@@ -242,9 +242,6 @@ function isPlainObject(value) {
242
242
  const proto = Object.getPrototypeOf(value);
243
243
  return proto === Object.prototype || proto === null;
244
244
  }
245
- function isShallowArray(array) {
246
- return array.every((item) => !isObject(item));
247
- }
248
245
  function isUnsafeKey(key) {
249
246
  return typeof key === "string" && (key === "__proto__" || key === "prototype" || key === "constructor");
250
247
  }
@@ -279,4 +276,4 @@ function resolveOptions(options) {
279
276
  };
280
277
  }
281
278
 
282
- export { bunshinClone, forEachOwnKey, isObject, isPlainObject, isShallowArray, isUnsafeKey };
279
+ export { bunshinClone, forEachOwnKey, isObject, isPlainObject, isUnsafeKey };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bunshin-clone",
3
- "version": "1.8.3",
3
+ "version": "1.8.5",
4
4
  "description": "High-performance deep clone utility with descriptor support",
5
5
  "keywords": [
6
6
  "array",
@@ -59,9 +59,14 @@
59
59
  "README.md"
60
60
  ],
61
61
  "scripts": {
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",
64
+ "bench:run": "node ./benchmark/run.ts",
65
+ "bench:uninstall": "npm un bunshin-clone-npm klona lodash.clonedeep @types/lodash.clonedeep rfdc tinybench",
62
66
  "build": "tsup",
63
67
  "lint": "tsc --noEmit",
64
- "prepublishOnly": "npm run build"
68
+ "prepublishOnly": "npm run build",
69
+ "test": "bun test"
65
70
  },
66
71
  "devDependencies": {
67
72
  "bun-types": "latest",