@socketsecurity/lib 1.0.4 → 1.1.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.
Files changed (80) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/abort.js.map +2 -2
  3. package/dist/argv/parse.js.map +2 -2
  4. package/dist/arrays.d.ts +143 -0
  5. package/dist/arrays.js.map +2 -2
  6. package/dist/bin.js +1 -4
  7. package/dist/bin.js.map +2 -2
  8. package/dist/cacache.d.ts +0 -2
  9. package/dist/cacache.js +0 -1
  10. package/dist/cacache.js.map +2 -2
  11. package/dist/cache-with-ttl.js.map +2 -2
  12. package/dist/dlx.js.map +2 -2
  13. package/dist/external/@yarnpkg/extensions.d.ts +0 -1
  14. package/dist/external/cacache.d.ts +0 -7
  15. package/dist/external/debug.d.ts +0 -3
  16. package/dist/external/fast-sort.d.ts +0 -1
  17. package/dist/external/libnpmpack.d.ts +0 -1
  18. package/dist/external/make-fetch-happen.d.ts +0 -1
  19. package/dist/external/pacote.d.ts +0 -5
  20. package/dist/external/semver.d.ts +0 -1
  21. package/dist/external/validate-npm-package-name.js +1 -1
  22. package/dist/external/yargs-parser.d.ts +0 -1
  23. package/dist/external/yoctocolors-cjs.js +1 -1
  24. package/dist/external/zod.js +9 -9
  25. package/dist/fs.d.ts +595 -23
  26. package/dist/fs.js.map +2 -2
  27. package/dist/git.d.ts +488 -41
  28. package/dist/git.js.map +2 -2
  29. package/dist/github.d.ts +361 -12
  30. package/dist/github.js.map +2 -2
  31. package/dist/http-request.d.ts +463 -4
  32. package/dist/http-request.js.map +2 -2
  33. package/dist/json.d.ts +177 -4
  34. package/dist/json.js.map +2 -2
  35. package/dist/logger.d.ts +823 -70
  36. package/dist/logger.js +654 -51
  37. package/dist/logger.js.map +2 -2
  38. package/dist/objects.d.ts +386 -10
  39. package/dist/objects.js.map +2 -2
  40. package/dist/path.d.ts +270 -6
  41. package/dist/path.js.map +2 -2
  42. package/dist/promises.d.ts +432 -27
  43. package/dist/promises.js +3 -0
  44. package/dist/promises.js.map +2 -2
  45. package/dist/signal-exit.js.map +2 -2
  46. package/dist/sorts.js.map +2 -2
  47. package/dist/spawn.d.ts +242 -33
  48. package/dist/spawn.js.map +2 -2
  49. package/dist/spinner.d.ts +260 -20
  50. package/dist/spinner.js +201 -63
  51. package/dist/spinner.js.map +2 -2
  52. package/dist/stdio/clear.d.ts +130 -9
  53. package/dist/stdio/clear.js.map +2 -2
  54. package/dist/stdio/divider.d.ts +106 -10
  55. package/dist/stdio/divider.js +10 -0
  56. package/dist/stdio/divider.js.map +2 -2
  57. package/dist/stdio/footer.d.ts +70 -3
  58. package/dist/stdio/footer.js.map +2 -2
  59. package/dist/stdio/header.d.ts +93 -12
  60. package/dist/stdio/header.js.map +2 -2
  61. package/dist/stdio/mask.d.ts +82 -14
  62. package/dist/stdio/mask.js +25 -4
  63. package/dist/stdio/mask.js.map +2 -2
  64. package/dist/stdio/progress.d.ts +112 -15
  65. package/dist/stdio/progress.js +43 -3
  66. package/dist/stdio/progress.js.map +2 -2
  67. package/dist/stdio/prompts.d.ts +95 -5
  68. package/dist/stdio/prompts.js.map +2 -2
  69. package/dist/stdio/stderr.d.ts +114 -11
  70. package/dist/stdio/stderr.js.map +2 -2
  71. package/dist/stdio/stdout.d.ts +107 -11
  72. package/dist/stdio/stdout.js.map +2 -2
  73. package/dist/strings.d.ts +357 -28
  74. package/dist/strings.js.map +2 -2
  75. package/dist/suppress-warnings.js.map +2 -2
  76. package/dist/validation/json-parser.d.ts +226 -7
  77. package/dist/validation/json-parser.js.map +2 -2
  78. package/dist/validation/types.d.ts +114 -12
  79. package/dist/validation/types.js.map +1 -1
  80. package/package.json +5 -3
package/dist/objects.d.ts CHANGED
@@ -1,71 +1,279 @@
1
1
  // Type definitions
2
+ /**
3
+ * Record of property keys mapped to getter functions.
4
+ * Used for defining lazy getters on objects.
5
+ */
2
6
  type GetterDefObj = {
3
7
  [key: PropertyKey]: () => unknown;
4
8
  };
9
+ /**
10
+ * Statistics tracking for lazy getter initialization.
11
+ * Keeps track of which lazy getters have been accessed and initialized.
12
+ */
5
13
  type LazyGetterStats = {
6
14
  initialized?: Set<PropertyKey> | undefined;
7
15
  };
16
+ /**
17
+ * Configuration options for creating constants objects.
18
+ */
8
19
  type ConstantsObjectOptions = {
20
+ /**
21
+ * Lazy getter definitions to attach to the object.
22
+ * @default undefined
23
+ */
9
24
  getters?: GetterDefObj | undefined;
25
+ /**
26
+ * Internal properties to store under `kInternalsSymbol`.
27
+ * @default undefined
28
+ */
10
29
  internals?: object | undefined;
30
+ /**
31
+ * Properties to mix into the object (lower priority than `props`).
32
+ * @default undefined
33
+ */
11
34
  mixin?: object | undefined;
12
35
  };
36
+ /**
37
+ * Type helper that creates a remapped type with fresh property mapping.
38
+ * Useful for flattening intersection types into a single object type.
39
+ */
13
40
  type Remap<T> = {
14
41
  [K in keyof T]: T[K];
15
42
  } extends infer O ? {
16
43
  [K in keyof O]: O[K];
17
44
  } : never;
18
- // Type for generic property bag.
45
+ /**
46
+ * Type for generic property bag.
47
+ */
19
48
  type PropertyBag = {
20
49
  [key: PropertyKey]: unknown;
21
50
  };
22
- // Type for generic sorted object entries.
51
+ /**
52
+ * Type for generic sorted object entries.
53
+ */
23
54
  type SortedObject<T> = {
24
55
  [key: PropertyKey]: T;
25
56
  };
26
57
  export type { GetterDefObj, LazyGetterStats, ConstantsObjectOptions, Remap };
27
58
  /**
28
59
  * Create a lazy getter function that memoizes its result.
60
+ *
61
+ * The returned function will only call the getter once, caching the result
62
+ * for subsequent calls. This is useful for expensive computations or
63
+ * operations that should only happen when needed.
64
+ *
65
+ * @param name - The property key name for the getter (used for debugging and stats)
66
+ * @param getter - Function that computes the value on first access
67
+ * @param stats - Optional stats object to track initialization
68
+ * @returns A memoized getter function
69
+ *
70
+ * @example
71
+ * ```ts
72
+ * const stats = { initialized: new Set() }
73
+ * const getLargeData = createLazyGetter('data', () => {
74
+ * console.log('Computing expensive data...')
75
+ * return { large: 'dataset' }
76
+ * }, stats)
77
+ *
78
+ * getLargeData() // Logs "Computing expensive data..." and returns data
79
+ * getLargeData() // Returns cached data without logging
80
+ * console.log(stats.initialized.has('data')) // true
81
+ * ```
29
82
  */
30
83
  /*@__NO_SIDE_EFFECTS__*/
31
- export declare function createLazyGetter<T>(name: PropertyKey, getter: () => T, stats?: LazyGetterStats): () => T;
84
+ export declare function createLazyGetter<T>(name: PropertyKey, getter: () => T, stats?: LazyGetterStats | undefined): () => T;
32
85
  /**
33
86
  * Create a frozen constants object with lazy getters and internal properties.
87
+ *
88
+ * This function creates an immutable object with:
89
+ * - Regular properties from `props`
90
+ * - Lazy getters that compute values on first access
91
+ * - Internal properties accessible via `kInternalsSymbol`
92
+ * - Mixin properties (lower priority, won't override existing)
93
+ * - Alphabetically sorted keys for consistency
94
+ *
95
+ * The resulting object is deeply frozen and cannot be modified.
96
+ *
97
+ * @param props - Regular properties to include on the object
98
+ * @param options_ - Configuration options
99
+ * @returns A frozen object with all specified properties
100
+ *
101
+ * @example
102
+ * ```ts
103
+ * const config = createConstantsObject(
104
+ * { apiUrl: 'https://api.example.com' },
105
+ * {
106
+ * getters: {
107
+ * client: () => new APIClient(),
108
+ * timestamp: () => Date.now()
109
+ * },
110
+ * internals: {
111
+ * version: '1.0.0'
112
+ * }
113
+ * }
114
+ * )
115
+ *
116
+ * console.log(config.apiUrl) // 'https://api.example.com'
117
+ * console.log(config.client) // APIClient instance (computed on first access)
118
+ * console.log(config[kInternalsSymbol].version) // '1.0.0'
119
+ * ```
34
120
  */
35
121
  /*@__NO_SIDE_EFFECTS__*/
36
- export declare function createConstantsObject(props: object, options_?: ConstantsObjectOptions): Readonly<object>;
122
+ export declare function createConstantsObject(props: object, options_?: ConstantsObjectOptions | undefined): Readonly<object>;
37
123
  /**
38
124
  * Define a getter property on an object.
125
+ *
126
+ * The getter is non-enumerable and configurable, meaning it won't show up
127
+ * in `for...in` loops or `Object.keys()`, but can be redefined later.
128
+ *
129
+ * @param object - The object to define the getter on
130
+ * @param propKey - The property key for the getter
131
+ * @param getter - Function that computes the property value
132
+ * @returns The modified object (for chaining)
133
+ *
134
+ * @example
135
+ * ```ts
136
+ * const obj = {}
137
+ * defineGetter(obj, 'timestamp', () => Date.now())
138
+ * console.log(obj.timestamp) // Current timestamp
139
+ * console.log(obj.timestamp) // Different timestamp (computed each time)
140
+ * console.log(Object.keys(obj)) // [] (non-enumerable)
141
+ * ```
39
142
  */
40
143
  /*@__NO_SIDE_EFFECTS__*/
41
144
  export declare function defineGetter<T>(object: object, propKey: PropertyKey, getter: () => T): object;
42
145
  /**
43
146
  * Define a lazy getter property on an object.
147
+ *
148
+ * Unlike `defineGetter()`, this version memoizes the result so the getter
149
+ * function is only called once. Subsequent accesses return the cached value.
150
+ *
151
+ * @param object - The object to define the lazy getter on
152
+ * @param propKey - The property key for the lazy getter
153
+ * @param getter - Function that computes the value on first access
154
+ * @param stats - Optional stats object to track initialization
155
+ * @returns The modified object (for chaining)
156
+ *
157
+ * @example
158
+ * ```ts
159
+ * const obj = {}
160
+ * defineLazyGetter(obj, 'data', () => {
161
+ * console.log('Loading data...')
162
+ * return { expensive: 'computation' }
163
+ * })
164
+ * console.log(obj.data) // Logs "Loading data..." and returns data
165
+ * console.log(obj.data) // Returns same data without logging
166
+ * ```
44
167
  */
45
168
  /*@__NO_SIDE_EFFECTS__*/
46
- export declare function defineLazyGetter<T>(object: object, propKey: PropertyKey, getter: () => T, stats?: LazyGetterStats): object;
169
+ export declare function defineLazyGetter<T>(object: object, propKey: PropertyKey, getter: () => T, stats?: LazyGetterStats | undefined): object;
47
170
  /**
48
171
  * Define multiple lazy getter properties on an object.
172
+ *
173
+ * Each getter in the provided object will be converted to a lazy getter
174
+ * and attached to the target object. All getters share the same stats object
175
+ * for tracking initialization.
176
+ *
177
+ * @param object - The object to define lazy getters on
178
+ * @param getterDefObj - Object mapping property keys to getter functions
179
+ * @param stats - Optional stats object to track initialization
180
+ * @returns The modified object (for chaining)
181
+ *
182
+ * @example
183
+ * ```ts
184
+ * const obj = {}
185
+ * const stats = { initialized: new Set() }
186
+ * defineLazyGetters(obj, {
187
+ * user: () => fetchUser(),
188
+ * config: () => loadConfig(),
189
+ * timestamp: () => Date.now()
190
+ * }, stats)
191
+ *
192
+ * console.log(obj.user) // Fetches user on first access
193
+ * console.log(obj.config) // Loads config on first access
194
+ * console.log(stats.initialized) // Set(['user', 'config'])
195
+ * ```
49
196
  */
50
197
  /*@__NO_SIDE_EFFECTS__*/
51
- export declare function defineLazyGetters(object: object, getterDefObj: GetterDefObj | undefined, stats?: LazyGetterStats): object;
198
+ export declare function defineLazyGetters(object: object, getterDefObj: GetterDefObj | undefined, stats?: LazyGetterStats | undefined): object;
52
199
  /**
53
200
  * Compare two entry arrays by their keys for sorting.
201
+ *
202
+ * Used internally for alphabetically sorting object entries.
203
+ * String keys are compared directly, non-string keys are converted to strings first.
204
+ *
205
+ * @param a - First entry tuple [key, value]
206
+ * @param b - Second entry tuple [key, value]
207
+ * @returns Negative if a < b, positive if a > b, zero if equal
208
+ *
209
+ * @example
210
+ * ```ts
211
+ * const entries = [['zebra', 1], ['apple', 2], ['banana', 3]]
212
+ * entries.sort(entryKeyComparator)
213
+ * // [['apple', 2], ['banana', 3], ['zebra', 1]]
214
+ * ```
54
215
  */
55
216
  /*@__NO_SIDE_EFFECTS__*/
56
217
  export declare function entryKeyComparator(a: [PropertyKey, unknown], b: [PropertyKey, unknown]): number;
57
218
  /**
58
219
  * Get the enumerable own property keys of an object.
220
+ *
221
+ * This is a safe wrapper around `Object.keys()` that returns an empty array
222
+ * for non-object values instead of throwing an error.
223
+ *
224
+ * @param obj - The value to get keys from
225
+ * @returns Array of enumerable string keys, or empty array for non-objects
226
+ *
227
+ * @example
228
+ * ```ts
229
+ * getKeys({ a: 1, b: 2 }) // ['a', 'b']
230
+ * getKeys([10, 20, 30]) // ['0', '1', '2']
231
+ * getKeys(null) // []
232
+ * getKeys(undefined) // []
233
+ * getKeys('hello') // []
234
+ * ```
59
235
  */
60
236
  /*@__NO_SIDE_EFFECTS__*/
61
237
  export declare function getKeys(obj: unknown): string[];
62
238
  /**
63
239
  * Get an own property value from an object safely.
240
+ *
241
+ * Returns `undefined` if the value is null/undefined or if the property
242
+ * doesn't exist as an own property (not inherited). This avoids prototype
243
+ * chain lookups and prevents errors on null/undefined values.
244
+ *
245
+ * @param obj - The object to get the property from
246
+ * @param propKey - The property key to look up
247
+ * @returns The property value, or `undefined` if not found or obj is null/undefined
248
+ *
249
+ * @example
250
+ * ```ts
251
+ * const obj = { name: 'Alice', age: 30 }
252
+ * getOwn(obj, 'name') // 'Alice'
253
+ * getOwn(obj, 'missing') // undefined
254
+ * getOwn(obj, 'toString') // undefined (inherited, not own property)
255
+ * getOwn(null, 'name') // undefined
256
+ * getOwn(undefined, 'name') // undefined
257
+ * ```
64
258
  */
65
259
  /*@__NO_SIDE_EFFECTS__*/
66
260
  export declare function getOwn(obj: unknown, propKey: PropertyKey): unknown;
67
261
  /**
68
262
  * Get all own property values from an object.
263
+ *
264
+ * Returns values for all own properties (enumerable and non-enumerable),
265
+ * but not inherited properties. Returns an empty array for null/undefined.
266
+ *
267
+ * @param obj - The object to get values from
268
+ * @returns Array of all own property values, or empty array for null/undefined
269
+ *
270
+ * @example
271
+ * ```ts
272
+ * getOwnPropertyValues({ a: 1, b: 2, c: 3 }) // [1, 2, 3]
273
+ * getOwnPropertyValues([10, 20, 30]) // [10, 20, 30]
274
+ * getOwnPropertyValues(null) // []
275
+ * getOwnPropertyValues(undefined) // []
276
+ * ```
69
277
  */
70
278
  /*@__NO_SIDE_EFFECTS__*/
71
279
  export declare function getOwnPropertyValues<T>(obj: {
@@ -73,16 +281,69 @@ export declare function getOwnPropertyValues<T>(obj: {
73
281
  } | null | undefined): T[];
74
282
  /**
75
283
  * Check if an object has any enumerable own properties.
284
+ *
285
+ * Returns `true` if the object has at least one enumerable own property,
286
+ * `false` otherwise. Also returns `false` for null/undefined.
287
+ *
288
+ * @param obj - The value to check
289
+ * @returns `true` if obj has enumerable own properties, `false` otherwise
290
+ *
291
+ * @example
292
+ * ```ts
293
+ * hasKeys({ a: 1 }) // true
294
+ * hasKeys({}) // false
295
+ * hasKeys([]) // false
296
+ * hasKeys([1, 2]) // true
297
+ * hasKeys(null) // false
298
+ * hasKeys(undefined) // false
299
+ * hasKeys(Object.create({ inherited: true })) // false (inherited, not own)
300
+ * ```
76
301
  */
77
302
  /*@__NO_SIDE_EFFECTS__*/
78
303
  export declare function hasKeys(obj: unknown): obj is PropertyBag;
79
304
  /**
80
305
  * Check if an object has an own property.
306
+ *
307
+ * Type-safe wrapper around `Object.hasOwn()` that returns `false` for
308
+ * null/undefined instead of throwing. Only checks own properties, not
309
+ * inherited ones from the prototype chain.
310
+ *
311
+ * @param obj - The value to check
312
+ * @param propKey - The property key to look for
313
+ * @returns `true` if obj has the property as an own property, `false` otherwise
314
+ *
315
+ * @example
316
+ * ```ts
317
+ * const obj = { name: 'Alice' }
318
+ * hasOwn(obj, 'name') // true
319
+ * hasOwn(obj, 'age') // false
320
+ * hasOwn(obj, 'toString') // false (inherited from Object.prototype)
321
+ * hasOwn(null, 'name') // false
322
+ * hasOwn(undefined, 'name') // false
323
+ * ```
81
324
  */
82
325
  /*@__NO_SIDE_EFFECTS__*/
83
326
  export declare function hasOwn(obj: unknown, propKey: PropertyKey): obj is object & PropertyBag;
84
327
  /**
85
328
  * Check if a value is an object (including arrays).
329
+ *
330
+ * Returns `true` for any object type including arrays, functions, dates, etc.
331
+ * Returns `false` for primitives and `null`.
332
+ *
333
+ * @param value - The value to check
334
+ * @returns `true` if value is an object (including arrays), `false` otherwise
335
+ *
336
+ * @example
337
+ * ```ts
338
+ * isObject({}) // true
339
+ * isObject([]) // true
340
+ * isObject(new Date()) // true
341
+ * isObject(() => {}) // false (functions are not objects for typeof)
342
+ * isObject(null) // false
343
+ * isObject(undefined) // false
344
+ * isObject(42) // false
345
+ * isObject('string') // false
346
+ * ```
86
347
  */
87
348
  /*@__NO_SIDE_EFFECTS__*/
88
349
  export declare function isObject(value: unknown): value is {
@@ -90,6 +351,23 @@ export declare function isObject(value: unknown): value is {
90
351
  };
91
352
  /**
92
353
  * Check if a value is a plain object (not an array, not a built-in).
354
+ *
355
+ * Returns `true` only for plain objects created with `{}` or `Object.create(null)`.
356
+ * Returns `false` for arrays, built-in objects (Date, RegExp, etc.), and primitives.
357
+ *
358
+ * @param value - The value to check
359
+ * @returns `true` if value is a plain object, `false` otherwise
360
+ *
361
+ * @example
362
+ * ```ts
363
+ * isObjectObject({}) // true
364
+ * isObjectObject({ a: 1 }) // true
365
+ * isObjectObject(Object.create(null)) // true
366
+ * isObjectObject([]) // false
367
+ * isObjectObject(new Date()) // false
368
+ * isObjectObject(null) // false
369
+ * isObjectObject(42) // false
370
+ * ```
93
371
  */
94
372
  /*@__NO_SIDE_EFFECTS__*/
95
373
  export declare function isObjectObject(value: unknown): value is {
@@ -100,8 +378,17 @@ export declare function isObjectObject(value: unknown): value is {
100
378
  // `exports.SomeName = void 0;` which causes runtime errors.
101
379
  // See: https://github.com/SocketDev/socket-packageurl-js/issues/3
102
380
  /**
103
- * Alias for native Object.assign.
104
- * Copies all enumerable own properties from one or more source objects to a target object.
381
+ * Alias for native `Object.assign`.
382
+ *
383
+ * Copies all enumerable own properties from one or more source objects
384
+ * to a target object and returns the modified target object.
385
+ *
386
+ * @example
387
+ * ```ts
388
+ * const target = { a: 1 }
389
+ * const source = { b: 2, c: 3 }
390
+ * objectAssign(target, source) // { a: 1, b: 2, c: 3 }
391
+ * ```
105
392
  */
106
393
  export declare const objectAssign: {
107
394
  <T extends {}, U>(target: T, source: U): T & U;
@@ -111,6 +398,21 @@ export declare const objectAssign: {
111
398
  };
112
399
  /**
113
400
  * Get all own property entries (key-value pairs) from an object.
401
+ *
402
+ * Unlike `Object.entries()`, this includes non-enumerable properties and
403
+ * symbol keys. Returns an empty array for null/undefined.
404
+ *
405
+ * @param obj - The object to get entries from
406
+ * @returns Array of [key, value] tuples, or empty array for null/undefined
407
+ *
408
+ * @example
409
+ * ```ts
410
+ * objectEntries({ a: 1, b: 2 }) // [['a', 1], ['b', 2]]
411
+ * const sym = Symbol('key')
412
+ * objectEntries({ [sym]: 'value', x: 10 }) // [[Symbol(key), 'value'], ['x', 10]]
413
+ * objectEntries(null) // []
414
+ * objectEntries(undefined) // []
415
+ * ```
114
416
  */
115
417
  /*@__NO_SIDE_EFFECTS__*/
116
418
  export declare function objectEntries(obj: unknown): Array<[PropertyKey, unknown]>;
@@ -119,8 +421,18 @@ export declare function objectEntries(obj: unknown): Array<[PropertyKey, unknown
119
421
  // `exports.SomeName = void 0;` which causes runtime errors.
120
422
  // See: https://github.com/SocketDev/socket-packageurl-js/issues/3
121
423
  /**
122
- * Alias for native Object.freeze.
123
- * Freezes an object, preventing new properties from being added and existing properties from being removed or modified.
424
+ * Alias for native `Object.freeze`.
425
+ *
426
+ * Freezes an object, preventing new properties from being added and existing
427
+ * properties from being removed or modified. Makes the object immutable.
428
+ *
429
+ * @example
430
+ * ```ts
431
+ * const obj = { a: 1 }
432
+ * objectFreeze(obj)
433
+ * obj.a = 2 // Silently fails in non-strict mode, throws in strict mode
434
+ * obj.b = 3 // Silently fails in non-strict mode, throws in strict mode
435
+ * ```
124
436
  */
125
437
  export declare const objectFreeze: {
126
438
  <T extends Function>(f: T): T;
@@ -131,16 +443,80 @@ export declare const objectFreeze: {
131
443
  };
132
444
  /**
133
445
  * Deep merge source object into target object.
446
+ *
447
+ * Recursively merges properties from `source` into `target`. Arrays in source
448
+ * completely replace arrays in target (no element-wise merging). Objects are
449
+ * merged recursively. Includes infinite loop detection for safety.
450
+ *
451
+ * @param target - The object to merge into (will be modified)
452
+ * @param source - The object to merge from
453
+ * @returns The modified target object
454
+ *
455
+ * @example
456
+ * ```ts
457
+ * const target = { a: { x: 1 }, b: [1, 2] }
458
+ * const source = { a: { y: 2 }, b: [3, 4, 5], c: 3 }
459
+ * merge(target, source)
460
+ * // { a: { x: 1, y: 2 }, b: [3, 4, 5], c: 3 }
461
+ * ```
462
+ *
463
+ * @example
464
+ * ```ts
465
+ * // Arrays are replaced, not merged
466
+ * merge({ arr: [1, 2] }, { arr: [3] }) // { arr: [3] }
467
+ *
468
+ * // Deep object merging
469
+ * merge(
470
+ * { config: { api: 'v1', timeout: 1000 } },
471
+ * { config: { api: 'v2', retries: 3 } }
472
+ * )
473
+ * // { config: { api: 'v2', timeout: 1000, retries: 3 } }
474
+ * ```
134
475
  */
135
476
  /*@__NO_SIDE_EFFECTS__*/
136
477
  export declare function merge<T extends object, U extends object>(target: T, source: U): T & U;
137
478
  /**
138
479
  * Convert an object to a new object with sorted keys.
480
+ *
481
+ * Creates a new object with the same properties as the input, but with keys
482
+ * sorted alphabetically. Symbol keys are sorted separately and placed first.
483
+ * This is useful for consistent key ordering in serialization or comparisons.
484
+ *
485
+ * @param obj - The object to sort
486
+ * @returns A new object with sorted keys
487
+ *
488
+ * @example
489
+ * ```ts
490
+ * toSortedObject({ z: 1, a: 2, m: 3 })
491
+ * // { a: 2, m: 3, z: 1 }
492
+ *
493
+ * const sym1 = Symbol('first')
494
+ * const sym2 = Symbol('second')
495
+ * toSortedObject({ z: 1, [sym2]: 2, a: 3, [sym1]: 4 })
496
+ * // { [Symbol(first)]: 4, [Symbol(second)]: 2, a: 3, z: 1 }
497
+ * ```
139
498
  */
140
499
  /*@__NO_SIDE_EFFECTS__*/
141
500
  export declare function toSortedObject<T extends object>(obj: T): T;
142
501
  /**
143
502
  * Create an object from entries with sorted keys.
503
+ *
504
+ * Takes an iterable of [key, value] entries and creates a new object with
505
+ * keys sorted alphabetically. Symbol keys are sorted separately and placed
506
+ * first in the resulting object.
507
+ *
508
+ * @param entries - Iterable of [key, value] tuples
509
+ * @returns A new object with sorted keys
510
+ *
511
+ * @example
512
+ * ```ts
513
+ * toSortedObjectFromEntries([['z', 1], ['a', 2], ['m', 3]])
514
+ * // { a: 2, m: 3, z: 1 }
515
+ *
516
+ * const entries = new Map([['beta', 2], ['alpha', 1], ['gamma', 3]])
517
+ * toSortedObjectFromEntries(entries)
518
+ * // { alpha: 1, beta: 2, gamma: 3 }
519
+ * ```
144
520
  */
145
521
  /*@__NO_SIDE_EFFECTS__*/
146
522
  export declare function toSortedObjectFromEntries<T = unknown>(entries: Iterable<[PropertyKey, T]>): SortedObject<T>;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/objects.ts"],
4
- "sourcesContent": ["/**\n * @fileoverview Object manipulation and reflection utilities.\n * Provides type-safe object operations, property access, and structural helpers.\n */\n\nimport {\n kInternalsSymbol,\n LOOP_SENTINEL,\n UNDEFINED_TOKEN,\n} from '#constants/core'\n\nimport { isArray } from './arrays'\nimport { localeCompare } from './sorts'\n\n// Type definitions\ntype GetterDefObj = { [key: PropertyKey]: () => unknown }\ntype LazyGetterStats = { initialized?: Set<PropertyKey> | undefined }\ntype ConstantsObjectOptions = {\n getters?: GetterDefObj | undefined\n internals?: object | undefined\n mixin?: object | undefined\n}\ntype Remap<T> = { [K in keyof T]: T[K] } extends infer O\n ? { [K in keyof O]: O[K] }\n : never\n\n// Type for dynamic lazy getter record.\ntype LazyGetterRecord<T> = {\n [key: PropertyKey]: () => T\n}\n\n// Type for generic property bag.\ntype PropertyBag = {\n [key: PropertyKey]: unknown\n}\n\n// Type for generic sorted object entries.\ntype SortedObject<T> = {\n [key: PropertyKey]: T\n}\n\nexport type { GetterDefObj, LazyGetterStats, ConstantsObjectOptions, Remap }\n\n// IMPORTANT: Do not use destructuring here - use direct assignment instead.\n// tsgo has a bug that incorrectly transpiles destructured exports, resulting in\n// `exports.SomeName = void 0;` which causes runtime errors.\n// See: https://github.com/SocketDev/socket-packageurl-js/issues/3\nconst ObjectDefineProperties = Object.defineProperties\nconst ObjectDefineProperty = Object.defineProperty\nconst ObjectFreeze = Object.freeze\nconst ObjectFromEntries = Object.fromEntries\nconst ObjectGetOwnPropertyDescriptors = Object.getOwnPropertyDescriptors\nconst ObjectGetOwnPropertyNames = Object.getOwnPropertyNames\nconst ObjectGetPrototypeOf = Object.getPrototypeOf\nconst ObjectHasOwn = Object.hasOwn\nconst ObjectKeys = Object.keys\nconst ObjectPrototype = Object.prototype\nconst ObjectSetPrototypeOf = Object.setPrototypeOf\n// @ts-expect-error - __defineGetter__ exists but not in type definitions.\n// IMPORTANT: Do not use destructuring here - use direct assignment instead.\n// tsgo has a bug that incorrectly transpiles destructured exports, resulting in\n// `exports.SomeName = void 0;` which causes runtime errors.\n// See: https://github.com/SocketDev/socket-packageurl-js/issues/3\nconst __defineGetter__ = Object.prototype.__defineGetter__\n// IMPORTANT: Do not use destructuring here - use direct assignment instead.\n// tsgo has a bug that incorrectly transpiles destructured exports, resulting in\n// `exports.SomeName = void 0;` which causes runtime errors.\n// See: https://github.com/SocketDev/socket-packageurl-js/issues/3\nconst ReflectOwnKeys = Reflect.ownKeys\n\n/**\n * Create a lazy getter function that memoizes its result.\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function createLazyGetter<T>(\n name: PropertyKey,\n getter: () => T,\n stats?: LazyGetterStats,\n): () => T {\n let lazyValue: T | typeof UNDEFINED_TOKEN = UNDEFINED_TOKEN\n // Dynamically name the getter without using Object.defineProperty.\n const { [name]: lazyGetter } = {\n [name]() {\n if (lazyValue === UNDEFINED_TOKEN) {\n stats?.initialized?.add(name)\n lazyValue = getter()\n }\n return lazyValue as T\n },\n } as LazyGetterRecord<T>\n return lazyGetter as unknown as () => T\n}\n\n/**\n * Create a frozen constants object with lazy getters and internal properties.\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function createConstantsObject(\n props: object,\n options_?: ConstantsObjectOptions,\n): Readonly<object> {\n const options = { __proto__: null, ...options_ } as ConstantsObjectOptions\n const attributes = ObjectFreeze({\n __proto__: null,\n getters: options.getters\n ? ObjectFreeze(\n ObjectSetPrototypeOf(toSortedObject(options.getters), null),\n )\n : undefined,\n internals: options.internals\n ? ObjectFreeze(\n ObjectSetPrototypeOf(toSortedObject(options.internals), null),\n )\n : undefined,\n mixin: options.mixin\n ? ObjectFreeze(\n ObjectDefineProperties(\n { __proto__: null },\n ObjectGetOwnPropertyDescriptors(options.mixin),\n ),\n )\n : undefined,\n props: props\n ? ObjectFreeze(ObjectSetPrototypeOf(toSortedObject(props), null))\n : undefined,\n })\n const lazyGetterStats = ObjectFreeze({\n __proto__: null,\n initialized: new Set<PropertyKey>(),\n })\n const object = defineLazyGetters(\n {\n __proto__: null,\n [kInternalsSymbol]: ObjectFreeze({\n __proto__: null,\n get attributes() {\n return attributes\n },\n get lazyGetterStats() {\n return lazyGetterStats\n },\n ...attributes.internals,\n }),\n kInternalsSymbol,\n ...attributes.props,\n },\n attributes.getters,\n lazyGetterStats,\n )\n if (attributes.mixin) {\n ObjectDefineProperties(\n object,\n toSortedObjectFromEntries(\n objectEntries(ObjectGetOwnPropertyDescriptors(attributes.mixin)).filter(\n p => !ObjectHasOwn(object, p[0]),\n ),\n ) as PropertyDescriptorMap,\n )\n }\n return ObjectFreeze(object)\n}\n\n/**\n * Define a getter property on an object.\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function defineGetter<T>(\n object: object,\n propKey: PropertyKey,\n getter: () => T,\n): object {\n ObjectDefineProperty(object, propKey, {\n get: getter,\n enumerable: false,\n configurable: true,\n })\n return object\n}\n\n/**\n * Define a lazy getter property on an object.\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function defineLazyGetter<T>(\n object: object,\n propKey: PropertyKey,\n getter: () => T,\n stats?: LazyGetterStats,\n): object {\n return defineGetter(object, propKey, createLazyGetter(propKey, getter, stats))\n}\n\n/**\n * Define multiple lazy getter properties on an object.\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function defineLazyGetters(\n object: object,\n getterDefObj: GetterDefObj | undefined,\n stats?: LazyGetterStats,\n): object {\n if (getterDefObj !== null && typeof getterDefObj === 'object') {\n const keys = ReflectOwnKeys(getterDefObj)\n for (let i = 0, { length } = keys; i < length; i += 1) {\n const key = keys[i] as PropertyKey\n defineLazyGetter(\n object,\n key,\n createLazyGetter(key, getterDefObj[key] as () => unknown, stats),\n )\n }\n }\n return object\n}\n\n/**\n * Compare two entry arrays by their keys for sorting.\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function entryKeyComparator(\n a: [PropertyKey, unknown],\n b: [PropertyKey, unknown],\n): number {\n const keyA = a[0]\n const keyB = b[0]\n const strKeyA = typeof keyA === 'string' ? keyA : String(keyA)\n const strKeyB = typeof keyB === 'string' ? keyB : String(keyB)\n return localeCompare(strKeyA, strKeyB)\n}\n\n/**\n * Get the enumerable own property keys of an object.\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function getKeys(obj: unknown): string[] {\n return isObject(obj) ? ObjectKeys(obj) : []\n}\n\n/**\n * Get an own property value from an object safely.\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function getOwn(obj: unknown, propKey: PropertyKey): unknown {\n if (obj === null || obj === undefined) {\n return undefined\n }\n return ObjectHasOwn(obj as object, propKey)\n ? (obj as Record<PropertyKey, unknown>)[propKey]\n : undefined\n}\n\n/**\n * Get all own property values from an object.\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function getOwnPropertyValues<T>(\n obj: { [key: PropertyKey]: T } | null | undefined,\n): T[] {\n if (obj === null || obj === undefined) {\n return []\n }\n const keys = ObjectGetOwnPropertyNames(obj)\n const { length } = keys\n const values = Array(length)\n for (let i = 0; i < length; i += 1) {\n values[i] = obj[keys[i] as string]\n }\n return values\n}\n\n/**\n * Check if an object has any enumerable own properties.\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function hasKeys(obj: unknown): obj is PropertyBag {\n if (obj === null || obj === undefined) {\n return false\n }\n for (const key in obj as object) {\n if (ObjectHasOwn(obj as object, key)) {\n return true\n }\n }\n return false\n}\n\n/**\n * Check if an object has an own property.\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function hasOwn(\n obj: unknown,\n propKey: PropertyKey,\n): obj is object & PropertyBag {\n if (obj === null || obj === undefined) {\n return false\n }\n return ObjectHasOwn(obj as object, propKey)\n}\n\n/**\n * Check if a value is an object (including arrays).\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function isObject(\n value: unknown,\n): value is { [key: PropertyKey]: unknown } {\n return value !== null && typeof value === 'object'\n}\n\n/**\n * Check if a value is a plain object (not an array, not a built-in).\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function isObjectObject(\n value: unknown,\n): value is { [key: PropertyKey]: unknown } {\n if (value === null || typeof value !== 'object' || isArray(value)) {\n return false\n }\n const proto = ObjectGetPrototypeOf(value)\n return proto === null || proto === ObjectPrototype\n}\n\n// IMPORTANT: Do not use destructuring here - use direct assignment instead.\n// tsgo has a bug that incorrectly transpiles destructured exports, resulting in\n// `exports.SomeName = void 0;` which causes runtime errors.\n// See: https://github.com/SocketDev/socket-packageurl-js/issues/3\n\n/**\n * Alias for native Object.assign.\n * Copies all enumerable own properties from one or more source objects to a target object.\n */\nexport const objectAssign = Object.assign\n\n/**\n * Get all own property entries (key-value pairs) from an object.\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function objectEntries(obj: unknown): Array<[PropertyKey, unknown]> {\n if (obj === null || obj === undefined) {\n return []\n }\n const keys = ReflectOwnKeys(obj as object)\n const { length } = keys\n const entries = Array(length)\n const record = obj as Record<PropertyKey, unknown>\n for (let i = 0; i < length; i += 1) {\n const key = keys[i] as PropertyKey\n entries[i] = [key, record[key]]\n }\n return entries\n}\n\n// IMPORTANT: Do not use destructuring here - use direct assignment instead.\n// tsgo has a bug that incorrectly transpiles destructured exports, resulting in\n// `exports.SomeName = void 0;` which causes runtime errors.\n// See: https://github.com/SocketDev/socket-packageurl-js/issues/3\n\n/**\n * Alias for native Object.freeze.\n * Freezes an object, preventing new properties from being added and existing properties from being removed or modified.\n */\nexport const objectFreeze = Object.freeze\n\n/**\n * Deep merge source object into target object.\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function merge<T extends object, U extends object>(\n target: T,\n source: U,\n): T & U {\n if (!isObject(target) || !isObject(source)) {\n return target as T & U\n }\n const queue: Array<[unknown, unknown]> = [[target, source]]\n let pos = 0\n let { length: queueLength } = queue\n while (pos < queueLength) {\n if (pos === LOOP_SENTINEL) {\n throw new Error('Detected infinite loop in object crawl of merge')\n }\n const { 0: currentTarget, 1: currentSource } = queue[pos++] as [\n Record<PropertyKey, unknown>,\n Record<PropertyKey, unknown>,\n ]\n\n if (!currentSource || !currentTarget) {\n continue\n }\n\n const isSourceArray = isArray(currentSource)\n const isTargetArray = isArray(currentTarget)\n\n // Skip array merging - arrays in source replace arrays in target\n if (isSourceArray || isTargetArray) {\n continue\n }\n\n const keys = ReflectOwnKeys(currentSource as object)\n for (let i = 0, { length } = keys; i < length; i += 1) {\n const key = keys[i] as PropertyKey\n const srcVal = currentSource[key]\n const targetVal = currentTarget[key]\n if (isArray(srcVal)) {\n // Replace arrays entirely\n currentTarget[key] = srcVal\n } else if (isObject(srcVal)) {\n if (isObject(targetVal) && !isArray(targetVal)) {\n queue[queueLength++] = [targetVal, srcVal]\n } else {\n currentTarget[key] = srcVal\n }\n } else {\n currentTarget[key] = srcVal\n }\n }\n }\n return target as T & U\n}\n\n/**\n * Convert an object to a new object with sorted keys.\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function toSortedObject<T extends object>(obj: T): T {\n return toSortedObjectFromEntries(objectEntries(obj)) as T\n}\n\n/**\n * Create an object from entries with sorted keys.\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function toSortedObjectFromEntries<T = unknown>(\n entries: Iterable<[PropertyKey, T]>,\n): SortedObject<T> {\n const otherEntries = []\n const symbolEntries = []\n // Use for-of to work with entries iterators.\n for (const entry of entries) {\n if (typeof entry[0] === 'symbol') {\n symbolEntries.push(entry)\n } else {\n otherEntries.push(entry)\n }\n }\n if (!otherEntries.length && !symbolEntries.length) {\n return {}\n }\n return ObjectFromEntries([\n // The String constructor is safe to use with symbols.\n ...symbolEntries.sort(entryKeyComparator),\n ...otherEntries.sort(entryKeyComparator),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and reflection utilities.\n * Provides type-safe object operations, property access, and structural helpers.\n */\n\nimport {\n kInternalsSymbol,\n LOOP_SENTINEL,\n UNDEFINED_TOKEN,\n} from '#constants/core'\n\nimport { isArray } from './arrays'\nimport { localeCompare } from './sorts'\n\n// Type definitions\n\n/**\n * Record of property keys mapped to getter functions.\n * Used for defining lazy getters on objects.\n */\ntype GetterDefObj = { [key: PropertyKey]: () => unknown }\n\n/**\n * Statistics tracking for lazy getter initialization.\n * Keeps track of which lazy getters have been accessed and initialized.\n */\ntype LazyGetterStats = { initialized?: Set<PropertyKey> | undefined }\n\n/**\n * Configuration options for creating constants objects.\n */\ntype ConstantsObjectOptions = {\n /**\n * Lazy getter definitions to attach to the object.\n * @default undefined\n */\n getters?: GetterDefObj | undefined\n /**\n * Internal properties to store under `kInternalsSymbol`.\n * @default undefined\n */\n internals?: object | undefined\n /**\n * Properties to mix into the object (lower priority than `props`).\n * @default undefined\n */\n mixin?: object | undefined\n}\n\n/**\n * Type helper that creates a remapped type with fresh property mapping.\n * Useful for flattening intersection types into a single object type.\n */\ntype Remap<T> = { [K in keyof T]: T[K] } extends infer O\n ? { [K in keyof O]: O[K] }\n : never\n\n/**\n * Type for dynamic lazy getter record.\n */\ntype LazyGetterRecord<T> = {\n [key: PropertyKey]: () => T\n}\n\n/**\n * Type for generic property bag.\n */\ntype PropertyBag = {\n [key: PropertyKey]: unknown\n}\n\n/**\n * Type for generic sorted object entries.\n */\ntype SortedObject<T> = {\n [key: PropertyKey]: T\n}\n\nexport type { GetterDefObj, LazyGetterStats, ConstantsObjectOptions, Remap }\n\n// IMPORTANT: Do not use destructuring here - use direct assignment instead.\n// tsgo has a bug that incorrectly transpiles destructured exports, resulting in\n// `exports.SomeName = void 0;` which causes runtime errors.\n// See: https://github.com/SocketDev/socket-packageurl-js/issues/3\nconst ObjectDefineProperties = Object.defineProperties\nconst ObjectDefineProperty = Object.defineProperty\nconst ObjectFreeze = Object.freeze\nconst ObjectFromEntries = Object.fromEntries\nconst ObjectGetOwnPropertyDescriptors = Object.getOwnPropertyDescriptors\nconst ObjectGetOwnPropertyNames = Object.getOwnPropertyNames\nconst ObjectGetPrototypeOf = Object.getPrototypeOf\nconst ObjectHasOwn = Object.hasOwn\nconst ObjectKeys = Object.keys\nconst ObjectPrototype = Object.prototype\nconst ObjectSetPrototypeOf = Object.setPrototypeOf\n// @ts-expect-error - __defineGetter__ exists but not in type definitions.\n// IMPORTANT: Do not use destructuring here - use direct assignment instead.\n// tsgo has a bug that incorrectly transpiles destructured exports, resulting in\n// `exports.SomeName = void 0;` which causes runtime errors.\n// See: https://github.com/SocketDev/socket-packageurl-js/issues/3\nconst __defineGetter__ = Object.prototype.__defineGetter__\n// IMPORTANT: Do not use destructuring here - use direct assignment instead.\n// tsgo has a bug that incorrectly transpiles destructured exports, resulting in\n// `exports.SomeName = void 0;` which causes runtime errors.\n// See: https://github.com/SocketDev/socket-packageurl-js/issues/3\nconst ReflectOwnKeys = Reflect.ownKeys\n\n/**\n * Create a lazy getter function that memoizes its result.\n *\n * The returned function will only call the getter once, caching the result\n * for subsequent calls. This is useful for expensive computations or\n * operations that should only happen when needed.\n *\n * @param name - The property key name for the getter (used for debugging and stats)\n * @param getter - Function that computes the value on first access\n * @param stats - Optional stats object to track initialization\n * @returns A memoized getter function\n *\n * @example\n * ```ts\n * const stats = { initialized: new Set() }\n * const getLargeData = createLazyGetter('data', () => {\n * console.log('Computing expensive data...')\n * return { large: 'dataset' }\n * }, stats)\n *\n * getLargeData() // Logs \"Computing expensive data...\" and returns data\n * getLargeData() // Returns cached data without logging\n * console.log(stats.initialized.has('data')) // true\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function createLazyGetter<T>(\n name: PropertyKey,\n getter: () => T,\n stats?: LazyGetterStats | undefined,\n): () => T {\n let lazyValue: T | typeof UNDEFINED_TOKEN = UNDEFINED_TOKEN\n // Dynamically name the getter without using Object.defineProperty.\n const { [name]: lazyGetter } = {\n [name]() {\n if (lazyValue === UNDEFINED_TOKEN) {\n stats?.initialized?.add(name)\n lazyValue = getter()\n }\n return lazyValue as T\n },\n } as LazyGetterRecord<T>\n return lazyGetter as unknown as () => T\n}\n\n/**\n * Create a frozen constants object with lazy getters and internal properties.\n *\n * This function creates an immutable object with:\n * - Regular properties from `props`\n * - Lazy getters that compute values on first access\n * - Internal properties accessible via `kInternalsSymbol`\n * - Mixin properties (lower priority, won't override existing)\n * - Alphabetically sorted keys for consistency\n *\n * The resulting object is deeply frozen and cannot be modified.\n *\n * @param props - Regular properties to include on the object\n * @param options_ - Configuration options\n * @returns A frozen object with all specified properties\n *\n * @example\n * ```ts\n * const config = createConstantsObject(\n * { apiUrl: 'https://api.example.com' },\n * {\n * getters: {\n * client: () => new APIClient(),\n * timestamp: () => Date.now()\n * },\n * internals: {\n * version: '1.0.0'\n * }\n * }\n * )\n *\n * console.log(config.apiUrl) // 'https://api.example.com'\n * console.log(config.client) // APIClient instance (computed on first access)\n * console.log(config[kInternalsSymbol].version) // '1.0.0'\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function createConstantsObject(\n props: object,\n options_?: ConstantsObjectOptions | undefined,\n): Readonly<object> {\n const options = { __proto__: null, ...options_ } as ConstantsObjectOptions\n const attributes = ObjectFreeze({\n __proto__: null,\n getters: options.getters\n ? ObjectFreeze(\n ObjectSetPrototypeOf(toSortedObject(options.getters), null),\n )\n : undefined,\n internals: options.internals\n ? ObjectFreeze(\n ObjectSetPrototypeOf(toSortedObject(options.internals), null),\n )\n : undefined,\n mixin: options.mixin\n ? ObjectFreeze(\n ObjectDefineProperties(\n { __proto__: null },\n ObjectGetOwnPropertyDescriptors(options.mixin),\n ),\n )\n : undefined,\n props: props\n ? ObjectFreeze(ObjectSetPrototypeOf(toSortedObject(props), null))\n : undefined,\n })\n const lazyGetterStats = ObjectFreeze({\n __proto__: null,\n initialized: new Set<PropertyKey>(),\n })\n const object = defineLazyGetters(\n {\n __proto__: null,\n [kInternalsSymbol]: ObjectFreeze({\n __proto__: null,\n get attributes() {\n return attributes\n },\n get lazyGetterStats() {\n return lazyGetterStats\n },\n ...attributes.internals,\n }),\n kInternalsSymbol,\n ...attributes.props,\n },\n attributes.getters,\n lazyGetterStats,\n )\n if (attributes.mixin) {\n ObjectDefineProperties(\n object,\n toSortedObjectFromEntries(\n objectEntries(ObjectGetOwnPropertyDescriptors(attributes.mixin)).filter(\n p => !ObjectHasOwn(object, p[0]),\n ),\n ) as PropertyDescriptorMap,\n )\n }\n return ObjectFreeze(object)\n}\n\n/**\n * Define a getter property on an object.\n *\n * The getter is non-enumerable and configurable, meaning it won't show up\n * in `for...in` loops or `Object.keys()`, but can be redefined later.\n *\n * @param object - The object to define the getter on\n * @param propKey - The property key for the getter\n * @param getter - Function that computes the property value\n * @returns The modified object (for chaining)\n *\n * @example\n * ```ts\n * const obj = {}\n * defineGetter(obj, 'timestamp', () => Date.now())\n * console.log(obj.timestamp) // Current timestamp\n * console.log(obj.timestamp) // Different timestamp (computed each time)\n * console.log(Object.keys(obj)) // [] (non-enumerable)\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function defineGetter<T>(\n object: object,\n propKey: PropertyKey,\n getter: () => T,\n): object {\n ObjectDefineProperty(object, propKey, {\n get: getter,\n enumerable: false,\n configurable: true,\n })\n return object\n}\n\n/**\n * Define a lazy getter property on an object.\n *\n * Unlike `defineGetter()`, this version memoizes the result so the getter\n * function is only called once. Subsequent accesses return the cached value.\n *\n * @param object - The object to define the lazy getter on\n * @param propKey - The property key for the lazy getter\n * @param getter - Function that computes the value on first access\n * @param stats - Optional stats object to track initialization\n * @returns The modified object (for chaining)\n *\n * @example\n * ```ts\n * const obj = {}\n * defineLazyGetter(obj, 'data', () => {\n * console.log('Loading data...')\n * return { expensive: 'computation' }\n * })\n * console.log(obj.data) // Logs \"Loading data...\" and returns data\n * console.log(obj.data) // Returns same data without logging\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function defineLazyGetter<T>(\n object: object,\n propKey: PropertyKey,\n getter: () => T,\n stats?: LazyGetterStats | undefined,\n): object {\n return defineGetter(object, propKey, createLazyGetter(propKey, getter, stats))\n}\n\n/**\n * Define multiple lazy getter properties on an object.\n *\n * Each getter in the provided object will be converted to a lazy getter\n * and attached to the target object. All getters share the same stats object\n * for tracking initialization.\n *\n * @param object - The object to define lazy getters on\n * @param getterDefObj - Object mapping property keys to getter functions\n * @param stats - Optional stats object to track initialization\n * @returns The modified object (for chaining)\n *\n * @example\n * ```ts\n * const obj = {}\n * const stats = { initialized: new Set() }\n * defineLazyGetters(obj, {\n * user: () => fetchUser(),\n * config: () => loadConfig(),\n * timestamp: () => Date.now()\n * }, stats)\n *\n * console.log(obj.user) // Fetches user on first access\n * console.log(obj.config) // Loads config on first access\n * console.log(stats.initialized) // Set(['user', 'config'])\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function defineLazyGetters(\n object: object,\n getterDefObj: GetterDefObj | undefined,\n stats?: LazyGetterStats | undefined,\n): object {\n if (getterDefObj !== null && typeof getterDefObj === 'object') {\n const keys = ReflectOwnKeys(getterDefObj)\n for (let i = 0, { length } = keys; i < length; i += 1) {\n const key = keys[i] as PropertyKey\n defineLazyGetter(\n object,\n key,\n createLazyGetter(key, getterDefObj[key] as () => unknown, stats),\n )\n }\n }\n return object\n}\n\n/**\n * Compare two entry arrays by their keys for sorting.\n *\n * Used internally for alphabetically sorting object entries.\n * String keys are compared directly, non-string keys are converted to strings first.\n *\n * @param a - First entry tuple [key, value]\n * @param b - Second entry tuple [key, value]\n * @returns Negative if a < b, positive if a > b, zero if equal\n *\n * @example\n * ```ts\n * const entries = [['zebra', 1], ['apple', 2], ['banana', 3]]\n * entries.sort(entryKeyComparator)\n * // [['apple', 2], ['banana', 3], ['zebra', 1]]\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function entryKeyComparator(\n a: [PropertyKey, unknown],\n b: [PropertyKey, unknown],\n): number {\n const keyA = a[0]\n const keyB = b[0]\n const strKeyA = typeof keyA === 'string' ? keyA : String(keyA)\n const strKeyB = typeof keyB === 'string' ? keyB : String(keyB)\n return localeCompare(strKeyA, strKeyB)\n}\n\n/**\n * Get the enumerable own property keys of an object.\n *\n * This is a safe wrapper around `Object.keys()` that returns an empty array\n * for non-object values instead of throwing an error.\n *\n * @param obj - The value to get keys from\n * @returns Array of enumerable string keys, or empty array for non-objects\n *\n * @example\n * ```ts\n * getKeys({ a: 1, b: 2 }) // ['a', 'b']\n * getKeys([10, 20, 30]) // ['0', '1', '2']\n * getKeys(null) // []\n * getKeys(undefined) // []\n * getKeys('hello') // []\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function getKeys(obj: unknown): string[] {\n return isObject(obj) ? ObjectKeys(obj) : []\n}\n\n/**\n * Get an own property value from an object safely.\n *\n * Returns `undefined` if the value is null/undefined or if the property\n * doesn't exist as an own property (not inherited). This avoids prototype\n * chain lookups and prevents errors on null/undefined values.\n *\n * @param obj - The object to get the property from\n * @param propKey - The property key to look up\n * @returns The property value, or `undefined` if not found or obj is null/undefined\n *\n * @example\n * ```ts\n * const obj = { name: 'Alice', age: 30 }\n * getOwn(obj, 'name') // 'Alice'\n * getOwn(obj, 'missing') // undefined\n * getOwn(obj, 'toString') // undefined (inherited, not own property)\n * getOwn(null, 'name') // undefined\n * getOwn(undefined, 'name') // undefined\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function getOwn(obj: unknown, propKey: PropertyKey): unknown {\n if (obj === null || obj === undefined) {\n return undefined\n }\n return ObjectHasOwn(obj as object, propKey)\n ? (obj as Record<PropertyKey, unknown>)[propKey]\n : undefined\n}\n\n/**\n * Get all own property values from an object.\n *\n * Returns values for all own properties (enumerable and non-enumerable),\n * but not inherited properties. Returns an empty array for null/undefined.\n *\n * @param obj - The object to get values from\n * @returns Array of all own property values, or empty array for null/undefined\n *\n * @example\n * ```ts\n * getOwnPropertyValues({ a: 1, b: 2, c: 3 }) // [1, 2, 3]\n * getOwnPropertyValues([10, 20, 30]) // [10, 20, 30]\n * getOwnPropertyValues(null) // []\n * getOwnPropertyValues(undefined) // []\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function getOwnPropertyValues<T>(\n obj: { [key: PropertyKey]: T } | null | undefined,\n): T[] {\n if (obj === null || obj === undefined) {\n return []\n }\n const keys = ObjectGetOwnPropertyNames(obj)\n const { length } = keys\n const values = Array(length)\n for (let i = 0; i < length; i += 1) {\n values[i] = obj[keys[i] as string]\n }\n return values\n}\n\n/**\n * Check if an object has any enumerable own properties.\n *\n * Returns `true` if the object has at least one enumerable own property,\n * `false` otherwise. Also returns `false` for null/undefined.\n *\n * @param obj - The value to check\n * @returns `true` if obj has enumerable own properties, `false` otherwise\n *\n * @example\n * ```ts\n * hasKeys({ a: 1 }) // true\n * hasKeys({}) // false\n * hasKeys([]) // false\n * hasKeys([1, 2]) // true\n * hasKeys(null) // false\n * hasKeys(undefined) // false\n * hasKeys(Object.create({ inherited: true })) // false (inherited, not own)\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function hasKeys(obj: unknown): obj is PropertyBag {\n if (obj === null || obj === undefined) {\n return false\n }\n for (const key in obj as object) {\n if (ObjectHasOwn(obj as object, key)) {\n return true\n }\n }\n return false\n}\n\n/**\n * Check if an object has an own property.\n *\n * Type-safe wrapper around `Object.hasOwn()` that returns `false` for\n * null/undefined instead of throwing. Only checks own properties, not\n * inherited ones from the prototype chain.\n *\n * @param obj - The value to check\n * @param propKey - The property key to look for\n * @returns `true` if obj has the property as an own property, `false` otherwise\n *\n * @example\n * ```ts\n * const obj = { name: 'Alice' }\n * hasOwn(obj, 'name') // true\n * hasOwn(obj, 'age') // false\n * hasOwn(obj, 'toString') // false (inherited from Object.prototype)\n * hasOwn(null, 'name') // false\n * hasOwn(undefined, 'name') // false\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function hasOwn(\n obj: unknown,\n propKey: PropertyKey,\n): obj is object & PropertyBag {\n if (obj === null || obj === undefined) {\n return false\n }\n return ObjectHasOwn(obj as object, propKey)\n}\n\n/**\n * Check if a value is an object (including arrays).\n *\n * Returns `true` for any object type including arrays, functions, dates, etc.\n * Returns `false` for primitives and `null`.\n *\n * @param value - The value to check\n * @returns `true` if value is an object (including arrays), `false` otherwise\n *\n * @example\n * ```ts\n * isObject({}) // true\n * isObject([]) // true\n * isObject(new Date()) // true\n * isObject(() => {}) // false (functions are not objects for typeof)\n * isObject(null) // false\n * isObject(undefined) // false\n * isObject(42) // false\n * isObject('string') // false\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function isObject(\n value: unknown,\n): value is { [key: PropertyKey]: unknown } {\n return value !== null && typeof value === 'object'\n}\n\n/**\n * Check if a value is a plain object (not an array, not a built-in).\n *\n * Returns `true` only for plain objects created with `{}` or `Object.create(null)`.\n * Returns `false` for arrays, built-in objects (Date, RegExp, etc.), and primitives.\n *\n * @param value - The value to check\n * @returns `true` if value is a plain object, `false` otherwise\n *\n * @example\n * ```ts\n * isObjectObject({}) // true\n * isObjectObject({ a: 1 }) // true\n * isObjectObject(Object.create(null)) // true\n * isObjectObject([]) // false\n * isObjectObject(new Date()) // false\n * isObjectObject(null) // false\n * isObjectObject(42) // false\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function isObjectObject(\n value: unknown,\n): value is { [key: PropertyKey]: unknown } {\n if (value === null || typeof value !== 'object' || isArray(value)) {\n return false\n }\n const proto = ObjectGetPrototypeOf(value)\n return proto === null || proto === ObjectPrototype\n}\n\n// IMPORTANT: Do not use destructuring here - use direct assignment instead.\n// tsgo has a bug that incorrectly transpiles destructured exports, resulting in\n// `exports.SomeName = void 0;` which causes runtime errors.\n// See: https://github.com/SocketDev/socket-packageurl-js/issues/3\n\n/**\n * Alias for native `Object.assign`.\n *\n * Copies all enumerable own properties from one or more source objects\n * to a target object and returns the modified target object.\n *\n * @example\n * ```ts\n * const target = { a: 1 }\n * const source = { b: 2, c: 3 }\n * objectAssign(target, source) // { a: 1, b: 2, c: 3 }\n * ```\n */\nexport const objectAssign = Object.assign\n\n/**\n * Get all own property entries (key-value pairs) from an object.\n *\n * Unlike `Object.entries()`, this includes non-enumerable properties and\n * symbol keys. Returns an empty array for null/undefined.\n *\n * @param obj - The object to get entries from\n * @returns Array of [key, value] tuples, or empty array for null/undefined\n *\n * @example\n * ```ts\n * objectEntries({ a: 1, b: 2 }) // [['a', 1], ['b', 2]]\n * const sym = Symbol('key')\n * objectEntries({ [sym]: 'value', x: 10 }) // [[Symbol(key), 'value'], ['x', 10]]\n * objectEntries(null) // []\n * objectEntries(undefined) // []\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function objectEntries(obj: unknown): Array<[PropertyKey, unknown]> {\n if (obj === null || obj === undefined) {\n return []\n }\n const keys = ReflectOwnKeys(obj as object)\n const { length } = keys\n const entries = Array(length)\n const record = obj as Record<PropertyKey, unknown>\n for (let i = 0; i < length; i += 1) {\n const key = keys[i] as PropertyKey\n entries[i] = [key, record[key]]\n }\n return entries\n}\n\n// IMPORTANT: Do not use destructuring here - use direct assignment instead.\n// tsgo has a bug that incorrectly transpiles destructured exports, resulting in\n// `exports.SomeName = void 0;` which causes runtime errors.\n// See: https://github.com/SocketDev/socket-packageurl-js/issues/3\n\n/**\n * Alias for native `Object.freeze`.\n *\n * Freezes an object, preventing new properties from being added and existing\n * properties from being removed or modified. Makes the object immutable.\n *\n * @example\n * ```ts\n * const obj = { a: 1 }\n * objectFreeze(obj)\n * obj.a = 2 // Silently fails in non-strict mode, throws in strict mode\n * obj.b = 3 // Silently fails in non-strict mode, throws in strict mode\n * ```\n */\nexport const objectFreeze = Object.freeze\n\n/**\n * Deep merge source object into target object.\n *\n * Recursively merges properties from `source` into `target`. Arrays in source\n * completely replace arrays in target (no element-wise merging). Objects are\n * merged recursively. Includes infinite loop detection for safety.\n *\n * @param target - The object to merge into (will be modified)\n * @param source - The object to merge from\n * @returns The modified target object\n *\n * @example\n * ```ts\n * const target = { a: { x: 1 }, b: [1, 2] }\n * const source = { a: { y: 2 }, b: [3, 4, 5], c: 3 }\n * merge(target, source)\n * // { a: { x: 1, y: 2 }, b: [3, 4, 5], c: 3 }\n * ```\n *\n * @example\n * ```ts\n * // Arrays are replaced, not merged\n * merge({ arr: [1, 2] }, { arr: [3] }) // { arr: [3] }\n *\n * // Deep object merging\n * merge(\n * { config: { api: 'v1', timeout: 1000 } },\n * { config: { api: 'v2', retries: 3 } }\n * )\n * // { config: { api: 'v2', timeout: 1000, retries: 3 } }\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function merge<T extends object, U extends object>(\n target: T,\n source: U,\n): T & U {\n if (!isObject(target) || !isObject(source)) {\n return target as T & U\n }\n const queue: Array<[unknown, unknown]> = [[target, source]]\n let pos = 0\n let { length: queueLength } = queue\n while (pos < queueLength) {\n if (pos === LOOP_SENTINEL) {\n throw new Error('Detected infinite loop in object crawl of merge')\n }\n const { 0: currentTarget, 1: currentSource } = queue[pos++] as [\n Record<PropertyKey, unknown>,\n Record<PropertyKey, unknown>,\n ]\n\n if (!currentSource || !currentTarget) {\n continue\n }\n\n const isSourceArray = isArray(currentSource)\n const isTargetArray = isArray(currentTarget)\n\n // Skip array merging - arrays in source replace arrays in target\n if (isSourceArray || isTargetArray) {\n continue\n }\n\n const keys = ReflectOwnKeys(currentSource as object)\n for (let i = 0, { length } = keys; i < length; i += 1) {\n const key = keys[i] as PropertyKey\n const srcVal = currentSource[key]\n const targetVal = currentTarget[key]\n if (isArray(srcVal)) {\n // Replace arrays entirely\n currentTarget[key] = srcVal\n } else if (isObject(srcVal)) {\n if (isObject(targetVal) && !isArray(targetVal)) {\n queue[queueLength++] = [targetVal, srcVal]\n } else {\n currentTarget[key] = srcVal\n }\n } else {\n currentTarget[key] = srcVal\n }\n }\n }\n return target as T & U\n}\n\n/**\n * Convert an object to a new object with sorted keys.\n *\n * Creates a new object with the same properties as the input, but with keys\n * sorted alphabetically. Symbol keys are sorted separately and placed first.\n * This is useful for consistent key ordering in serialization or comparisons.\n *\n * @param obj - The object to sort\n * @returns A new object with sorted keys\n *\n * @example\n * ```ts\n * toSortedObject({ z: 1, a: 2, m: 3 })\n * // { a: 2, m: 3, z: 1 }\n *\n * const sym1 = Symbol('first')\n * const sym2 = Symbol('second')\n * toSortedObject({ z: 1, [sym2]: 2, a: 3, [sym1]: 4 })\n * // { [Symbol(first)]: 4, [Symbol(second)]: 2, a: 3, z: 1 }\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function toSortedObject<T extends object>(obj: T): T {\n return toSortedObjectFromEntries(objectEntries(obj)) as T\n}\n\n/**\n * Create an object from entries with sorted keys.\n *\n * Takes an iterable of [key, value] entries and creates a new object with\n * keys sorted alphabetically. Symbol keys are sorted separately and placed\n * first in the resulting object.\n *\n * @param entries - Iterable of [key, value] tuples\n * @returns A new object with sorted keys\n *\n * @example\n * ```ts\n * toSortedObjectFromEntries([['z', 1], ['a', 2], ['m', 3]])\n * // { a: 2, m: 3, z: 1 }\n *\n * const entries = new Map([['beta', 2], ['alpha', 1], ['gamma', 3]])\n * toSortedObjectFromEntries(entries)\n * // { alpha: 1, beta: 2, gamma: 3 }\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function toSortedObjectFromEntries<T = unknown>(\n entries: Iterable<[PropertyKey, T]>,\n): SortedObject<T> {\n const otherEntries = []\n const symbolEntries = []\n // Use for-of to work with entries iterators.\n for (const entry of entries) {\n if (typeof entry[0] === 'symbol') {\n symbolEntries.push(entry)\n } else {\n otherEntries.push(entry)\n }\n }\n if (!otherEntries.length && !symbolEntries.length) {\n return {}\n }\n return ObjectFromEntries([\n // The String constructor is safe to use with symbols.\n ...symbolEntries.sort(entryKeyComparator),\n ...otherEntries.sort(entryKeyComparator),\n ])\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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