bunshin-clone 2.0.2 → 2.0.4

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.
@@ -147,6 +147,9 @@ 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 [...OWN_ENUM_STRING_KEYS(object), ...OWN_ENUM_SYMBOL_KEYS(object)];
152
+ }
150
153
  function OWN_ENUM_STRING_KEYS(object) {
151
154
  const keys = Object.keys(object);
152
155
  for (const key of keys) {
@@ -165,6 +168,9 @@ function OWN_ENUM_SYMBOL_KEYS(object) {
165
168
  }
166
169
  return keys;
167
170
  }
171
+ function OWN_KEYS(object) {
172
+ return [...OWN_STRING_KEYS(object), ...OWN_SYMBOL_KEYS(object)];
173
+ }
168
174
  function OWN_STRING_KEYS(object) {
169
175
  const keys = Object.getOwnPropertyNames(object);
170
176
  for (const key of keys) {
@@ -183,17 +189,9 @@ function isUnsafeKey(key) {
183
189
  function clonePlainObject(object, settings, refs) {
184
190
  const result = Object.create(Object.getPrototypeOf(object));
185
191
  refs.set(object, result);
186
- function copy(key) {
192
+ for (const key of (!settings.preserveSymbolKeys ? OWN_ENUM_STRING_KEYS : OWN_ENUM_KEYS)(object)) {
187
193
  result[key] = clone(object[key], settings, refs);
188
194
  }
189
- for (const key of OWN_ENUM_STRING_KEYS(object)) {
190
- copy(key);
191
- }
192
- if (settings.preserveSymbolKeys) {
193
- for (const key of OWN_ENUM_SYMBOL_KEYS(object)) {
194
- copy(key);
195
- }
196
- }
197
195
  return result;
198
196
  }
199
197
 
@@ -248,21 +246,15 @@ function cloneWithDescriptors(object, settings, refs) {
248
246
  const result = Object.create(Object.getPrototypeOf(object));
249
247
  refs.set(object, result);
250
248
  const descs = OWN_DESCS(object);
251
- function copy(key) {
249
+ for (const key of (!settings.preserveSymbolKeys ? OWN_STRING_KEYS : OWN_KEYS)(
250
+ object
251
+ )) {
252
252
  const desc = { ...descs[key] };
253
253
  if ("value" in desc) {
254
254
  desc.value = clone(desc.value, settings, refs);
255
255
  }
256
256
  Object.defineProperty(result, key, desc);
257
257
  }
258
- for (const key of OWN_STRING_KEYS(object)) {
259
- copy(key);
260
- }
261
- if (settings.preserveSymbolKeys) {
262
- for (const key of OWN_SYMBOL_KEYS(object)) {
263
- copy(key);
264
- }
265
- }
266
258
  return result;
267
259
  }
268
260
 
@@ -145,6 +145,9 @@ 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 [...OWN_ENUM_STRING_KEYS(object), ...OWN_ENUM_SYMBOL_KEYS(object)];
150
+ }
148
151
  function OWN_ENUM_STRING_KEYS(object) {
149
152
  const keys = Object.keys(object);
150
153
  for (const key of keys) {
@@ -163,6 +166,9 @@ function OWN_ENUM_SYMBOL_KEYS(object) {
163
166
  }
164
167
  return keys;
165
168
  }
169
+ function OWN_KEYS(object) {
170
+ return [...OWN_STRING_KEYS(object), ...OWN_SYMBOL_KEYS(object)];
171
+ }
166
172
  function OWN_STRING_KEYS(object) {
167
173
  const keys = Object.getOwnPropertyNames(object);
168
174
  for (const key of keys) {
@@ -181,17 +187,9 @@ function isUnsafeKey(key) {
181
187
  function clonePlainObject(object, settings, refs) {
182
188
  const result = Object.create(Object.getPrototypeOf(object));
183
189
  refs.set(object, result);
184
- function copy(key) {
190
+ for (const key of (!settings.preserveSymbolKeys ? OWN_ENUM_STRING_KEYS : OWN_ENUM_KEYS)(object)) {
185
191
  result[key] = clone(object[key], settings, refs);
186
192
  }
187
- for (const key of OWN_ENUM_STRING_KEYS(object)) {
188
- copy(key);
189
- }
190
- if (settings.preserveSymbolKeys) {
191
- for (const key of OWN_ENUM_SYMBOL_KEYS(object)) {
192
- copy(key);
193
- }
194
- }
195
193
  return result;
196
194
  }
197
195
 
@@ -246,21 +244,15 @@ function cloneWithDescriptors(object, settings, refs) {
246
244
  const result = Object.create(Object.getPrototypeOf(object));
247
245
  refs.set(object, result);
248
246
  const descs = OWN_DESCS(object);
249
- function copy(key) {
247
+ for (const key of (!settings.preserveSymbolKeys ? OWN_STRING_KEYS : OWN_KEYS)(
248
+ object
249
+ )) {
250
250
  const desc = { ...descs[key] };
251
251
  if ("value" in desc) {
252
252
  desc.value = clone(desc.value, settings, refs);
253
253
  }
254
254
  Object.defineProperty(result, key, desc);
255
255
  }
256
- for (const key of OWN_STRING_KEYS(object)) {
257
- copy(key);
258
- }
259
- if (settings.preserveSymbolKeys) {
260
- for (const key of OWN_SYMBOL_KEYS(object)) {
261
- copy(key);
262
- }
263
- }
264
256
  return result;
265
257
  }
266
258
 
package/dist/index.cjs CHANGED
@@ -151,17 +151,9 @@ 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
- function copy(key) {
154
+ for (const key of (!settings.preserveSymbolKeys ? own.OWN_ENUM_STRING_KEYS : own.OWN_ENUM_KEYS)(object)) {
155
155
  result[key] = clone(object[key], settings, refs);
156
156
  }
157
- for (const key of own.OWN_ENUM_STRING_KEYS(object)) {
158
- copy(key);
159
- }
160
- if (settings.preserveSymbolKeys) {
161
- for (const key of own.OWN_ENUM_SYMBOL_KEYS(object)) {
162
- copy(key);
163
- }
164
- }
165
157
  return result;
166
158
  }
167
159
 
@@ -214,21 +206,15 @@ function cloneWithDescriptors(object, settings, refs) {
214
206
  const result = Object.create(Object.getPrototypeOf(object));
215
207
  refs.set(object, result);
216
208
  const descs = own.OWN_DESCS(object);
217
- function copy(key) {
209
+ for (const key of (!settings.preserveSymbolKeys ? own.OWN_STRING_KEYS : own.OWN_KEYS)(
210
+ object
211
+ )) {
218
212
  const desc = { ...descs[key] };
219
213
  if ("value" in desc) {
220
214
  desc.value = clone(desc.value, settings, refs);
221
215
  }
222
216
  Object.defineProperty(result, key, desc);
223
217
  }
224
- for (const key of own.OWN_STRING_KEYS(object)) {
225
- copy(key);
226
- }
227
- if (settings.preserveSymbolKeys) {
228
- for (const key of own.OWN_SYMBOL_KEYS(object)) {
229
- copy(key);
230
- }
231
- }
232
218
  return result;
233
219
  }
234
220
 
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { OWN_DESCS, OWN_STRING_KEYS, OWN_SYMBOL_KEYS, OWN_ENUM_STRING_KEYS, OWN_ENUM_SYMBOL_KEYS } from '@y14e/own';
1
+ import { OWN_DESCS, OWN_STRING_KEYS, OWN_KEYS, OWN_ENUM_STRING_KEYS, OWN_ENUM_KEYS } from '@y14e/own';
2
2
 
3
3
  // src/utils.ts
4
4
  function isObject(value) {
@@ -149,17 +149,9 @@ 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
- function copy(key) {
152
+ for (const key of (!settings.preserveSymbolKeys ? OWN_ENUM_STRING_KEYS : OWN_ENUM_KEYS)(object)) {
153
153
  result[key] = clone(object[key], settings, refs);
154
154
  }
155
- for (const key of OWN_ENUM_STRING_KEYS(object)) {
156
- copy(key);
157
- }
158
- if (settings.preserveSymbolKeys) {
159
- for (const key of OWN_ENUM_SYMBOL_KEYS(object)) {
160
- copy(key);
161
- }
162
- }
163
155
  return result;
164
156
  }
165
157
 
@@ -212,21 +204,15 @@ function cloneWithDescriptors(object, settings, refs) {
212
204
  const result = Object.create(Object.getPrototypeOf(object));
213
205
  refs.set(object, result);
214
206
  const descs = OWN_DESCS(object);
215
- function copy(key) {
207
+ for (const key of (!settings.preserveSymbolKeys ? OWN_STRING_KEYS : OWN_KEYS)(
208
+ object
209
+ )) {
216
210
  const desc = { ...descs[key] };
217
211
  if ("value" in desc) {
218
212
  desc.value = clone(desc.value, settings, refs);
219
213
  }
220
214
  Object.defineProperty(result, key, desc);
221
215
  }
222
- for (const key of OWN_STRING_KEYS(object)) {
223
- copy(key);
224
- }
225
- if (settings.preserveSymbolKeys) {
226
- for (const key of OWN_SYMBOL_KEYS(object)) {
227
- copy(key);
228
- }
229
- }
230
216
  return result;
231
217
  }
232
218
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bunshin-clone",
3
- "version": "2.0.2",
3
+ "version": "2.0.4",
4
4
  "description": "High-performance deep clone utility with descriptor support",
5
5
  "keywords": [
6
6
  "array",
@@ -68,9 +68,6 @@
68
68
  "prepublishOnly": "npm run build",
69
69
  "test": "bun test"
70
70
  },
71
- "dependencies": {
72
- "@y14e/own": "^1.0.1"
73
- },
74
71
  "devDependencies": {
75
72
  "bun-types": "latest",
76
73
  "tsup": "^8.0.0",
@@ -82,5 +79,8 @@
82
79
  },
83
80
  "allowScripts": {
84
81
  "esbuild": true
82
+ },
83
+ "dependencies": {
84
+ "@y14e/own": "^1.0.3"
85
85
  }
86
86
  }