bunshin-clone 1.2.3 → 1.2.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 +41 -41
- package/dist/index.cjs +3 -3
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +3 -3
- package/package.json +2 -3
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.
|
|
16
|
+
import bunshinClone from 'https://esm.sh/bunshin-clone@1.2.5';
|
|
17
17
|
// or
|
|
18
|
-
import bunshinClone from 'https://cdn.jsdelivr.net/npm/bunshin-clone@1.2.
|
|
18
|
+
import bunshinClone from 'https://cdn.jsdelivr.net/npm/bunshin-clone@1.2.5/+esm';
|
|
19
19
|
// or
|
|
20
|
-
import bunshinClone from 'https://esm.unpkg.com/bunshin-clone@1.2.
|
|
20
|
+
import bunshinClone from 'https://esm.unpkg.com/bunshin-clone@1.2.5';
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
## 📦 APIs
|
|
@@ -34,8 +34,8 @@ bunshinClone(source, options);
|
|
|
34
34
|
|
|
35
35
|
```ts
|
|
36
36
|
interface BunshinCloneOptions {
|
|
37
|
-
preserveDescriptors
|
|
38
|
-
strictDescriptors
|
|
37
|
+
preserveDescriptors: boolean; // default: false
|
|
38
|
+
strictDescriptors: boolean; // default: false
|
|
39
39
|
}
|
|
40
40
|
```
|
|
41
41
|
|
|
@@ -70,20 +70,20 @@ console.log(result.nested === source.nested); // false
|
|
|
70
70
|
|
|
71
71
|
bunshin-clone correctly handles:
|
|
72
72
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
73
|
+
- Object (plain + prototype preserved)
|
|
74
|
+
- Array
|
|
75
|
+
- Map
|
|
76
|
+
- Set
|
|
77
|
+
- Date
|
|
78
|
+
- RegExp
|
|
79
|
+
- ArrayBuffer
|
|
80
|
+
- DataView
|
|
81
|
+
- TypedArray (Uint8Array, etc.)
|
|
82
|
+
- Error / DOMException
|
|
83
|
+
- Blob
|
|
84
|
+
- ImageData
|
|
85
|
+
- URL
|
|
86
|
+
- URLSearchParams
|
|
87
87
|
|
|
88
88
|
### Circular ref
|
|
89
89
|
|
|
@@ -134,10 +134,10 @@ Object.getOwnPropertyDescriptor(result, 'x')?.get;
|
|
|
134
134
|
|
|
135
135
|
Some values are returned as-is:
|
|
136
136
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
137
|
+
- Function
|
|
138
|
+
- WeakMap / WeakSet
|
|
139
|
+
- Proxy (not cloned)
|
|
140
|
+
- Other non-cloneable host objects
|
|
141
141
|
|
|
142
142
|
```ts
|
|
143
143
|
const fn = () => {};
|
|
@@ -162,35 +162,35 @@ result.a !== source.a; // true
|
|
|
162
162
|
|
|
163
163
|
#### Getter / Setter behavior
|
|
164
164
|
|
|
165
|
-
|
|
166
|
-
|
|
165
|
+
- Default: evaluated and converted to value
|
|
166
|
+
- preserveDescriptors: preserved as-is
|
|
167
167
|
|
|
168
168
|
#### Descriptor safety
|
|
169
169
|
|
|
170
170
|
When `preserveDescriptors` is enabled:
|
|
171
171
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
172
|
+
- descriptors are cloned safely
|
|
173
|
+
- original object is never mutated
|
|
174
|
+
- errors are controlled via `strictDescriptors`
|
|
175
175
|
|
|
176
176
|
### Performance
|
|
177
177
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
178
|
+
- No proxy / no diffing
|
|
179
|
+
- Minimal branching
|
|
180
|
+
- Fast path for plain objects and arrays
|
|
181
|
+
- Competitive with structuredClone in many cases
|
|
182
182
|
|
|
183
183
|
### Comparison
|
|
184
184
|
|
|
185
|
-
| Feature
|
|
186
|
-
|
|
187
|
-
| Circular refs | ✅
|
|
188
|
-
| Map / Set | ✅
|
|
189
|
-
| TypedArray | ✅
|
|
190
|
-
| Descriptor support | ✅
|
|
191
|
-
| Functions | pass-through
|
|
192
|
-
| Prototype preserved | ✅
|
|
193
|
-
| Custom control | ✅
|
|
185
|
+
| Feature | Bunshin Clone | structuredClone | lodash.clonedeep |
|
|
186
|
+
| ------------------- | ------------- | --------------- | ---------------- |
|
|
187
|
+
| Circular refs | ✅ | ✅ | ✅ |
|
|
188
|
+
| Map / Set | ✅ | ✅ | ⚠️ (partial) |
|
|
189
|
+
| TypedArray | ✅ | ✅ | ⚠️ (shallow) |
|
|
190
|
+
| Descriptor support | ✅ | ❌ | ❌ |
|
|
191
|
+
| Functions | pass-through | ❌ (throws) | pass-through |
|
|
192
|
+
| Prototype preserved | ✅ | ❌ | ⚠️ |
|
|
193
|
+
| Custom control | ✅ | ❌ | ❌ |
|
|
194
194
|
| Performance | ⚡ fast | ⚡ fast | 🐢 slower |
|
|
195
195
|
|
|
196
196
|
</details>
|
package/dist/index.cjs
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
// src/index.ts
|
|
4
4
|
var EMPTY_OPTIONS = {};
|
|
5
5
|
var { hasOwnProperty: HAS_OWN } = Object.prototype;
|
|
6
|
-
function bunshinClone(source, options, refs) {
|
|
7
|
-
return clone(source, options
|
|
6
|
+
function bunshinClone(source, options = EMPTY_OPTIONS, refs = /* @__PURE__ */ new WeakMap()) {
|
|
7
|
+
return clone(source, options, refs);
|
|
8
8
|
}
|
|
9
9
|
function clone(node, options, refs) {
|
|
10
10
|
if (!isObject(node)) {
|
|
@@ -209,7 +209,7 @@ function isUnsafeKey(key) {
|
|
|
209
209
|
* High-performance deep clone utility with descriptor support.
|
|
210
210
|
* Handles circular ref and complex built-in types.
|
|
211
211
|
*
|
|
212
|
-
* @version 1.2.
|
|
212
|
+
* @version 1.2.5
|
|
213
213
|
* @author Yusuke Kamiyamane
|
|
214
214
|
* @license MIT
|
|
215
215
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
package/dist/index.d.cts
CHANGED
|
@@ -3,17 +3,17 @@
|
|
|
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.
|
|
6
|
+
* @version 1.2.5
|
|
7
7
|
* @author Yusuke Kamiyamane
|
|
8
8
|
* @license MIT
|
|
9
9
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
10
10
|
* @see {@link https://github.com/y14e/bunshin-clone}
|
|
11
11
|
*/
|
|
12
12
|
interface BunshinCloneOptions {
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
preserveDescriptors: boolean;
|
|
14
|
+
strictDescriptors: boolean;
|
|
15
15
|
}
|
|
16
16
|
type Refs = WeakMap<object, unknown>;
|
|
17
|
-
declare function bunshinClone<T>(source: T, options?: BunshinCloneOptions
|
|
17
|
+
declare function bunshinClone<T>(source: T, options?: Partial<BunshinCloneOptions>, refs?: Refs): T;
|
|
18
18
|
|
|
19
19
|
export { type BunshinCloneOptions, bunshinClone as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -3,17 +3,17 @@
|
|
|
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.
|
|
6
|
+
* @version 1.2.5
|
|
7
7
|
* @author Yusuke Kamiyamane
|
|
8
8
|
* @license MIT
|
|
9
9
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
10
10
|
* @see {@link https://github.com/y14e/bunshin-clone}
|
|
11
11
|
*/
|
|
12
12
|
interface BunshinCloneOptions {
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
preserveDescriptors: boolean;
|
|
14
|
+
strictDescriptors: boolean;
|
|
15
15
|
}
|
|
16
16
|
type Refs = WeakMap<object, unknown>;
|
|
17
|
-
declare function bunshinClone<T>(source: T, options?: BunshinCloneOptions
|
|
17
|
+
declare function bunshinClone<T>(source: T, options?: Partial<BunshinCloneOptions>, refs?: Refs): T;
|
|
18
18
|
|
|
19
19
|
export { type BunshinCloneOptions, bunshinClone as default };
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
var EMPTY_OPTIONS = {};
|
|
3
3
|
var { hasOwnProperty: HAS_OWN } = Object.prototype;
|
|
4
|
-
function bunshinClone(source, options, refs) {
|
|
5
|
-
return clone(source, options
|
|
4
|
+
function bunshinClone(source, options = EMPTY_OPTIONS, refs = /* @__PURE__ */ new WeakMap()) {
|
|
5
|
+
return clone(source, options, refs);
|
|
6
6
|
}
|
|
7
7
|
function clone(node, options, refs) {
|
|
8
8
|
if (!isObject(node)) {
|
|
@@ -207,7 +207,7 @@ function isUnsafeKey(key) {
|
|
|
207
207
|
* High-performance deep clone utility with descriptor support.
|
|
208
208
|
* Handles circular ref and complex built-in types.
|
|
209
209
|
*
|
|
210
|
-
* @version 1.2.
|
|
210
|
+
* @version 1.2.5
|
|
211
211
|
* @author Yusuke Kamiyamane
|
|
212
212
|
* @license MIT
|
|
213
213
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bunshin-clone",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.5",
|
|
4
4
|
"description": "High-performance deep clone utility with descriptor support",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -20,8 +20,7 @@
|
|
|
20
20
|
],
|
|
21
21
|
"scripts": {
|
|
22
22
|
"build": "tsup",
|
|
23
|
-
"
|
|
24
|
-
"prepublishOnly": "npm run build && npm test",
|
|
23
|
+
"prepublishOnly": "npm run build",
|
|
25
24
|
"lint": "tsc --noEmit"
|
|
26
25
|
},
|
|
27
26
|
"keywords": [
|