bunshin-clone 1.9.3 → 2.0.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/dist/index.cjs CHANGED
@@ -1,5 +1,7 @@
1
1
  'use strict';
2
2
 
3
+ var own = require('@y14e/own');
4
+
3
5
  // src/utils.ts
4
6
  function isObject(value) {
5
7
  return typeof value === "object" && value !== null;
@@ -146,53 +148,17 @@ function cloneMap(map, settings, refs) {
146
148
  }
147
149
  return result;
148
150
  }
149
-
150
- // src/own.ts
151
- var OWN_DESCS = Object.getOwnPropertyDescriptors;
152
- var OWN_ENUM_STRING_KEYS = (object) => {
153
- const keys = Object.keys(object);
154
- for (const key of keys) {
155
- if (isUnsafeKey(key)) {
156
- keys.splice(keys.indexOf(key), 1);
157
- }
158
- }
159
- return keys;
160
- };
161
- var OWN_ENUM_SYMBOL_KEYS = (object) => {
162
- const keys = OWN_SYMBOL_KEYS(object);
163
- for (const key of keys) {
164
- if (!Object.prototype.propertyIsEnumerable.call(object, key)) {
165
- keys.splice(keys.indexOf(key), 1);
166
- }
167
- }
168
- return keys;
169
- };
170
- var OWN_STRING_KEYS = (object) => {
171
- const keys = Object.getOwnPropertyNames(object);
172
- for (const key of keys) {
173
- if (isUnsafeKey(key)) {
174
- keys.splice(keys.indexOf(key), 1);
175
- }
176
- }
177
- return keys;
178
- };
179
- var OWN_SYMBOL_KEYS = Object.getOwnPropertySymbols;
180
- function isUnsafeKey(key) {
181
- return typeof key === "string" && (key === "__proto__" || key === "prototype" || key === "constructor");
182
- }
183
-
184
- // src/clone/plain-object.ts
185
151
  function clonePlainObject(object, settings, refs) {
186
152
  const result = Object.create(Object.getPrototypeOf(object));
187
153
  refs.set(object, result);
188
154
  function copy(key) {
189
155
  result[key] = clone(object[key], settings, refs);
190
156
  }
191
- for (const key of OWN_ENUM_STRING_KEYS(object)) {
157
+ for (const key of own.OWN_ENUM_STRING_KEYS(object)) {
192
158
  copy(key);
193
159
  }
194
160
  if (settings.preserveSymbolKeys) {
195
- for (const key of OWN_ENUM_SYMBOL_KEYS(object)) {
161
+ for (const key of own.OWN_ENUM_SYMBOL_KEYS(object)) {
196
162
  copy(key);
197
163
  }
198
164
  }
@@ -244,12 +210,10 @@ function cloneURLSearchParams(params, refs) {
244
210
  refs.set(params, result);
245
211
  return result;
246
212
  }
247
-
248
- // src/clone/with-descriptors.ts
249
213
  function cloneWithDescriptors(object, settings, refs) {
250
214
  const result = Object.create(Object.getPrototypeOf(object));
251
215
  refs.set(object, result);
252
- const descs = OWN_DESCS(object);
216
+ const descs = own.OWN_DESCS(object);
253
217
  function copy(key) {
254
218
  const desc = { ...descs[key] };
255
219
  if ("value" in desc) {
@@ -263,11 +227,11 @@ function cloneWithDescriptors(object, settings, refs) {
263
227
  }
264
228
  }
265
229
  }
266
- for (const key of OWN_STRING_KEYS(object)) {
230
+ for (const key of own.OWN_STRING_KEYS(object)) {
267
231
  copy(key);
268
232
  }
269
233
  if (settings.preserveSymbolKeys) {
270
- for (const key of OWN_SYMBOL_KEYS(object)) {
234
+ for (const key of own.OWN_SYMBOL_KEYS(object)) {
271
235
  copy(key);
272
236
  }
273
237
  }
@@ -366,11 +330,6 @@ function resolveOptions(options) {
366
330
  };
367
331
  }
368
332
 
369
- exports.OWN_DESCS = OWN_DESCS;
370
- exports.OWN_ENUM_STRING_KEYS = OWN_ENUM_STRING_KEYS;
371
- exports.OWN_ENUM_SYMBOL_KEYS = OWN_ENUM_SYMBOL_KEYS;
372
- exports.OWN_STRING_KEYS = OWN_STRING_KEYS;
373
- exports.OWN_SYMBOL_KEYS = OWN_SYMBOL_KEYS;
374
333
  exports.bunshinClone = bunshinClone;
375
334
  exports.clone = clone;
376
335
  exports.isObject = isObject;
package/dist/index.d.cts CHANGED
@@ -10,18 +10,10 @@ type PlainObject = Record<PropertyKey, unknown>;
10
10
 
11
11
  declare function isPrimitiveArray(array: unknown[]): boolean;
12
12
 
13
- declare const OWN_DESCS: <T>(o: T) => { [P in keyof T]: TypedPropertyDescriptor<T[P]>; } & {
14
- [x: string]: PropertyDescriptor;
15
- };
16
- declare const OWN_ENUM_STRING_KEYS: (object: PlainObject) => string[];
17
- declare const OWN_ENUM_SYMBOL_KEYS: (object: PlainObject) => symbol[];
18
- declare const OWN_STRING_KEYS: (object: PlainObject) => string[];
19
- declare const OWN_SYMBOL_KEYS: (o: any) => symbol[];
20
-
21
13
  declare function isObject(value: unknown): value is object;
22
14
  declare function isPlainObject(value: unknown): value is PlainObject;
23
15
 
24
16
  declare function bunshinClone<T>(value: T, options?: Partial<BunshinCloneOptions>): T;
25
17
  declare function clone<T>(value: T, settings: BunshinCloneOptions, refs: Refs): T;
26
18
 
27
- export { type BunshinCloneOptions, OWN_DESCS, OWN_ENUM_STRING_KEYS, OWN_ENUM_SYMBOL_KEYS, OWN_STRING_KEYS, OWN_SYMBOL_KEYS, type PlainObject, bunshinClone, clone, isObject, isPlainObject, isPrimitiveArray };
19
+ export { type BunshinCloneOptions, type PlainObject, bunshinClone, clone, isObject, isPlainObject, isPrimitiveArray };
package/dist/index.d.ts CHANGED
@@ -10,18 +10,10 @@ type PlainObject = Record<PropertyKey, unknown>;
10
10
 
11
11
  declare function isPrimitiveArray(array: unknown[]): boolean;
12
12
 
13
- declare const OWN_DESCS: <T>(o: T) => { [P in keyof T]: TypedPropertyDescriptor<T[P]>; } & {
14
- [x: string]: PropertyDescriptor;
15
- };
16
- declare const OWN_ENUM_STRING_KEYS: (object: PlainObject) => string[];
17
- declare const OWN_ENUM_SYMBOL_KEYS: (object: PlainObject) => symbol[];
18
- declare const OWN_STRING_KEYS: (object: PlainObject) => string[];
19
- declare const OWN_SYMBOL_KEYS: (o: any) => symbol[];
20
-
21
13
  declare function isObject(value: unknown): value is object;
22
14
  declare function isPlainObject(value: unknown): value is PlainObject;
23
15
 
24
16
  declare function bunshinClone<T>(value: T, options?: Partial<BunshinCloneOptions>): T;
25
17
  declare function clone<T>(value: T, settings: BunshinCloneOptions, refs: Refs): T;
26
18
 
27
- export { type BunshinCloneOptions, OWN_DESCS, OWN_ENUM_STRING_KEYS, OWN_ENUM_SYMBOL_KEYS, OWN_STRING_KEYS, OWN_SYMBOL_KEYS, type PlainObject, bunshinClone, clone, isObject, isPlainObject, isPrimitiveArray };
19
+ export { type BunshinCloneOptions, type PlainObject, bunshinClone, clone, isObject, isPlainObject, isPrimitiveArray };
package/dist/index.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { OWN_DESCS, OWN_STRING_KEYS, OWN_SYMBOL_KEYS, OWN_ENUM_STRING_KEYS, OWN_ENUM_SYMBOL_KEYS } from '@y14e/own';
2
+
1
3
  // src/utils.ts
2
4
  function isObject(value) {
3
5
  return typeof value === "object" && value !== null;
@@ -144,42 +146,6 @@ function cloneMap(map, settings, refs) {
144
146
  }
145
147
  return result;
146
148
  }
147
-
148
- // src/own.ts
149
- var OWN_DESCS = Object.getOwnPropertyDescriptors;
150
- var OWN_ENUM_STRING_KEYS = (object) => {
151
- const keys = Object.keys(object);
152
- for (const key of keys) {
153
- if (isUnsafeKey(key)) {
154
- keys.splice(keys.indexOf(key), 1);
155
- }
156
- }
157
- return keys;
158
- };
159
- var OWN_ENUM_SYMBOL_KEYS = (object) => {
160
- const keys = OWN_SYMBOL_KEYS(object);
161
- for (const key of keys) {
162
- if (!Object.prototype.propertyIsEnumerable.call(object, key)) {
163
- keys.splice(keys.indexOf(key), 1);
164
- }
165
- }
166
- return keys;
167
- };
168
- var OWN_STRING_KEYS = (object) => {
169
- const keys = Object.getOwnPropertyNames(object);
170
- for (const key of keys) {
171
- if (isUnsafeKey(key)) {
172
- keys.splice(keys.indexOf(key), 1);
173
- }
174
- }
175
- return keys;
176
- };
177
- var OWN_SYMBOL_KEYS = Object.getOwnPropertySymbols;
178
- function isUnsafeKey(key) {
179
- return typeof key === "string" && (key === "__proto__" || key === "prototype" || key === "constructor");
180
- }
181
-
182
- // src/clone/plain-object.ts
183
149
  function clonePlainObject(object, settings, refs) {
184
150
  const result = Object.create(Object.getPrototypeOf(object));
185
151
  refs.set(object, result);
@@ -242,8 +208,6 @@ function cloneURLSearchParams(params, refs) {
242
208
  refs.set(params, result);
243
209
  return result;
244
210
  }
245
-
246
- // src/clone/with-descriptors.ts
247
211
  function cloneWithDescriptors(object, settings, refs) {
248
212
  const result = Object.create(Object.getPrototypeOf(object));
249
213
  refs.set(object, result);
@@ -364,4 +328,4 @@ function resolveOptions(options) {
364
328
  };
365
329
  }
366
330
 
367
- export { OWN_DESCS, OWN_ENUM_STRING_KEYS, OWN_ENUM_SYMBOL_KEYS, OWN_STRING_KEYS, OWN_SYMBOL_KEYS, bunshinClone, clone, isObject, isPlainObject, isPrimitiveArray };
331
+ export { bunshinClone, clone, isObject, isPlainObject, isPrimitiveArray };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bunshin-clone",
3
- "version": "1.9.3",
3
+ "version": "2.0.0",
4
4
  "description": "High-performance deep clone utility with descriptor support",
5
5
  "keywords": [
6
6
  "array",
@@ -68,6 +68,9 @@
68
68
  "prepublishOnly": "npm run build",
69
69
  "test": "bun test"
70
70
  },
71
+ "dependencies": {
72
+ "@y14e/own": "^1.0.0"
73
+ },
71
74
  "devDependencies": {
72
75
  "bun-types": "latest",
73
76
  "tsup": "^8.0.0",