bunshin-clone 1.8.4 → 1.8.6
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 +1 -1
- package/dist/index.cjs +6 -8
- package/dist/index.d.cts +1 -2
- package/dist/index.d.ts +1 -2
- package/dist/index.js +7 -8
- package/package.json +7 -2
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
|
|
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
|
@@ -42,9 +42,10 @@ function clone(value, settings, refs) {
|
|
|
42
42
|
return result;
|
|
43
43
|
}
|
|
44
44
|
if (value instanceof RegExp) {
|
|
45
|
-
const
|
|
45
|
+
const { source, flags, lastIndex } = value;
|
|
46
|
+
const result = new RegExp(source, flags);
|
|
46
47
|
refs.set(value, result);
|
|
47
|
-
result.lastIndex =
|
|
48
|
+
result.lastIndex = lastIndex;
|
|
48
49
|
return result;
|
|
49
50
|
}
|
|
50
51
|
if (value instanceof ArrayBuffer) {
|
|
@@ -63,7 +64,8 @@ function clone(value, settings, refs) {
|
|
|
63
64
|
return cloneError(value, settings, refs);
|
|
64
65
|
}
|
|
65
66
|
if (value instanceof Blob) {
|
|
66
|
-
const
|
|
67
|
+
const { size, type } = value;
|
|
68
|
+
const result = value.slice(0, size, type);
|
|
67
69
|
refs.set(value, result);
|
|
68
70
|
return result;
|
|
69
71
|
}
|
|
@@ -114,7 +116,7 @@ function cloneWithDescriptors(object, settings, refs) {
|
|
|
114
116
|
return result;
|
|
115
117
|
}
|
|
116
118
|
function cloneArray(array, settings, refs) {
|
|
117
|
-
if (
|
|
119
|
+
if (array.every((item) => !isObject(item))) {
|
|
118
120
|
const result2 = array.slice();
|
|
119
121
|
refs.set(array, result2);
|
|
120
122
|
return result2;
|
|
@@ -244,9 +246,6 @@ function isPlainObject(value) {
|
|
|
244
246
|
const proto = Object.getPrototypeOf(value);
|
|
245
247
|
return proto === Object.prototype || proto === null;
|
|
246
248
|
}
|
|
247
|
-
function isShallowArray(array) {
|
|
248
|
-
return array.every((item) => !isObject(item));
|
|
249
|
-
}
|
|
250
249
|
function isUnsafeKey(key) {
|
|
251
250
|
return typeof key === "string" && (key === "__proto__" || key === "prototype" || key === "constructor");
|
|
252
251
|
}
|
|
@@ -285,5 +284,4 @@ exports.bunshinClone = bunshinClone;
|
|
|
285
284
|
exports.forEachOwnKey = forEachOwnKey;
|
|
286
285
|
exports.isObject = isObject;
|
|
287
286
|
exports.isPlainObject = isPlainObject;
|
|
288
|
-
exports.isShallowArray = isShallowArray;
|
|
289
287
|
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,
|
|
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,
|
|
15
|
+
export { type BunshinCloneOptions, bunshinClone, forEachOwnKey, isObject, isPlainObject, isUnsafeKey };
|
package/dist/index.js
CHANGED
|
@@ -40,9 +40,10 @@ function clone(value, settings, refs) {
|
|
|
40
40
|
return result;
|
|
41
41
|
}
|
|
42
42
|
if (value instanceof RegExp) {
|
|
43
|
-
const
|
|
43
|
+
const { source, flags, lastIndex } = value;
|
|
44
|
+
const result = new RegExp(source, flags);
|
|
44
45
|
refs.set(value, result);
|
|
45
|
-
result.lastIndex =
|
|
46
|
+
result.lastIndex = lastIndex;
|
|
46
47
|
return result;
|
|
47
48
|
}
|
|
48
49
|
if (value instanceof ArrayBuffer) {
|
|
@@ -61,7 +62,8 @@ function clone(value, settings, refs) {
|
|
|
61
62
|
return cloneError(value, settings, refs);
|
|
62
63
|
}
|
|
63
64
|
if (value instanceof Blob) {
|
|
64
|
-
const
|
|
65
|
+
const { size, type } = value;
|
|
66
|
+
const result = value.slice(0, size, type);
|
|
65
67
|
refs.set(value, result);
|
|
66
68
|
return result;
|
|
67
69
|
}
|
|
@@ -112,7 +114,7 @@ function cloneWithDescriptors(object, settings, refs) {
|
|
|
112
114
|
return result;
|
|
113
115
|
}
|
|
114
116
|
function cloneArray(array, settings, refs) {
|
|
115
|
-
if (
|
|
117
|
+
if (array.every((item) => !isObject(item))) {
|
|
116
118
|
const result2 = array.slice();
|
|
117
119
|
refs.set(array, result2);
|
|
118
120
|
return result2;
|
|
@@ -242,9 +244,6 @@ function isPlainObject(value) {
|
|
|
242
244
|
const proto = Object.getPrototypeOf(value);
|
|
243
245
|
return proto === Object.prototype || proto === null;
|
|
244
246
|
}
|
|
245
|
-
function isShallowArray(array) {
|
|
246
|
-
return array.every((item) => !isObject(item));
|
|
247
|
-
}
|
|
248
247
|
function isUnsafeKey(key) {
|
|
249
248
|
return typeof key === "string" && (key === "__proto__" || key === "prototype" || key === "constructor");
|
|
250
249
|
}
|
|
@@ -279,4 +278,4 @@ function resolveOptions(options) {
|
|
|
279
278
|
};
|
|
280
279
|
}
|
|
281
280
|
|
|
282
|
-
export { bunshinClone, forEachOwnKey, isObject, isPlainObject,
|
|
281
|
+
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
|
+
"version": "1.8.6",
|
|
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 lodash.clonedeep @types/lodash.clonedeep tinybench",
|
|
64
|
+
"bench:run": "node ./benchmark/run.ts",
|
|
65
|
+
"bench:uninstall": "npm un bunshin-clone-npm lodash.clonedeep @types/lodash.clonedeep 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",
|