bunshin-clone 2.0.2 → 2.0.3

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,12 @@ function cloneMap(map, settings, refs) {
147
147
  return result;
148
148
  }
149
149
  var OWN_DESCS = Object.getOwnPropertyDescriptors;
150
+ function OWN_ENUM_KEYS(object, symbol) {
151
+ return typeof symbol !== "boolean" || !symbol ? OWN_ENUM_STRING_KEYS(object) : [
152
+ ...OWN_ENUM_STRING_KEYS(object),
153
+ ...OWN_ENUM_SYMBOL_KEYS(object)
154
+ ];
155
+ }
150
156
  function OWN_ENUM_STRING_KEYS(object) {
151
157
  const keys = Object.keys(object);
152
158
  for (const key of keys) {
@@ -165,6 +171,12 @@ function OWN_ENUM_SYMBOL_KEYS(object) {
165
171
  }
166
172
  return keys;
167
173
  }
174
+ function OWN_KEYS(object, symbol) {
175
+ return typeof symbol !== "boolean" || !symbol ? OWN_STRING_KEYS(object) : [
176
+ ...OWN_STRING_KEYS(object),
177
+ ...OWN_SYMBOL_KEYS(object)
178
+ ];
179
+ }
168
180
  function OWN_STRING_KEYS(object) {
169
181
  const keys = Object.getOwnPropertyNames(object);
170
182
  for (const key of keys) {
@@ -183,17 +195,9 @@ function isUnsafeKey(key) {
183
195
  function clonePlainObject(object, settings, refs) {
184
196
  const result = Object.create(Object.getPrototypeOf(object));
185
197
  refs.set(object, result);
186
- function copy(key) {
198
+ for (const key of OWN_ENUM_KEYS(object, settings.preserveSymbolKeys)) {
187
199
  result[key] = clone(object[key], settings, refs);
188
200
  }
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
201
  return result;
198
202
  }
199
203
 
@@ -248,21 +252,13 @@ function cloneWithDescriptors(object, settings, refs) {
248
252
  const result = Object.create(Object.getPrototypeOf(object));
249
253
  refs.set(object, result);
250
254
  const descs = OWN_DESCS(object);
251
- function copy(key) {
255
+ for (const key of OWN_KEYS(object, settings.preserveSymbolKeys)) {
252
256
  const desc = { ...descs[key] };
253
257
  if ("value" in desc) {
254
258
  desc.value = clone(desc.value, settings, refs);
255
259
  }
256
260
  Object.defineProperty(result, key, desc);
257
261
  }
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
262
  return result;
267
263
  }
268
264
 
@@ -145,6 +145,12 @@ function cloneMap(map, settings, refs) {
145
145
  return result;
146
146
  }
147
147
  var OWN_DESCS = Object.getOwnPropertyDescriptors;
148
+ function OWN_ENUM_KEYS(object, symbol) {
149
+ return typeof symbol !== "boolean" || !symbol ? OWN_ENUM_STRING_KEYS(object) : [
150
+ ...OWN_ENUM_STRING_KEYS(object),
151
+ ...OWN_ENUM_SYMBOL_KEYS(object)
152
+ ];
153
+ }
148
154
  function OWN_ENUM_STRING_KEYS(object) {
149
155
  const keys = Object.keys(object);
150
156
  for (const key of keys) {
@@ -163,6 +169,12 @@ function OWN_ENUM_SYMBOL_KEYS(object) {
163
169
  }
164
170
  return keys;
165
171
  }
172
+ function OWN_KEYS(object, symbol) {
173
+ return typeof symbol !== "boolean" || !symbol ? OWN_STRING_KEYS(object) : [
174
+ ...OWN_STRING_KEYS(object),
175
+ ...OWN_SYMBOL_KEYS(object)
176
+ ];
177
+ }
166
178
  function OWN_STRING_KEYS(object) {
167
179
  const keys = Object.getOwnPropertyNames(object);
168
180
  for (const key of keys) {
@@ -181,17 +193,9 @@ function isUnsafeKey(key) {
181
193
  function clonePlainObject(object, settings, refs) {
182
194
  const result = Object.create(Object.getPrototypeOf(object));
183
195
  refs.set(object, result);
184
- function copy(key) {
196
+ for (const key of OWN_ENUM_KEYS(object, settings.preserveSymbolKeys)) {
185
197
  result[key] = clone(object[key], settings, refs);
186
198
  }
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
199
  return result;
196
200
  }
197
201
 
@@ -246,21 +250,13 @@ function cloneWithDescriptors(object, settings, refs) {
246
250
  const result = Object.create(Object.getPrototypeOf(object));
247
251
  refs.set(object, result);
248
252
  const descs = OWN_DESCS(object);
249
- function copy(key) {
253
+ for (const key of OWN_KEYS(object, settings.preserveSymbolKeys)) {
250
254
  const desc = { ...descs[key] };
251
255
  if ("value" in desc) {
252
256
  desc.value = clone(desc.value, settings, refs);
253
257
  }
254
258
  Object.defineProperty(result, key, desc);
255
259
  }
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
260
  return result;
265
261
  }
266
262
 
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 own.OWN_ENUM_KEYS(object, settings.preserveSymbolKeys)) {
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,13 @@ 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 own.OWN_KEYS(object, settings.preserveSymbolKeys)) {
218
210
  const desc = { ...descs[key] };
219
211
  if ("value" in desc) {
220
212
  desc.value = clone(desc.value, settings, refs);
221
213
  }
222
214
  Object.defineProperty(result, key, desc);
223
215
  }
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
216
  return result;
233
217
  }
234
218
 
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_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 OWN_ENUM_KEYS(object, settings.preserveSymbolKeys)) {
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,13 @@ 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 OWN_KEYS(object, settings.preserveSymbolKeys)) {
216
208
  const desc = { ...descs[key] };
217
209
  if ("value" in desc) {
218
210
  desc.value = clone(desc.value, settings, refs);
219
211
  }
220
212
  Object.defineProperty(result, key, desc);
221
213
  }
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
214
  return result;
231
215
  }
232
216
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bunshin-clone",
3
- "version": "2.0.2",
3
+ "version": "2.0.3",
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.2"
85
85
  }
86
86
  }