bunshin-clone 1.3.2 → 1.4.0
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 +3 -3
- package/dist/index.cjs +34 -44
- package/dist/index.d.cts +0 -11
- package/dist/index.d.ts +0 -11
- package/dist/index.js +34 -44
- package/package.json +1 -1
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.
|
|
16
|
+
import { bunshinClone } from 'https://esm.sh/bunshin-clone@1.4.0';
|
|
17
17
|
// or
|
|
18
|
-
import { bunshinClone } from 'https://cdn.jsdelivr.net/npm/bunshin-clone@1.
|
|
18
|
+
import { bunshinClone } from 'https://cdn.jsdelivr.net/npm/bunshin-clone@1.4.0/+esm';
|
|
19
19
|
// or
|
|
20
|
-
import { bunshinClone } from 'https://esm.unpkg.com/bunshin-clone@1.
|
|
20
|
+
import { bunshinClone } from 'https://esm.unpkg.com/bunshin-clone@1.4.0';
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
## 📦 APIs
|
package/dist/index.cjs
CHANGED
|
@@ -114,45 +114,19 @@ function clone(node, options, refs) {
|
|
|
114
114
|
return node;
|
|
115
115
|
}
|
|
116
116
|
function cloneError(value, settings, refs) {
|
|
117
|
-
const
|
|
117
|
+
const result = createErrorInstance(value, settings, refs);
|
|
118
|
+
refs.set(value, result);
|
|
118
119
|
if (value instanceof DOMException) {
|
|
119
|
-
|
|
120
|
-
refs.set(value, result2);
|
|
121
|
-
return result2;
|
|
122
|
-
}
|
|
123
|
-
let result;
|
|
124
|
-
switch (name) {
|
|
125
|
-
case "EvalError":
|
|
126
|
-
result = new EvalError(message);
|
|
127
|
-
break;
|
|
128
|
-
case "RangeError":
|
|
129
|
-
result = new RangeError(message);
|
|
130
|
-
break;
|
|
131
|
-
case "ReferenceError":
|
|
132
|
-
result = new ReferenceError(message);
|
|
133
|
-
break;
|
|
134
|
-
case "SyntaxError":
|
|
135
|
-
result = new SyntaxError(message);
|
|
136
|
-
break;
|
|
137
|
-
case "TypeError":
|
|
138
|
-
result = new TypeError(message);
|
|
139
|
-
break;
|
|
140
|
-
case "URIError":
|
|
141
|
-
result = new URIError(message);
|
|
142
|
-
break;
|
|
143
|
-
default:
|
|
144
|
-
result = new Error(message);
|
|
145
|
-
result.name = name;
|
|
120
|
+
return result;
|
|
146
121
|
}
|
|
147
|
-
|
|
148
|
-
if (stack) {
|
|
122
|
+
if (value.stack) {
|
|
149
123
|
try {
|
|
150
|
-
result.stack = stack;
|
|
124
|
+
result.stack = value.stack;
|
|
151
125
|
} catch {
|
|
152
126
|
}
|
|
153
127
|
}
|
|
154
|
-
if ("cause" in value && cause !== void 0) {
|
|
155
|
-
result.cause = clone(cause, settings, refs);
|
|
128
|
+
if ("cause" in value && value.cause !== void 0) {
|
|
129
|
+
result.cause = clone(value.cause, settings, refs);
|
|
156
130
|
}
|
|
157
131
|
for (const key of Object.keys(value)) {
|
|
158
132
|
Reflect.set(result, key, clone(Reflect.get(value, key), settings, refs));
|
|
@@ -181,6 +155,33 @@ function cloneWithDescriptors(node, settings, refs) {
|
|
|
181
155
|
});
|
|
182
156
|
return result;
|
|
183
157
|
}
|
|
158
|
+
var ERROR_CTORS = {
|
|
159
|
+
EvalError,
|
|
160
|
+
RangeError,
|
|
161
|
+
ReferenceError,
|
|
162
|
+
SyntaxError,
|
|
163
|
+
TypeError,
|
|
164
|
+
URIError
|
|
165
|
+
};
|
|
166
|
+
function createErrorInstance(value, settings, refs) {
|
|
167
|
+
const { message, name } = value;
|
|
168
|
+
if (value instanceof DOMException) {
|
|
169
|
+
return new DOMException(message, name);
|
|
170
|
+
}
|
|
171
|
+
if (value instanceof AggregateError) {
|
|
172
|
+
return new AggregateError(
|
|
173
|
+
value.errors.map((e) => clone(e, settings, refs)),
|
|
174
|
+
message
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
const Ctor = ERROR_CTORS[name];
|
|
178
|
+
if (Ctor) {
|
|
179
|
+
return new Ctor(message);
|
|
180
|
+
}
|
|
181
|
+
const result = new Error(message);
|
|
182
|
+
result.name = name;
|
|
183
|
+
return result;
|
|
184
|
+
}
|
|
184
185
|
function forEachOwnKey(object, callback) {
|
|
185
186
|
for (const key of Object.keys(object)) {
|
|
186
187
|
callback(key);
|
|
@@ -214,17 +215,6 @@ function resolveOptions(options) {
|
|
|
214
215
|
}
|
|
215
216
|
return { preserveDescriptors, strictDescriptors };
|
|
216
217
|
}
|
|
217
|
-
/**
|
|
218
|
-
* Bunshin Clone
|
|
219
|
-
* High-performance deep clone utility with descriptor support.
|
|
220
|
-
* Handles circular ref and complex built-in types.
|
|
221
|
-
*
|
|
222
|
-
* @version 1.3.2
|
|
223
|
-
* @author Yusuke Kamiyamane
|
|
224
|
-
* @license MIT
|
|
225
|
-
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
226
|
-
* @see {@link https://github.com/y14e/bunshin-clone}
|
|
227
|
-
*/
|
|
228
218
|
|
|
229
219
|
exports.bunshinClone = bunshinClone;
|
|
230
220
|
exports.forEachOwnKey = forEachOwnKey;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Bunshin Clone
|
|
3
|
-
* High-performance deep clone utility with descriptor support.
|
|
4
|
-
* Handles circular ref and complex built-in types.
|
|
5
|
-
*
|
|
6
|
-
* @version 1.3.2
|
|
7
|
-
* @author Yusuke Kamiyamane
|
|
8
|
-
* @license MIT
|
|
9
|
-
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
10
|
-
* @see {@link https://github.com/y14e/bunshin-clone}
|
|
11
|
-
*/
|
|
12
1
|
interface BunshinCloneOptions {
|
|
13
2
|
preserveDescriptors: boolean;
|
|
14
3
|
strictDescriptors: boolean;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Bunshin Clone
|
|
3
|
-
* High-performance deep clone utility with descriptor support.
|
|
4
|
-
* Handles circular ref and complex built-in types.
|
|
5
|
-
*
|
|
6
|
-
* @version 1.3.2
|
|
7
|
-
* @author Yusuke Kamiyamane
|
|
8
|
-
* @license MIT
|
|
9
|
-
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
10
|
-
* @see {@link https://github.com/y14e/bunshin-clone}
|
|
11
|
-
*/
|
|
12
1
|
interface BunshinCloneOptions {
|
|
13
2
|
preserveDescriptors: boolean;
|
|
14
3
|
strictDescriptors: boolean;
|
package/dist/index.js
CHANGED
|
@@ -112,45 +112,19 @@ function clone(node, options, refs) {
|
|
|
112
112
|
return node;
|
|
113
113
|
}
|
|
114
114
|
function cloneError(value, settings, refs) {
|
|
115
|
-
const
|
|
115
|
+
const result = createErrorInstance(value, settings, refs);
|
|
116
|
+
refs.set(value, result);
|
|
116
117
|
if (value instanceof DOMException) {
|
|
117
|
-
|
|
118
|
-
refs.set(value, result2);
|
|
119
|
-
return result2;
|
|
120
|
-
}
|
|
121
|
-
let result;
|
|
122
|
-
switch (name) {
|
|
123
|
-
case "EvalError":
|
|
124
|
-
result = new EvalError(message);
|
|
125
|
-
break;
|
|
126
|
-
case "RangeError":
|
|
127
|
-
result = new RangeError(message);
|
|
128
|
-
break;
|
|
129
|
-
case "ReferenceError":
|
|
130
|
-
result = new ReferenceError(message);
|
|
131
|
-
break;
|
|
132
|
-
case "SyntaxError":
|
|
133
|
-
result = new SyntaxError(message);
|
|
134
|
-
break;
|
|
135
|
-
case "TypeError":
|
|
136
|
-
result = new TypeError(message);
|
|
137
|
-
break;
|
|
138
|
-
case "URIError":
|
|
139
|
-
result = new URIError(message);
|
|
140
|
-
break;
|
|
141
|
-
default:
|
|
142
|
-
result = new Error(message);
|
|
143
|
-
result.name = name;
|
|
118
|
+
return result;
|
|
144
119
|
}
|
|
145
|
-
|
|
146
|
-
if (stack) {
|
|
120
|
+
if (value.stack) {
|
|
147
121
|
try {
|
|
148
|
-
result.stack = stack;
|
|
122
|
+
result.stack = value.stack;
|
|
149
123
|
} catch {
|
|
150
124
|
}
|
|
151
125
|
}
|
|
152
|
-
if ("cause" in value && cause !== void 0) {
|
|
153
|
-
result.cause = clone(cause, settings, refs);
|
|
126
|
+
if ("cause" in value && value.cause !== void 0) {
|
|
127
|
+
result.cause = clone(value.cause, settings, refs);
|
|
154
128
|
}
|
|
155
129
|
for (const key of Object.keys(value)) {
|
|
156
130
|
Reflect.set(result, key, clone(Reflect.get(value, key), settings, refs));
|
|
@@ -179,6 +153,33 @@ function cloneWithDescriptors(node, settings, refs) {
|
|
|
179
153
|
});
|
|
180
154
|
return result;
|
|
181
155
|
}
|
|
156
|
+
var ERROR_CTORS = {
|
|
157
|
+
EvalError,
|
|
158
|
+
RangeError,
|
|
159
|
+
ReferenceError,
|
|
160
|
+
SyntaxError,
|
|
161
|
+
TypeError,
|
|
162
|
+
URIError
|
|
163
|
+
};
|
|
164
|
+
function createErrorInstance(value, settings, refs) {
|
|
165
|
+
const { message, name } = value;
|
|
166
|
+
if (value instanceof DOMException) {
|
|
167
|
+
return new DOMException(message, name);
|
|
168
|
+
}
|
|
169
|
+
if (value instanceof AggregateError) {
|
|
170
|
+
return new AggregateError(
|
|
171
|
+
value.errors.map((e) => clone(e, settings, refs)),
|
|
172
|
+
message
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
const Ctor = ERROR_CTORS[name];
|
|
176
|
+
if (Ctor) {
|
|
177
|
+
return new Ctor(message);
|
|
178
|
+
}
|
|
179
|
+
const result = new Error(message);
|
|
180
|
+
result.name = name;
|
|
181
|
+
return result;
|
|
182
|
+
}
|
|
182
183
|
function forEachOwnKey(object, callback) {
|
|
183
184
|
for (const key of Object.keys(object)) {
|
|
184
185
|
callback(key);
|
|
@@ -212,16 +213,5 @@ function resolveOptions(options) {
|
|
|
212
213
|
}
|
|
213
214
|
return { preserveDescriptors, strictDescriptors };
|
|
214
215
|
}
|
|
215
|
-
/**
|
|
216
|
-
* Bunshin Clone
|
|
217
|
-
* High-performance deep clone utility with descriptor support.
|
|
218
|
-
* Handles circular ref and complex built-in types.
|
|
219
|
-
*
|
|
220
|
-
* @version 1.3.2
|
|
221
|
-
* @author Yusuke Kamiyamane
|
|
222
|
-
* @license MIT
|
|
223
|
-
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
224
|
-
* @see {@link https://github.com/y14e/bunshin-clone}
|
|
225
|
-
*/
|
|
226
216
|
|
|
227
217
|
export { bunshinClone, forEachOwnKey, isObject, isPlainObject, isUnsafeKey };
|