bunshin-clone 2.0.3 → 2.0.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/dist/index.bundle.cjs +21 -32
- package/dist/index.bundle.js +21 -32
- package/dist/index.cjs +17 -20
- package/dist/index.js +18 -21
- package/package.json +2 -2
package/dist/index.bundle.cjs
CHANGED
|
@@ -147,11 +147,8 @@ function cloneMap(map, settings, refs) {
|
|
|
147
147
|
return result;
|
|
148
148
|
}
|
|
149
149
|
var OWN_DESCS = Object.getOwnPropertyDescriptors;
|
|
150
|
-
function OWN_ENUM_KEYS(object
|
|
151
|
-
return
|
|
152
|
-
...OWN_ENUM_STRING_KEYS(object),
|
|
153
|
-
...OWN_ENUM_SYMBOL_KEYS(object)
|
|
154
|
-
];
|
|
150
|
+
function OWN_ENUM_KEYS(object) {
|
|
151
|
+
return [...OWN_ENUM_STRING_KEYS(object), ...OWN_ENUM_SYMBOL_KEYS(object)];
|
|
155
152
|
}
|
|
156
153
|
function OWN_ENUM_STRING_KEYS(object) {
|
|
157
154
|
const keys = Object.keys(object);
|
|
@@ -171,11 +168,8 @@ function OWN_ENUM_SYMBOL_KEYS(object) {
|
|
|
171
168
|
}
|
|
172
169
|
return keys;
|
|
173
170
|
}
|
|
174
|
-
function OWN_KEYS(object
|
|
175
|
-
return
|
|
176
|
-
...OWN_STRING_KEYS(object),
|
|
177
|
-
...OWN_SYMBOL_KEYS(object)
|
|
178
|
-
];
|
|
171
|
+
function OWN_KEYS(object) {
|
|
172
|
+
return [...OWN_STRING_KEYS(object), ...OWN_SYMBOL_KEYS(object)];
|
|
179
173
|
}
|
|
180
174
|
function OWN_STRING_KEYS(object) {
|
|
181
175
|
const keys = Object.getOwnPropertyNames(object);
|
|
@@ -195,8 +189,22 @@ function isUnsafeKey(key) {
|
|
|
195
189
|
function clonePlainObject(object, settings, refs) {
|
|
196
190
|
const result = Object.create(Object.getPrototypeOf(object));
|
|
197
191
|
refs.set(object, result);
|
|
198
|
-
|
|
199
|
-
|
|
192
|
+
const { preserveDescriptors, preserveSymbolKeys } = settings;
|
|
193
|
+
if (!preserveDescriptors) {
|
|
194
|
+
for (const key of (!preserveSymbolKeys ? OWN_ENUM_STRING_KEYS : OWN_ENUM_KEYS)(object)) {
|
|
195
|
+
result[key] = clone(object[key], settings, refs);
|
|
196
|
+
}
|
|
197
|
+
return result;
|
|
198
|
+
}
|
|
199
|
+
const descs = OWN_DESCS(object);
|
|
200
|
+
for (const key of (!preserveSymbolKeys ? OWN_STRING_KEYS : OWN_KEYS)(
|
|
201
|
+
object
|
|
202
|
+
)) {
|
|
203
|
+
const desc = { ...descs[key] };
|
|
204
|
+
if ("value" in desc) {
|
|
205
|
+
desc.value = clone(desc.value, settings, refs);
|
|
206
|
+
}
|
|
207
|
+
Object.defineProperty(result, key, desc);
|
|
200
208
|
}
|
|
201
209
|
return result;
|
|
202
210
|
}
|
|
@@ -247,21 +255,6 @@ function cloneURLSearchParams(params, refs) {
|
|
|
247
255
|
return result;
|
|
248
256
|
}
|
|
249
257
|
|
|
250
|
-
// src/clone/with-descriptors.ts
|
|
251
|
-
function cloneWithDescriptors(object, settings, refs) {
|
|
252
|
-
const result = Object.create(Object.getPrototypeOf(object));
|
|
253
|
-
refs.set(object, result);
|
|
254
|
-
const descs = OWN_DESCS(object);
|
|
255
|
-
for (const key of OWN_KEYS(object, settings.preserveSymbolKeys)) {
|
|
256
|
-
const desc = { ...descs[key] };
|
|
257
|
-
if ("value" in desc) {
|
|
258
|
-
desc.value = clone(desc.value, settings, refs);
|
|
259
|
-
}
|
|
260
|
-
Object.defineProperty(result, key, desc);
|
|
261
|
-
}
|
|
262
|
-
return result;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
258
|
// src/index.ts
|
|
266
259
|
function bunshinClone(value, options = {}) {
|
|
267
260
|
return clone(value, resolveOptions(options), /* @__PURE__ */ new WeakMap());
|
|
@@ -273,14 +266,10 @@ function clone(value, settings, refs) {
|
|
|
273
266
|
if (refs.has(value)) {
|
|
274
267
|
return refs.get(value);
|
|
275
268
|
}
|
|
276
|
-
const isClonePlainObject = isPlainObject(value);
|
|
277
|
-
if (settings.preserveDescriptors && isClonePlainObject) {
|
|
278
|
-
return cloneWithDescriptors(value, settings, refs);
|
|
279
|
-
}
|
|
280
269
|
if (Array.isArray(value)) {
|
|
281
270
|
return cloneArray(value, settings, refs);
|
|
282
271
|
}
|
|
283
|
-
if (
|
|
272
|
+
if (isPlainObject(value)) {
|
|
284
273
|
return clonePlainObject(value, settings, refs);
|
|
285
274
|
}
|
|
286
275
|
if (value instanceof Map) {
|
package/dist/index.bundle.js
CHANGED
|
@@ -145,11 +145,8 @@ function cloneMap(map, settings, refs) {
|
|
|
145
145
|
return result;
|
|
146
146
|
}
|
|
147
147
|
var OWN_DESCS = Object.getOwnPropertyDescriptors;
|
|
148
|
-
function OWN_ENUM_KEYS(object
|
|
149
|
-
return
|
|
150
|
-
...OWN_ENUM_STRING_KEYS(object),
|
|
151
|
-
...OWN_ENUM_SYMBOL_KEYS(object)
|
|
152
|
-
];
|
|
148
|
+
function OWN_ENUM_KEYS(object) {
|
|
149
|
+
return [...OWN_ENUM_STRING_KEYS(object), ...OWN_ENUM_SYMBOL_KEYS(object)];
|
|
153
150
|
}
|
|
154
151
|
function OWN_ENUM_STRING_KEYS(object) {
|
|
155
152
|
const keys = Object.keys(object);
|
|
@@ -169,11 +166,8 @@ function OWN_ENUM_SYMBOL_KEYS(object) {
|
|
|
169
166
|
}
|
|
170
167
|
return keys;
|
|
171
168
|
}
|
|
172
|
-
function OWN_KEYS(object
|
|
173
|
-
return
|
|
174
|
-
...OWN_STRING_KEYS(object),
|
|
175
|
-
...OWN_SYMBOL_KEYS(object)
|
|
176
|
-
];
|
|
169
|
+
function OWN_KEYS(object) {
|
|
170
|
+
return [...OWN_STRING_KEYS(object), ...OWN_SYMBOL_KEYS(object)];
|
|
177
171
|
}
|
|
178
172
|
function OWN_STRING_KEYS(object) {
|
|
179
173
|
const keys = Object.getOwnPropertyNames(object);
|
|
@@ -193,8 +187,22 @@ function isUnsafeKey(key) {
|
|
|
193
187
|
function clonePlainObject(object, settings, refs) {
|
|
194
188
|
const result = Object.create(Object.getPrototypeOf(object));
|
|
195
189
|
refs.set(object, result);
|
|
196
|
-
|
|
197
|
-
|
|
190
|
+
const { preserveDescriptors, preserveSymbolKeys } = settings;
|
|
191
|
+
if (!preserveDescriptors) {
|
|
192
|
+
for (const key of (!preserveSymbolKeys ? OWN_ENUM_STRING_KEYS : OWN_ENUM_KEYS)(object)) {
|
|
193
|
+
result[key] = clone(object[key], settings, refs);
|
|
194
|
+
}
|
|
195
|
+
return result;
|
|
196
|
+
}
|
|
197
|
+
const descs = OWN_DESCS(object);
|
|
198
|
+
for (const key of (!preserveSymbolKeys ? OWN_STRING_KEYS : OWN_KEYS)(
|
|
199
|
+
object
|
|
200
|
+
)) {
|
|
201
|
+
const desc = { ...descs[key] };
|
|
202
|
+
if ("value" in desc) {
|
|
203
|
+
desc.value = clone(desc.value, settings, refs);
|
|
204
|
+
}
|
|
205
|
+
Object.defineProperty(result, key, desc);
|
|
198
206
|
}
|
|
199
207
|
return result;
|
|
200
208
|
}
|
|
@@ -245,21 +253,6 @@ function cloneURLSearchParams(params, refs) {
|
|
|
245
253
|
return result;
|
|
246
254
|
}
|
|
247
255
|
|
|
248
|
-
// src/clone/with-descriptors.ts
|
|
249
|
-
function cloneWithDescriptors(object, settings, refs) {
|
|
250
|
-
const result = Object.create(Object.getPrototypeOf(object));
|
|
251
|
-
refs.set(object, result);
|
|
252
|
-
const descs = OWN_DESCS(object);
|
|
253
|
-
for (const key of OWN_KEYS(object, settings.preserveSymbolKeys)) {
|
|
254
|
-
const desc = { ...descs[key] };
|
|
255
|
-
if ("value" in desc) {
|
|
256
|
-
desc.value = clone(desc.value, settings, refs);
|
|
257
|
-
}
|
|
258
|
-
Object.defineProperty(result, key, desc);
|
|
259
|
-
}
|
|
260
|
-
return result;
|
|
261
|
-
}
|
|
262
|
-
|
|
263
256
|
// src/index.ts
|
|
264
257
|
function bunshinClone(value, options = {}) {
|
|
265
258
|
return clone(value, resolveOptions(options), /* @__PURE__ */ new WeakMap());
|
|
@@ -271,14 +264,10 @@ function clone(value, settings, refs) {
|
|
|
271
264
|
if (refs.has(value)) {
|
|
272
265
|
return refs.get(value);
|
|
273
266
|
}
|
|
274
|
-
const isClonePlainObject = isPlainObject(value);
|
|
275
|
-
if (settings.preserveDescriptors && isClonePlainObject) {
|
|
276
|
-
return cloneWithDescriptors(value, settings, refs);
|
|
277
|
-
}
|
|
278
267
|
if (Array.isArray(value)) {
|
|
279
268
|
return cloneArray(value, settings, refs);
|
|
280
269
|
}
|
|
281
|
-
if (
|
|
270
|
+
if (isPlainObject(value)) {
|
|
282
271
|
return clonePlainObject(value, settings, refs);
|
|
283
272
|
}
|
|
284
273
|
if (value instanceof Map) {
|
package/dist/index.cjs
CHANGED
|
@@ -151,8 +151,22 @@ function cloneMap(map, settings, refs) {
|
|
|
151
151
|
function clonePlainObject(object, settings, refs) {
|
|
152
152
|
const result = Object.create(Object.getPrototypeOf(object));
|
|
153
153
|
refs.set(object, result);
|
|
154
|
-
|
|
155
|
-
|
|
154
|
+
const { preserveDescriptors, preserveSymbolKeys } = settings;
|
|
155
|
+
if (!preserveDescriptors) {
|
|
156
|
+
for (const key of (!preserveSymbolKeys ? own.OWN_ENUM_STRING_KEYS : own.OWN_ENUM_KEYS)(object)) {
|
|
157
|
+
result[key] = clone(object[key], settings, refs);
|
|
158
|
+
}
|
|
159
|
+
return result;
|
|
160
|
+
}
|
|
161
|
+
const descs = own.OWN_DESCS(object);
|
|
162
|
+
for (const key of (!preserveSymbolKeys ? own.OWN_STRING_KEYS : own.OWN_KEYS)(
|
|
163
|
+
object
|
|
164
|
+
)) {
|
|
165
|
+
const desc = { ...descs[key] };
|
|
166
|
+
if ("value" in desc) {
|
|
167
|
+
desc.value = clone(desc.value, settings, refs);
|
|
168
|
+
}
|
|
169
|
+
Object.defineProperty(result, key, desc);
|
|
156
170
|
}
|
|
157
171
|
return result;
|
|
158
172
|
}
|
|
@@ -202,19 +216,6 @@ function cloneURLSearchParams(params, refs) {
|
|
|
202
216
|
refs.set(params, result);
|
|
203
217
|
return result;
|
|
204
218
|
}
|
|
205
|
-
function cloneWithDescriptors(object, settings, refs) {
|
|
206
|
-
const result = Object.create(Object.getPrototypeOf(object));
|
|
207
|
-
refs.set(object, result);
|
|
208
|
-
const descs = own.OWN_DESCS(object);
|
|
209
|
-
for (const key of own.OWN_KEYS(object, settings.preserveSymbolKeys)) {
|
|
210
|
-
const desc = { ...descs[key] };
|
|
211
|
-
if ("value" in desc) {
|
|
212
|
-
desc.value = clone(desc.value, settings, refs);
|
|
213
|
-
}
|
|
214
|
-
Object.defineProperty(result, key, desc);
|
|
215
|
-
}
|
|
216
|
-
return result;
|
|
217
|
-
}
|
|
218
219
|
|
|
219
220
|
// src/index.ts
|
|
220
221
|
function bunshinClone(value, options = {}) {
|
|
@@ -227,14 +228,10 @@ function clone(value, settings, refs) {
|
|
|
227
228
|
if (refs.has(value)) {
|
|
228
229
|
return refs.get(value);
|
|
229
230
|
}
|
|
230
|
-
const isClonePlainObject = isPlainObject(value);
|
|
231
|
-
if (settings.preserveDescriptors && isClonePlainObject) {
|
|
232
|
-
return cloneWithDescriptors(value, settings, refs);
|
|
233
|
-
}
|
|
234
231
|
if (Array.isArray(value)) {
|
|
235
232
|
return cloneArray(value, settings, refs);
|
|
236
233
|
}
|
|
237
|
-
if (
|
|
234
|
+
if (isPlainObject(value)) {
|
|
238
235
|
return clonePlainObject(value, settings, refs);
|
|
239
236
|
}
|
|
240
237
|
if (value instanceof Map) {
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OWN_DESCS,
|
|
1
|
+
import { OWN_ENUM_STRING_KEYS, OWN_ENUM_KEYS, OWN_DESCS, OWN_STRING_KEYS, OWN_KEYS } from '@y14e/own';
|
|
2
2
|
|
|
3
3
|
// src/utils.ts
|
|
4
4
|
function isObject(value) {
|
|
@@ -149,8 +149,22 @@ function cloneMap(map, settings, refs) {
|
|
|
149
149
|
function clonePlainObject(object, settings, refs) {
|
|
150
150
|
const result = Object.create(Object.getPrototypeOf(object));
|
|
151
151
|
refs.set(object, result);
|
|
152
|
-
|
|
153
|
-
|
|
152
|
+
const { preserveDescriptors, preserveSymbolKeys } = settings;
|
|
153
|
+
if (!preserveDescriptors) {
|
|
154
|
+
for (const key of (!preserveSymbolKeys ? OWN_ENUM_STRING_KEYS : OWN_ENUM_KEYS)(object)) {
|
|
155
|
+
result[key] = clone(object[key], settings, refs);
|
|
156
|
+
}
|
|
157
|
+
return result;
|
|
158
|
+
}
|
|
159
|
+
const descs = OWN_DESCS(object);
|
|
160
|
+
for (const key of (!preserveSymbolKeys ? OWN_STRING_KEYS : OWN_KEYS)(
|
|
161
|
+
object
|
|
162
|
+
)) {
|
|
163
|
+
const desc = { ...descs[key] };
|
|
164
|
+
if ("value" in desc) {
|
|
165
|
+
desc.value = clone(desc.value, settings, refs);
|
|
166
|
+
}
|
|
167
|
+
Object.defineProperty(result, key, desc);
|
|
154
168
|
}
|
|
155
169
|
return result;
|
|
156
170
|
}
|
|
@@ -200,19 +214,6 @@ function cloneURLSearchParams(params, refs) {
|
|
|
200
214
|
refs.set(params, result);
|
|
201
215
|
return result;
|
|
202
216
|
}
|
|
203
|
-
function cloneWithDescriptors(object, settings, refs) {
|
|
204
|
-
const result = Object.create(Object.getPrototypeOf(object));
|
|
205
|
-
refs.set(object, result);
|
|
206
|
-
const descs = OWN_DESCS(object);
|
|
207
|
-
for (const key of OWN_KEYS(object, settings.preserveSymbolKeys)) {
|
|
208
|
-
const desc = { ...descs[key] };
|
|
209
|
-
if ("value" in desc) {
|
|
210
|
-
desc.value = clone(desc.value, settings, refs);
|
|
211
|
-
}
|
|
212
|
-
Object.defineProperty(result, key, desc);
|
|
213
|
-
}
|
|
214
|
-
return result;
|
|
215
|
-
}
|
|
216
217
|
|
|
217
218
|
// src/index.ts
|
|
218
219
|
function bunshinClone(value, options = {}) {
|
|
@@ -225,14 +226,10 @@ function clone(value, settings, refs) {
|
|
|
225
226
|
if (refs.has(value)) {
|
|
226
227
|
return refs.get(value);
|
|
227
228
|
}
|
|
228
|
-
const isClonePlainObject = isPlainObject(value);
|
|
229
|
-
if (settings.preserveDescriptors && isClonePlainObject) {
|
|
230
|
-
return cloneWithDescriptors(value, settings, refs);
|
|
231
|
-
}
|
|
232
229
|
if (Array.isArray(value)) {
|
|
233
230
|
return cloneArray(value, settings, refs);
|
|
234
231
|
}
|
|
235
|
-
if (
|
|
232
|
+
if (isPlainObject(value)) {
|
|
236
233
|
return clonePlainObject(value, settings, refs);
|
|
237
234
|
}
|
|
238
235
|
if (value instanceof Map) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bunshin-clone",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.5",
|
|
4
4
|
"description": "High-performance deep clone utility with descriptor support",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"array",
|
|
@@ -81,6 +81,6 @@
|
|
|
81
81
|
"esbuild": true
|
|
82
82
|
},
|
|
83
83
|
"dependencies": {
|
|
84
|
-
"@y14e/own": "^1.0.
|
|
84
|
+
"@y14e/own": "^1.0.3"
|
|
85
85
|
}
|
|
86
86
|
}
|