bunshin-clone 2.0.4 → 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 +17 -24
- package/dist/index.bundle.js +17 -24
- package/dist/index.cjs +17 -22
- package/dist/index.js +18 -23
- package/package.json +1 -1
package/dist/index.bundle.cjs
CHANGED
|
@@ -189,8 +189,22 @@ function isUnsafeKey(key) {
|
|
|
189
189
|
function clonePlainObject(object, settings, refs) {
|
|
190
190
|
const result = Object.create(Object.getPrototypeOf(object));
|
|
191
191
|
refs.set(object, result);
|
|
192
|
-
|
|
193
|
-
|
|
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);
|
|
194
208
|
}
|
|
195
209
|
return result;
|
|
196
210
|
}
|
|
@@ -241,23 +255,6 @@ function cloneURLSearchParams(params, refs) {
|
|
|
241
255
|
return result;
|
|
242
256
|
}
|
|
243
257
|
|
|
244
|
-
// src/clone/with-descriptors.ts
|
|
245
|
-
function cloneWithDescriptors(object, settings, refs) {
|
|
246
|
-
const result = Object.create(Object.getPrototypeOf(object));
|
|
247
|
-
refs.set(object, result);
|
|
248
|
-
const descs = OWN_DESCS(object);
|
|
249
|
-
for (const key of (!settings.preserveSymbolKeys ? OWN_STRING_KEYS : OWN_KEYS)(
|
|
250
|
-
object
|
|
251
|
-
)) {
|
|
252
|
-
const desc = { ...descs[key] };
|
|
253
|
-
if ("value" in desc) {
|
|
254
|
-
desc.value = clone(desc.value, settings, refs);
|
|
255
|
-
}
|
|
256
|
-
Object.defineProperty(result, key, desc);
|
|
257
|
-
}
|
|
258
|
-
return result;
|
|
259
|
-
}
|
|
260
|
-
|
|
261
258
|
// src/index.ts
|
|
262
259
|
function bunshinClone(value, options = {}) {
|
|
263
260
|
return clone(value, resolveOptions(options), /* @__PURE__ */ new WeakMap());
|
|
@@ -269,14 +266,10 @@ function clone(value, settings, refs) {
|
|
|
269
266
|
if (refs.has(value)) {
|
|
270
267
|
return refs.get(value);
|
|
271
268
|
}
|
|
272
|
-
const isClonePlainObject = isPlainObject(value);
|
|
273
|
-
if (settings.preserveDescriptors && isClonePlainObject) {
|
|
274
|
-
return cloneWithDescriptors(value, settings, refs);
|
|
275
|
-
}
|
|
276
269
|
if (Array.isArray(value)) {
|
|
277
270
|
return cloneArray(value, settings, refs);
|
|
278
271
|
}
|
|
279
|
-
if (
|
|
272
|
+
if (isPlainObject(value)) {
|
|
280
273
|
return clonePlainObject(value, settings, refs);
|
|
281
274
|
}
|
|
282
275
|
if (value instanceof Map) {
|
package/dist/index.bundle.js
CHANGED
|
@@ -187,8 +187,22 @@ function isUnsafeKey(key) {
|
|
|
187
187
|
function clonePlainObject(object, settings, refs) {
|
|
188
188
|
const result = Object.create(Object.getPrototypeOf(object));
|
|
189
189
|
refs.set(object, result);
|
|
190
|
-
|
|
191
|
-
|
|
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);
|
|
192
206
|
}
|
|
193
207
|
return result;
|
|
194
208
|
}
|
|
@@ -239,23 +253,6 @@ function cloneURLSearchParams(params, refs) {
|
|
|
239
253
|
return result;
|
|
240
254
|
}
|
|
241
255
|
|
|
242
|
-
// src/clone/with-descriptors.ts
|
|
243
|
-
function cloneWithDescriptors(object, settings, refs) {
|
|
244
|
-
const result = Object.create(Object.getPrototypeOf(object));
|
|
245
|
-
refs.set(object, result);
|
|
246
|
-
const descs = OWN_DESCS(object);
|
|
247
|
-
for (const key of (!settings.preserveSymbolKeys ? OWN_STRING_KEYS : OWN_KEYS)(
|
|
248
|
-
object
|
|
249
|
-
)) {
|
|
250
|
-
const desc = { ...descs[key] };
|
|
251
|
-
if ("value" in desc) {
|
|
252
|
-
desc.value = clone(desc.value, settings, refs);
|
|
253
|
-
}
|
|
254
|
-
Object.defineProperty(result, key, desc);
|
|
255
|
-
}
|
|
256
|
-
return result;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
256
|
// src/index.ts
|
|
260
257
|
function bunshinClone(value, options = {}) {
|
|
261
258
|
return clone(value, resolveOptions(options), /* @__PURE__ */ new WeakMap());
|
|
@@ -267,14 +264,10 @@ function clone(value, settings, refs) {
|
|
|
267
264
|
if (refs.has(value)) {
|
|
268
265
|
return refs.get(value);
|
|
269
266
|
}
|
|
270
|
-
const isClonePlainObject = isPlainObject(value);
|
|
271
|
-
if (settings.preserveDescriptors && isClonePlainObject) {
|
|
272
|
-
return cloneWithDescriptors(value, settings, refs);
|
|
273
|
-
}
|
|
274
267
|
if (Array.isArray(value)) {
|
|
275
268
|
return cloneArray(value, settings, refs);
|
|
276
269
|
}
|
|
277
|
-
if (
|
|
270
|
+
if (isPlainObject(value)) {
|
|
278
271
|
return clonePlainObject(value, settings, refs);
|
|
279
272
|
}
|
|
280
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,21 +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 (!settings.preserveSymbolKeys ? own.OWN_STRING_KEYS : own.OWN_KEYS)(
|
|
210
|
-
object
|
|
211
|
-
)) {
|
|
212
|
-
const desc = { ...descs[key] };
|
|
213
|
-
if ("value" in desc) {
|
|
214
|
-
desc.value = clone(desc.value, settings, refs);
|
|
215
|
-
}
|
|
216
|
-
Object.defineProperty(result, key, desc);
|
|
217
|
-
}
|
|
218
|
-
return result;
|
|
219
|
-
}
|
|
220
219
|
|
|
221
220
|
// src/index.ts
|
|
222
221
|
function bunshinClone(value, options = {}) {
|
|
@@ -229,14 +228,10 @@ function clone(value, settings, refs) {
|
|
|
229
228
|
if (refs.has(value)) {
|
|
230
229
|
return refs.get(value);
|
|
231
230
|
}
|
|
232
|
-
const isClonePlainObject = isPlainObject(value);
|
|
233
|
-
if (settings.preserveDescriptors && isClonePlainObject) {
|
|
234
|
-
return cloneWithDescriptors(value, settings, refs);
|
|
235
|
-
}
|
|
236
231
|
if (Array.isArray(value)) {
|
|
237
232
|
return cloneArray(value, settings, refs);
|
|
238
233
|
}
|
|
239
|
-
if (
|
|
234
|
+
if (isPlainObject(value)) {
|
|
240
235
|
return clonePlainObject(value, settings, refs);
|
|
241
236
|
}
|
|
242
237
|
if (value instanceof Map) {
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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,21 +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 (!settings.preserveSymbolKeys ? OWN_STRING_KEYS : OWN_KEYS)(
|
|
208
|
-
object
|
|
209
|
-
)) {
|
|
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
217
|
|
|
219
218
|
// src/index.ts
|
|
220
219
|
function bunshinClone(value, options = {}) {
|
|
@@ -227,14 +226,10 @@ function clone(value, settings, refs) {
|
|
|
227
226
|
if (refs.has(value)) {
|
|
228
227
|
return refs.get(value);
|
|
229
228
|
}
|
|
230
|
-
const isClonePlainObject = isPlainObject(value);
|
|
231
|
-
if (settings.preserveDescriptors && isClonePlainObject) {
|
|
232
|
-
return cloneWithDescriptors(value, settings, refs);
|
|
233
|
-
}
|
|
234
229
|
if (Array.isArray(value)) {
|
|
235
230
|
return cloneArray(value, settings, refs);
|
|
236
231
|
}
|
|
237
|
-
if (
|
|
232
|
+
if (isPlainObject(value)) {
|
|
238
233
|
return clonePlainObject(value, settings, refs);
|
|
239
234
|
}
|
|
240
235
|
if (value instanceof Map) {
|