@helpers4/object 2.0.0-alpha.2 → 2.0.0-alpha.21

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/lib/index.js CHANGED
@@ -1,78 +1,453 @@
1
- // helpers/object/get.ts
2
- function get(obj, path, defaultValue) {
3
- const keys = path.split(".");
4
- let result = obj;
5
- for (const key of keys) {
6
- if (result == null || typeof result !== "object") {
7
- return defaultValue;
8
- }
9
- result = result[key];
10
- }
11
- return result !== undefined ? result : defaultValue;
12
- }
13
- // helpers/object/set.ts
14
- function set(obj, path, value) {
15
- const keys = path.split(".");
16
- let current = obj;
17
- for (let i = 0;i < keys.length - 1; i++) {
18
- const key = keys[i];
19
- if (!(key in current) || typeof current[key] !== "object" || current[key] === null) {
20
- current[key] = {};
21
- }
22
- current = current[key];
23
- }
24
- current[keys[keys.length - 1]] = value;
25
- return obj;
26
- }
27
- // helpers/object/deepMerge.ts
1
+ //#region helpers/object/compact.ts
2
+ function compact(obj) {
3
+ if (obj === void 0 || obj === null) return obj;
4
+ const result = {};
5
+ for (const key of Object.keys(obj)) if (obj[key]) result[key] = obj[key];
6
+ return result;
7
+ }
8
+ //#endregion
9
+ //#region helpers/object/deepClone.ts
10
+ /**
11
+ * This file is part of helpers4.
12
+ * Copyright (C) 2025 baxyz
13
+ * SPDX-License-Identifier: LGPL-3.0-or-later
14
+ */
15
+ var UNSAFE_KEYS$2 = new Set([
16
+ "__proto__",
17
+ "constructor",
18
+ "prototype"
19
+ ]);
20
+ /**
21
+ * Creates a deep copy of an object or array
22
+ * @param obj - The object to clone
23
+ * @returns Deep cloned object
24
+ * @since 1.9.0
25
+ */
26
+ function deepClone(obj) {
27
+ if (obj === null || typeof obj !== "object") return obj;
28
+ if (obj instanceof Date) return new Date(obj.getTime());
29
+ if (Array.isArray(obj)) return obj.map((item) => deepClone(item));
30
+ const cloned = {};
31
+ for (const key in obj) if (Object.prototype.hasOwnProperty.call(obj, key) && !UNSAFE_KEYS$2.has(key)) cloned[key] = deepClone(obj[key]);
32
+ return cloned;
33
+ }
34
+ //#endregion
35
+ //#region helpers/array/shallowEquals.ts
36
+ /**
37
+ * This file is part of helpers4.
38
+ * Copyright (C) 2025 baxyz
39
+ * SPDX-License-Identifier: LGPL-3.0-or-later
40
+ */
41
+ /**
42
+ * Quick comparison of two arrays using JSON.stringify.
43
+ * This is a fast but simple comparison that may not work for all edge cases.
44
+ *
45
+ * @param arrA - First array to compare
46
+ * @param arrB - Second array to compare
47
+ * @returns `true` if arrays are identical according to JSON.stringify, `false` otherwise
48
+ * @since 2.0.0
49
+ */
50
+ function shallowEquals$1(arrA, arrB) {
51
+ try {
52
+ return JSON.stringify(arrA) === JSON.stringify(arrB);
53
+ } catch {
54
+ return arrA === arrB;
55
+ }
56
+ }
57
+ //#endregion
58
+ //#region helpers/date/timestamp.ts
59
+ /**
60
+ * Checks if a timestamp is likely in seconds (Java/Unix style) vs milliseconds (JavaScript style)
61
+ * @param timestamp - The timestamp to check
62
+ * @returns True if timestamp appears to be in seconds
63
+ * @since 1.9.0
64
+ */
65
+ function isTimestampInSeconds(timestamp) {
66
+ return Math.abs(timestamp) < 1e10;
67
+ }
68
+ /**
69
+ * Converts a timestamp to JavaScript milliseconds format
70
+ * @param timestamp - The timestamp (in seconds or milliseconds)
71
+ * @returns Timestamp in milliseconds
72
+ * @since 1.9.0
73
+ */
74
+ function normalizeTimestamp(timestamp) {
75
+ return isTimestampInSeconds(timestamp) ? timestamp * 1e3 : timestamp;
76
+ }
77
+ //#endregion
78
+ //#region helpers/date/ensureDate.ts
79
+ /**
80
+ * This file is part of helpers4.
81
+ * Copyright (C) 2025 baxyz
82
+ * SPDX-License-Identifier: LGPL-3.0-or-later
83
+ */
84
+ /**
85
+ * Type guard that checks whether a value satisfies the {@link EpochMilliseconds}
86
+ * structural interface (e.g. `Temporal.Instant`, `Temporal.ZonedDateTime`).
87
+ */
88
+ function hasEpochMilliseconds(value) {
89
+ return typeof value === "object" && value !== null && "epochMilliseconds" in value && typeof value.epochMilliseconds === "number";
90
+ }
91
+ /**
92
+ * Safely converts a date-like value to a valid `Date` object, or returns `null`.
93
+ *
94
+ * Accepts `Date`, timestamps (seconds or milliseconds, auto-detected), date strings,
95
+ * and objects with an `epochMilliseconds` property (e.g. `Temporal.Instant`,
96
+ * `Temporal.ZonedDateTime`).
97
+ * Returns `null` for `null`, `undefined`, empty strings, `0`, and any value that
98
+ * produces an invalid `Date`.
99
+ *
100
+ * This is the date equivalent of {@link ensureArray} — it normalizes flexible
101
+ * input into a guaranteed type (or a safe fallback).
102
+ *
103
+ * @param input - A date-like value to convert
104
+ * @returns A valid `Date` object, or `null` if the input is invalid
105
+ * @example
106
+ * ensureDate('2025-01-19T12:00:00Z') // => Date
107
+ * ensureDate(1737290400) // => Date (from Unix seconds)
108
+ * ensureDate(1737290400000) // => Date (from milliseconds)
109
+ * ensureDate(new Date()) // => Date (same reference)
110
+ * ensureDate(null) // => null
111
+ * ensureDate('invalid') // => null
112
+ *
113
+ * @see {@link DateLike} for the accepted input types
114
+ * @since 2.0.0
115
+ */
116
+ function ensureDate(input) {
117
+ if (input === null || input === void 0 || input === "" || input === 0) return null;
118
+ if (input instanceof Date) return isNaN(input.getTime()) ? null : input;
119
+ if (hasEpochMilliseconds(input)) {
120
+ const date = new Date(input.epochMilliseconds);
121
+ return isNaN(date.getTime()) ? null : date;
122
+ }
123
+ if (typeof input === "number") {
124
+ const normalized = normalizeTimestamp(input);
125
+ const date = new Date(normalized);
126
+ return isNaN(date.getTime()) ? null : date;
127
+ }
128
+ if (typeof input === "string") {
129
+ const date = new Date(input);
130
+ return isNaN(date.getTime()) ? null : date;
131
+ }
132
+ return null;
133
+ }
134
+ //#endregion
135
+ //#region helpers/date/compare.ts
136
+ /**
137
+ * This file is part of helpers4.
138
+ * Copyright (C) 2025 baxyz
139
+ * SPDX-License-Identifier: LGPL-3.0-or-later
140
+ */
141
+ /**
142
+ * Comparison of two dates.
143
+ *
144
+ * Accepts any {@link DateLike} input (Date, timestamp, or date string).
145
+ *
146
+ * @param dateA - First date to compare
147
+ * @param dateB - Second date to compare
148
+ * @param options - Comparison options
149
+ * @returns `true` if dates are identical according to the specified precision, `false` otherwise
150
+ * @example
151
+ * compare('2025-01-19', new Date('2025-01-19T08:00:00Z'), { precision: 'days' })
152
+ * // => true
153
+ * @since 2.0.0
154
+ */
155
+ function compare(dateA, dateB, options = {}) {
156
+ const { precision = "milliseconds" } = options;
157
+ const a = ensureDate(dateA);
158
+ const b = ensureDate(dateB);
159
+ if (a === null || b === null) return false;
160
+ switch (precision) {
161
+ case "years": return a.getFullYear() === b.getFullYear();
162
+ case "months": return a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth();
163
+ case "days": return a.toDateString() === b.toDateString();
164
+ case "hours": return Math.floor(a.getTime() / (1e3 * 60 * 60)) === Math.floor(b.getTime() / (1e3 * 60 * 60));
165
+ case "minutes": return Math.floor(a.getTime() / (1e3 * 60)) === Math.floor(b.getTime() / (1e3 * 60));
166
+ case "seconds": return Math.floor(a.getTime() / 1e3) === Math.floor(b.getTime() / 1e3);
167
+ default: return a.getTime() === b.getTime();
168
+ }
169
+ }
170
+ //#endregion
171
+ //#region helpers/type/isSpecialObject.ts
172
+ /**
173
+ * This file is part of helpers4.
174
+ * Copyright (C) 2025 baxyz
175
+ * SPDX-License-Identifier: LGPL-3.0-or-later
176
+ */
177
+ /**
178
+ * Determines if a value is a special object that should not have its properties compared deeply.
179
+ * Special objects include: Date, Function, Promise, Observable, RegExp, Error, Map, Set, WeakMap, WeakSet, etc.
180
+ *
181
+ * @param value - The value to check
182
+ * @returns `true` if the value is a special object, `false` otherwise
183
+ * @since 2.0.0
184
+ */
185
+ function isSpecialObject(value) {
186
+ if (value === null || value === void 0) return false;
187
+ if (typeof value === "function") return true;
188
+ if (typeof value !== "object") return false;
189
+ if (Array.isArray(value)) return false;
190
+ if (value instanceof Date || value instanceof Promise || value instanceof RegExp || value instanceof Error || value instanceof Map || value instanceof Set || value instanceof WeakMap || value instanceof WeakSet || value instanceof ArrayBuffer || value instanceof DataView) return true;
191
+ if (value.constructor?.name === "Observable") return true;
192
+ if (typeof HTMLElement !== "undefined" && value instanceof HTMLElement) return true;
193
+ const constructorName = value.constructor?.name;
194
+ if (constructorName && [
195
+ "Buffer",
196
+ "URL",
197
+ "URLSearchParams",
198
+ "File",
199
+ "Blob",
200
+ "FormData",
201
+ "Headers",
202
+ "Request",
203
+ "Response",
204
+ "EventTarget",
205
+ "Symbol"
206
+ ].includes(constructorName)) return true;
207
+ return false;
208
+ }
209
+ //#endregion
210
+ //#region helpers/object/deepCompare.ts
211
+ /**
212
+ * This file is part of helpers4.
213
+ * Copyright (C) 2025 baxyz
214
+ * SPDX-License-Identifier: LGPL-3.0-or-later
215
+ */
216
+ /**
217
+ * Deep comparison of two objects that returns detailed information about differences.
218
+ *
219
+ * @param objA - First object to compare (can be object, undefined, or null)
220
+ * @param objB - Second object to compare (can be object, undefined, or null)
221
+ * @returns `true` if objects are identical, `false` if incompatible types, or a `DeepCompareResult` object detailing differences
222
+ * @since 2.0.0
223
+ */
224
+ function deepCompare(objA, objB) {
225
+ if (objA === objB) return true;
226
+ if (objA == null || objB == null) return false;
227
+ if (objA instanceof Date && objB instanceof Date) return compare(objA, objB);
228
+ if (Array.isArray(objA) && Array.isArray(objB)) return shallowEquals$1(objA, objB);
229
+ if (Array.isArray(objA) || Array.isArray(objB)) return false;
230
+ if (isSpecialObject(objA) || isSpecialObject(objB)) return objA === objB;
231
+ const keys = Array.from(new Set([...Object.keys(objA), ...Object.keys(objB)]));
232
+ const differences = {};
233
+ for (const key of keys) {
234
+ const hasA = key in objA;
235
+ const hasB = key in objB;
236
+ if (!hasA && hasB) differences[key] = "onlyB";
237
+ else if (hasA && !hasB) differences[key] = "onlyA";
238
+ else {
239
+ const valueA = objA[key];
240
+ const valueB = objB[key];
241
+ if (Array.isArray(valueA) && Array.isArray(valueB)) {
242
+ if (!shallowEquals$1(valueA, valueB)) differences[key] = false;
243
+ } else if (valueA instanceof Date && valueB instanceof Date) {
244
+ if (!compare(valueA, valueB)) differences[key] = false;
245
+ } else if (isSpecialObject(valueA) || isSpecialObject(valueB)) {
246
+ if (valueA !== valueB) differences[key] = false;
247
+ } else if (valueA !== null && valueB !== null && valueA !== void 0 && valueB !== void 0 && typeof valueA === "object" && typeof valueB === "object" && !isSpecialObject(valueA) && !isSpecialObject(valueB)) {
248
+ const nestedResult = deepCompare(valueA, valueB);
249
+ if (nestedResult !== true) differences[key] = nestedResult === false ? false : nestedResult;
250
+ } else if (valueA !== valueB) differences[key] = false;
251
+ }
252
+ }
253
+ return Object.keys(differences).length > 0 ? differences : true;
254
+ }
255
+ //#endregion
256
+ //#region helpers/type/isPlainObject.ts
257
+ /**
258
+ * This file is part of helpers4.
259
+ * Copyright (C) 2025 baxyz
260
+ * SPDX-License-Identifier: LGPL-3.0-or-later
261
+ */
262
+ /**
263
+ * Checks if a value is a plain object.
264
+ *
265
+ * A plain object is created by `{}`, `new Object()`, or `Object.create(null)`.
266
+ * Returns `false` for arrays, Date, Map, Set, RegExp, class instances, etc.
267
+ *
268
+ * @param value - The value to check
269
+ * @returns True if value is a plain object
270
+ * @example
271
+ * isPlainObject({}) // => true
272
+ * isPlainObject({ a: 1 }) // => true
273
+ * isPlainObject(new Date()) // => false
274
+ * isPlainObject([]) // => false
275
+ * isPlainObject(null) // => false
276
+ * @since 2.0.0
277
+ */
278
+ function isPlainObject(value) {
279
+ if (value === null || typeof value !== "object") return false;
280
+ const proto = Object.getPrototypeOf(value);
281
+ return proto === Object.prototype || proto === null;
282
+ }
283
+ //#endregion
284
+ //#region helpers/object/deepMerge.ts
285
+ /**
286
+ * This file is part of helpers4.
287
+ * Copyright (C) 2025 baxyz
288
+ * SPDX-License-Identifier: LGPL-3.0-or-later
289
+ */
290
+ var UNSAFE_KEYS$1 = new Set([
291
+ "__proto__",
292
+ "constructor",
293
+ "prototype"
294
+ ]);
28
295
  function deepMerge(target, ...sources) {
29
- if (!sources.length)
30
- return target;
31
- const source = sources.shift();
32
- if (!source)
33
- return deepMerge(target, ...sources);
34
- for (const key in source) {
35
- const targetValue = target[key];
36
- const sourceValue = source[key];
37
- if (isObject(targetValue) && isObject(sourceValue)) {
38
- target[key] = deepMerge(targetValue, sourceValue);
39
- } else if (sourceValue !== undefined) {
40
- target[key] = sourceValue;
41
- }
42
- }
43
- return deepMerge(target, ...sources);
44
- }
45
- function isObject(item) {
46
- return item && typeof item === "object" && !Array.isArray(item);
47
- }
48
- // helpers/object/removeUndefinedNull.ts
49
- import { isNullish } from "radashi";
296
+ if (target === void 0 || target === null) return target;
297
+ if (!sources.length) return target;
298
+ const source = sources.shift();
299
+ if (!source) return deepMerge(target, ...sources);
300
+ for (const key in source) {
301
+ if (!Object.hasOwn(source, key) || UNSAFE_KEYS$1.has(key)) continue;
302
+ const targetValue = target[key];
303
+ const sourceValue = source[key];
304
+ if (isPlainObject(targetValue) && isPlainObject(sourceValue)) target[key] = deepMerge(targetValue, sourceValue);
305
+ else if (sourceValue !== void 0) target[key] = sourceValue;
306
+ }
307
+ return deepMerge(target, ...sources);
308
+ }
309
+ //#endregion
310
+ //#region helpers/object/get.ts
311
+ /**
312
+ * This file is part of helpers4.
313
+ * Copyright (C) 2025 baxyz
314
+ * SPDX-License-Identifier: LGPL-3.0-or-later
315
+ */
316
+ /**
317
+ * Gets a value from an object using a dot-notated path
318
+ * @param obj - The object to get value from
319
+ * @param path - The dot-notated path (e.g., 'a.b.c')
320
+ * @param defaultValue - Default value if path doesn't exist
321
+ * @returns The value at the path or default value
322
+ * @since 1.9.0
323
+ */
324
+ function get(obj, path, defaultValue) {
325
+ const keys = path.split(".");
326
+ let result = obj;
327
+ for (const key of keys) {
328
+ if (result == null || typeof result !== "object") return defaultValue;
329
+ result = result[key];
330
+ }
331
+ return result !== void 0 ? result : defaultValue;
332
+ }
333
+ //#endregion
334
+ //#region helpers/object/omit.ts
335
+ function omit(obj, keys) {
336
+ if (obj === void 0 || obj === null) return obj;
337
+ const result = { ...obj };
338
+ for (const key of keys) delete result[key];
339
+ return result;
340
+ }
341
+ //#endregion
342
+ //#region helpers/object/pick.ts
343
+ function pick(obj, keys) {
344
+ if (obj === void 0 || obj === null) return obj;
345
+ const result = {};
346
+ for (const key of keys) if (Object.prototype.hasOwnProperty.call(obj, key)) result[key] = obj[key];
347
+ return result;
348
+ }
349
+ //#endregion
350
+ //#region helpers/type/isNullish.ts
351
+ /**
352
+ * This file is part of helpers4.
353
+ * Copyright (C) 2025 baxyz
354
+ * SPDX-License-Identifier: LGPL-3.0-or-later
355
+ */
356
+ /**
357
+ * Checks if a value is null or undefined (nullish).
358
+ * @param value - The value to check
359
+ * @returns True if value is null or undefined
360
+ * @example
361
+ * isNullish(null) // => true
362
+ * isNullish(undefined) // => true
363
+ * isNullish(0) // => false
364
+ * isNullish('') // => false
365
+ *
366
+ * @see {@link isDefined} for the inverse check (`!isNullish`)
367
+ * @see {@link isFalsy} to also catch `0`, `""`, `false`, and `NaN`
368
+ * @since 2.0.0
369
+ */
370
+ function isNullish(value) {
371
+ return value === null || value === void 0;
372
+ }
373
+ //#endregion
374
+ //#region helpers/object/removeUndefinedNull.ts
375
+ /**
376
+ * This file is part of helpers4.
377
+ * Copyright (C) 2025 baxyz
378
+ * SPDX-License-Identifier: LGPL-3.0-or-later
379
+ */
380
+ /**
381
+ * Remove null and undefined values from an object.
382
+ *
383
+ * @param obj an object
384
+ * @returns A shallow copy of the object without null or undefined values
385
+ * @since 1.0.0
386
+ */
50
387
  function removeUndefinedNull(obj) {
51
- return obj ? Object.entries(obj).filter(([_, v]) => !isNullish(v)).reduce((acc, [k, v]) => ({ ...acc, [k]: v }), {}) : obj;
388
+ if (!obj) return obj;
389
+ const result = {};
390
+ for (const [k, v] of Object.entries(obj)) if (!isNullish(v)) result[k] = v;
391
+ return result;
52
392
  }
53
- // helpers/object/deepClone.ts
54
- function deepClone(obj) {
55
- if (obj === null || typeof obj !== "object") {
56
- return obj;
57
- }
58
- if (obj instanceof Date) {
59
- return new Date(obj.getTime());
60
- }
61
- if (Array.isArray(obj)) {
62
- return obj.map((item) => deepClone(item));
63
- }
64
- const cloned = {};
65
- for (const key in obj) {
66
- if (obj.hasOwnProperty(key)) {
67
- cloned[key] = deepClone(obj[key]);
68
- }
69
- }
70
- return cloned;
71
- }
72
- export {
73
- set,
74
- removeUndefinedNull,
75
- get,
76
- deepMerge,
77
- deepClone
78
- };
393
+ //#endregion
394
+ //#region helpers/object/set.ts
395
+ /**
396
+ * This file is part of helpers4.
397
+ * Copyright (C) 2025 baxyz
398
+ * SPDX-License-Identifier: LGPL-3.0-or-later
399
+ */
400
+ var UNSAFE_KEYS = new Set([
401
+ "__proto__",
402
+ "constructor",
403
+ "prototype"
404
+ ]);
405
+ /**
406
+ * Sets a value in an object using a dot-notated path
407
+ * @param obj - The object to set value in
408
+ * @param path - The dot-notated path (e.g., 'a.b.c')
409
+ * @param value - The value to set
410
+ * @returns The modified object
411
+ * @since 1.9.0
412
+ */
413
+ function set(obj, path, value) {
414
+ const keys = path.split(".");
415
+ if (keys.some((k) => UNSAFE_KEYS.has(k))) return obj;
416
+ let current = obj;
417
+ for (let i = 0; i < keys.length - 1; i++) {
418
+ const key = keys[i];
419
+ if (!(key in current) || typeof current[key] !== "object" || current[key] === null) current[key] = {};
420
+ current = current[key];
421
+ }
422
+ current[keys[keys.length - 1]] = value;
423
+ return obj;
424
+ }
425
+ //#endregion
426
+ //#region helpers/object/shallowEquals.ts
427
+ /**
428
+ * This file is part of helpers4.
429
+ * Copyright (C) 2025 baxyz
430
+ * SPDX-License-Identifier: LGPL-3.0-or-later
431
+ */
432
+ /**
433
+ * Quick comparison of two objects using JSON.stringify.
434
+ * This is a fast but simple comparison that may not work for all edge cases.
435
+ *
436
+ * @param objA - First object to compare
437
+ * @param objB - Second object to compare
438
+ * @returns `true` if objects are identical according to JSON.stringify, `false` otherwise
439
+ * @since 2.0.0
440
+ */
441
+ function shallowEquals(objA, objB) {
442
+ if (objA === objB) return true;
443
+ if (typeof objA === "function" || typeof objB === "function") return objA === objB;
444
+ try {
445
+ return JSON.stringify(objA) === JSON.stringify(objB);
446
+ } catch {
447
+ return objA === objB;
448
+ }
449
+ }
450
+ //#endregion
451
+ export { compact, deepClone, deepCompare, deepMerge, get, omit, pick, removeUndefinedNull, set, shallowEquals };
452
+
453
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../helpers/object/compact.ts","../../../helpers/object/deepClone.ts","../../../helpers/array/shallowEquals.ts","../../../helpers/date/timestamp.ts","../../../helpers/date/ensureDate.ts","../../../helpers/date/compare.ts","../../../helpers/type/isSpecialObject.ts","../../../helpers/object/deepCompare.ts","../../../helpers/type/isPlainObject.ts","../../../helpers/object/deepMerge.ts","../../../helpers/object/get.ts","../../../helpers/object/omit.ts","../../../helpers/object/pick.ts","../../../helpers/type/isNullish.ts","../../../helpers/object/removeUndefinedNull.ts","../../../helpers/object/set.ts","../../../helpers/object/shallowEquals.ts"],"sourcesContent":["/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Removes all entries with falsy values (`false`, `null`, `undefined`, `0`, `\"\"`, `NaN`) from an object.\n * @param obj - The source object\n * @returns A new object containing only entries with truthy values\n * @example\n * compact({ a: 1, b: null, c: '', d: 0, e: 'hello' })\n * // => { a: 1, e: 'hello' }\n * @since 2.0.0\n */\nexport function compact<T extends Record<string, unknown>>(obj: T): Partial<T>;\nexport function compact(obj: undefined): undefined;\nexport function compact(obj: null): null;\nexport function compact<T extends Record<string, unknown>>(obj: T | undefined | null): Partial<T> | undefined | null {\n if (obj === undefined || obj === null) return obj;\n const result: Partial<T> = {};\n for (const key of Object.keys(obj) as (keyof T)[]) {\n if (obj[key]) {\n result[key] = obj[key];\n }\n }\n return result;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\nconst UNSAFE_KEYS = new Set(['__proto__', 'constructor', 'prototype']);\n\n/**\n * Creates a deep copy of an object or array\n * @param obj - The object to clone\n * @returns Deep cloned object\n * @since 1.9.0\n */\nexport function deepClone<T>(obj: T): T {\n if (obj === null || typeof obj !== \"object\") {\n return obj;\n }\n\n if (obj instanceof Date) {\n return new Date(obj.getTime()) as T;\n }\n\n if (Array.isArray(obj)) {\n return obj.map(item => deepClone(item)) as T;\n }\n\n const cloned = {} as T;\n for (const key in obj) {\n if (Object.prototype.hasOwnProperty.call(obj, key) && !UNSAFE_KEYS.has(key)) {\n cloned[key] = deepClone(obj[key]);\n }\n }\n\n return cloned;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Quick comparison of two arrays using JSON.stringify.\n * This is a fast but simple comparison that may not work for all edge cases.\n *\n * @param arrA - First array to compare\n * @param arrB - Second array to compare\n * @returns `true` if arrays are identical according to JSON.stringify, `false` otherwise\n * @since 2.0.0\n */\nexport function shallowEquals<T>(arrA: T[], arrB: T[]): boolean {\n try {\n return JSON.stringify(arrA) === JSON.stringify(arrB);\n } catch {\n // If JSON.stringify fails (e.g., circular references), fall back to reference equality\n return arrA === arrB;\n }\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\nimport { ensureDate } from './ensureDate';\nimport type { DateLike } from './types.model';\n\n/**\n * Checks if a timestamp is likely in seconds (Java/Unix style) vs milliseconds (JavaScript style)\n * @param timestamp - The timestamp to check\n * @returns True if timestamp appears to be in seconds\n * @since 1.9.0\n */\nexport function isTimestampInSeconds(timestamp: number): boolean {\n // Timestamps before year 2001 in milliseconds are less than 10^10\n // Use Math.abs to correctly handle negative timestamps (before epoch)\n return Math.abs(timestamp) < 10000000000;\n}\n\n/**\n * Converts a timestamp to JavaScript milliseconds format\n * @param timestamp - The timestamp (in seconds or milliseconds)\n * @returns Timestamp in milliseconds\n * @since 1.9.0\n */\nexport function normalizeTimestamp(timestamp: number): number {\n return isTimestampInSeconds(timestamp) ? timestamp * 1000 : timestamp;\n}\n\n/**\n * Converts a date to a timestamp in **seconds** (epoch seconds).\n *\n * Use this when sending a date to a backend API that expects seconds\n * (e.g. Java `Instant.getEpochSecond()`, Python `time.time()`).\n *\n * @param date - The date to convert\n * @returns Seconds since the Unix epoch, or `null` for invalid input\n * @example\n * toSeconds('2025-01-19T12:00:00Z') // => 1737288000\n * toSeconds(null) // => null\n *\n * @since 2.0.0\n */\nexport function toSeconds(date: DateLike): number | null {\n const d = ensureDate(date);\n if (!d) return null;\n return Math.floor(d.getTime() / 1000);\n}\n\n/**\n * Converts a date to a timestamp in **milliseconds** (epoch millis).\n *\n * Use this when you need a plain number from a `DateLike` value\n * (e.g. for `Date.now()` comparisons, localStorage, or JS-native APIs).\n *\n * @param date - The date to convert\n * @returns Milliseconds since the Unix epoch, or `null` for invalid input\n * @example\n * toMillis('2025-01-19T12:00:00Z') // => 1737288000000\n * toMillis(null) // => null\n *\n * @since 2.0.0\n */\nexport function toMillis(date: DateLike): number | null {\n const d = ensureDate(date);\n if (!d) return null;\n return d.getTime();\n}\n\n/**\n * Creates a `Date` from a timestamp in **seconds**.\n *\n * Use this when receiving a timestamp from a backend that sends seconds\n * (e.g. Java `Instant.getEpochSecond()`). No heuristic — the input is\n * always treated as seconds.\n *\n * @param seconds - Seconds since the Unix epoch\n * @returns A valid `Date`, or `null` for `NaN` / non-finite input\n * @example\n * fromSeconds(1737288000) // => Date('2025-01-19T12:00:00Z')\n * fromSeconds(0) // => Date('1970-01-01T00:00:00Z')\n * fromSeconds(NaN) // => null\n *\n * @since 2.0.0\n */\nexport function fromSeconds(seconds: number): Date | null {\n if (!Number.isFinite(seconds)) return null;\n return new Date(seconds * 1000);\n}\n\n/**\n * Creates a `Date` from a timestamp in **milliseconds**.\n *\n * Use this when receiving a timestamp from a JS-native source\n * (e.g. `Date.now()`, `performance.timeOrigin`). No heuristic — the\n * input is always treated as milliseconds.\n *\n * @param ms - Milliseconds since the Unix epoch\n * @returns A valid `Date`, or `null` for `NaN` / non-finite input\n * @example\n * fromMillis(1737288000000) // => Date('2025-01-19T12:00:00Z')\n * fromMillis(0) // => Date('1970-01-01T00:00:00Z')\n * fromMillis(NaN) // => null\n *\n * @since 2.0.0\n */\nexport function fromMillis(ms: number): Date | null {\n if (!Number.isFinite(ms)) return null;\n return new Date(ms);\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\nimport { normalizeTimestamp } from './timestamp';\nimport type { DateLike, EpochMilliseconds } from './types.model';\n\n/**\n * Type guard that checks whether a value satisfies the {@link EpochMilliseconds}\n * structural interface (e.g. `Temporal.Instant`, `Temporal.ZonedDateTime`).\n */\nfunction hasEpochMilliseconds(value: unknown): value is EpochMilliseconds {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'epochMilliseconds' in value &&\n typeof (value as EpochMilliseconds).epochMilliseconds === 'number'\n );\n}\n\n/**\n * Safely converts a date-like value to a valid `Date` object, or returns `null`.\n *\n * Accepts `Date`, timestamps (seconds or milliseconds, auto-detected), date strings,\n * and objects with an `epochMilliseconds` property (e.g. `Temporal.Instant`,\n * `Temporal.ZonedDateTime`).\n * Returns `null` for `null`, `undefined`, empty strings, `0`, and any value that\n * produces an invalid `Date`.\n *\n * This is the date equivalent of {@link ensureArray} — it normalizes flexible\n * input into a guaranteed type (or a safe fallback).\n *\n * @param input - A date-like value to convert\n * @returns A valid `Date` object, or `null` if the input is invalid\n * @example\n * ensureDate('2025-01-19T12:00:00Z') // => Date\n * ensureDate(1737290400) // => Date (from Unix seconds)\n * ensureDate(1737290400000) // => Date (from milliseconds)\n * ensureDate(new Date()) // => Date (same reference)\n * ensureDate(null) // => null\n * ensureDate('invalid') // => null\n *\n * @see {@link DateLike} for the accepted input types\n * @since 2.0.0\n */\nexport function ensureDate(input: DateLike | null | undefined): Date | null {\n if (input === null || input === undefined || input === '' || input === 0) {\n return null;\n }\n\n if (input instanceof Date) {\n return isNaN(input.getTime()) ? null : input;\n }\n\n if (hasEpochMilliseconds(input)) {\n const date = new Date(input.epochMilliseconds);\n return isNaN(date.getTime()) ? null : date;\n }\n\n if (typeof input === 'number') {\n const normalized = normalizeTimestamp(input);\n const date = new Date(normalized);\n return isNaN(date.getTime()) ? null : date;\n }\n\n if (typeof input === 'string') {\n const date = new Date(input);\n return isNaN(date.getTime()) ? null : date;\n }\n\n return null;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\nimport { ensureDate } from './ensureDate';\nimport type { DateLike } from './types.model';\n\n/**\n * Options for date comparison\n * @since 2.0.0\n */\nexport interface DateCompareOptions {\n /**\n * Comparison precision\n * - 'milliseconds': Compare all including milliseconds (default)\n * - 'seconds': Ignore milliseconds, compare to the second\n * - 'minutes': Ignore seconds and milliseconds, compare to the minute\n * - 'hours': Ignore minutes, seconds and milliseconds, compare to the hour\n * - 'days': Compare only the date part (ignore time completely)\n * - 'months': Compare only year and month\n * - 'years': Compare only year\n */\n precision?: 'milliseconds' | 'seconds' | 'minutes' | 'hours' | 'days' | 'months' | 'years';\n}\n\n/**\n * Comparison of two dates.\n *\n * Accepts any {@link DateLike} input (Date, timestamp, or date string).\n *\n * @param dateA - First date to compare\n * @param dateB - Second date to compare\n * @param options - Comparison options\n * @returns `true` if dates are identical according to the specified precision, `false` otherwise\n * @example\n * compare('2025-01-19', new Date('2025-01-19T08:00:00Z'), { precision: 'days' })\n * // => true\n * @since 2.0.0\n */\nexport function compare(dateA: DateLike, dateB: DateLike, options: DateCompareOptions = {}): boolean {\n const { precision = 'milliseconds' } = options;\n\n const a = ensureDate(dateA);\n const b = ensureDate(dateB);\n\n // Any invalid → not equal\n if (a === null || b === null) {\n return false;\n }\n\n switch (precision) {\n case 'years':\n return a.getFullYear() === b.getFullYear();\n\n case 'months':\n return a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth();\n\n case 'days':\n return a.toDateString() === b.toDateString();\n\n case 'hours': {\n const hoursA = Math.floor(a.getTime() / (1000 * 60 * 60));\n const hoursB = Math.floor(b.getTime() / (1000 * 60 * 60));\n return hoursA === hoursB;\n }\n\n case 'minutes': {\n const minutesA = Math.floor(a.getTime() / (1000 * 60));\n const minutesB = Math.floor(b.getTime() / (1000 * 60));\n return minutesA === minutesB;\n }\n\n case 'seconds': {\n const secondsA = Math.floor(a.getTime() / 1000);\n const secondsB = Math.floor(b.getTime() / 1000);\n return secondsA === secondsB;\n }\n\n case 'milliseconds':\n default:\n return a.getTime() === b.getTime();\n }\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Determines if a value is a special object that should not have its properties compared deeply.\n * Special objects include: Date, Function, Promise, Observable, RegExp, Error, Map, Set, WeakMap, WeakSet, etc.\n * \n * @param value - The value to check\n * @returns `true` if the value is a special object, `false` otherwise\n * @since 2.0.0\n */\nexport function isSpecialObject(value: unknown): boolean {\n if (value === null || value === undefined) {\n return false;\n }\n\n // Functions are special objects\n if (typeof value === 'function') {\n return true;\n }\n\n // Non-objects are not special\n if (typeof value !== 'object') {\n return false;\n }\n\n // Arrays are not considered special objects for our purposes\n if (Array.isArray(value)) {\n return false;\n }\n\n // Check for built-in special objects\n if (\n value instanceof Date ||\n value instanceof Promise ||\n value instanceof RegExp ||\n value instanceof Error ||\n value instanceof Map ||\n value instanceof Set ||\n value instanceof WeakMap ||\n value instanceof WeakSet ||\n value instanceof ArrayBuffer ||\n value instanceof DataView\n ) {\n return true;\n }\n\n // Check for Observable (RxJS or similar)\n if (value.constructor?.name === 'Observable') {\n return true;\n }\n\n // Check for DOM elements (if in browser environment)\n if (typeof HTMLElement !== 'undefined' && value instanceof HTMLElement) {\n return true;\n }\n\n // Check for other built-in types by constructor name\n const constructorName = value.constructor?.name;\n if (constructorName && [\n 'Buffer', // Node.js Buffer\n 'URL', // Web URL API\n 'URLSearchParams',\n 'File', // Web File API\n 'Blob', // Web Blob API\n 'FormData', // Web FormData API\n 'Headers', // Web Headers API\n 'Request', // Web Request API\n 'Response', // Web Response API\n 'EventTarget', // Web EventTarget API\n 'Symbol' // Symbol objects\n ].includes(constructorName)) {\n return true;\n }\n\n return false;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\nimport { shallowEquals as shallowEqualsArray } from '../array/shallowEquals';\nimport { compare as compareDate } from '../date/compare';\nimport { isSpecialObject } from '../type/isSpecialObject';\n\n/**\n * Result type for deep comparison when objects are not identical\n * @since 2.0.0\n */\nexport interface DeepCompareResult {\n [key: string]: \"onlyA\" | \"onlyB\" | false | DeepCompareResult;\n}\n\n/**\n * Deep comparison of two objects that returns detailed information about differences.\n *\n * @param objA - First object to compare (can be object, undefined, or null)\n * @param objB - Second object to compare (can be object, undefined, or null)\n * @returns `true` if objects are identical, `false` if incompatible types, or a `DeepCompareResult` object detailing differences\n * @since 2.0.0\n */\nexport function deepCompare(objA: object | undefined | null, objB: object | undefined | null): true | false | DeepCompareResult {\n // Quick reference equality check\n if (objA === objB) {\n return true;\n }\n\n // Handle null/undefined cases\n if (objA == null || objB == null) {\n return false;\n }\n\n // Handle Date objects\n if (objA instanceof Date && objB instanceof Date) {\n return compareDate(objA, objB);\n }\n\n // Handle Arrays at root level - use shallowEquals\n if (Array.isArray(objA) && Array.isArray(objB)) {\n return shallowEqualsArray(objA, objB);\n }\n\n // If one is array and other is not\n if (Array.isArray(objA) || Array.isArray(objB)) {\n return false;\n }\n\n // Handle special objects - compare by reference only\n if (isSpecialObject(objA) || isSpecialObject(objB)) {\n return objA === objB;\n }\n\n // Handle objects - detailed comparison\n const keys = Array.from(new Set([...Object.keys(objA), ...Object.keys(objB)]));\n\n const differences: DeepCompareResult = {};\n\n for (const key of keys) {\n const hasA = key in objA;\n const hasB = key in objB;\n\n if (!hasA && hasB) {\n differences[key] = \"onlyB\";\n } else if (hasA && !hasB) {\n differences[key] = \"onlyA\";\n } else {\n // Both objects have this key - compare values\n const valueA = (objA as Record<string, unknown>)[key];\n const valueB = (objB as Record<string, unknown>)[key];\n\n // For arrays, use shallowEquals\n if (Array.isArray(valueA) && Array.isArray(valueB)) {\n if (!shallowEqualsArray(valueA, valueB)) {\n differences[key] = false;\n }\n }\n // For dates, use compareDate\n else if (valueA instanceof Date && valueB instanceof Date) {\n if (!compareDate(valueA, valueB)) {\n differences[key] = false;\n }\n }\n // For special objects, compare by reference only\n else if (isSpecialObject(valueA) || isSpecialObject(valueB)) {\n if (valueA !== valueB) {\n differences[key] = false;\n }\n }\n // For objects, recurse (only plain objects now)\n else if (\n valueA !== null && valueB !== null &&\n valueA !== undefined && valueB !== undefined &&\n typeof valueA === 'object' && typeof valueB === 'object' &&\n !isSpecialObject(valueA) && !isSpecialObject(valueB)\n ) {\n const nestedResult = deepCompare(valueA, valueB);\n if (nestedResult !== true) {\n differences[key] = nestedResult === false ? false : nestedResult;\n }\n }\n // For primitives and other types, check equality\n else if (valueA !== valueB) {\n differences[key] = false;\n }\n }\n }\n\n return Object.keys(differences).length > 0 ? differences : true;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Checks if a value is a plain object.\n *\n * A plain object is created by `{}`, `new Object()`, or `Object.create(null)`.\n * Returns `false` for arrays, Date, Map, Set, RegExp, class instances, etc.\n *\n * @param value - The value to check\n * @returns True if value is a plain object\n * @example\n * isPlainObject({}) // => true\n * isPlainObject({ a: 1 }) // => true\n * isPlainObject(new Date()) // => false\n * isPlainObject([]) // => false\n * isPlainObject(null) // => false\n * @since 2.0.0\n */\nexport function isPlainObject(value: unknown): value is Record<string, unknown> {\n if (value === null || typeof value !== 'object') return false;\n const proto = Object.getPrototypeOf(value);\n return proto === Object.prototype || proto === null;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\nimport { isPlainObject } from '../type/isPlainObject';\n\nconst UNSAFE_KEYS = new Set(['__proto__', 'constructor', 'prototype']);\n\n/**\n * Merges two or more objects deeply\n * @param target - The target object\n * @param sources - The source objects to merge\n * @returns The merged object\n * @since 1.9.0\n */\nexport function deepMerge<T extends Record<string, unknown>>(target: T, ...sources: Record<string, unknown>[]): T;\nexport function deepMerge(target: undefined, ...sources: Record<string, unknown>[]): undefined;\nexport function deepMerge(target: null, ...sources: Record<string, unknown>[]): null;\nexport function deepMerge<T extends Record<string, unknown>>(target: T | undefined | null, ...sources: Record<string, unknown>[]): T | undefined | null {\n if (target === undefined || target === null) return target;\n if (!sources.length) return target;\n const source = sources.shift();\n\n if (!source) return deepMerge(target, ...sources);\n\n for (const key in source) {\n if (!Object.hasOwn(source, key) || UNSAFE_KEYS.has(key)) continue;\n\n const targetValue = target[key];\n const sourceValue = source[key];\n\n if (isPlainObject(targetValue) && isPlainObject(sourceValue)) {\n (target as Record<string, unknown>)[key] = deepMerge(targetValue as Record<string, unknown>, sourceValue as Record<string, unknown>);\n } else if (sourceValue !== undefined) {\n (target as Record<string, unknown>)[key] = sourceValue;\n }\n }\n\n return deepMerge(target, ...sources);\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Gets a value from an object using a dot-notated path\n * @param obj - The object to get value from\n * @param path - The dot-notated path (e.g., 'a.b.c')\n * @param defaultValue - Default value if path doesn't exist\n * @returns The value at the path or default value\n * @since 1.9.0\n */\nexport function get<T = unknown>(obj: unknown, path: string, defaultValue?: T): T | undefined {\n const keys = path.split('.');\n let result: unknown = obj;\n\n for (const key of keys) {\n if (result == null || typeof result !== 'object') {\n return defaultValue;\n }\n result = (result as Record<string, unknown>)[key];\n }\n\n return result !== undefined ? result as T | undefined : defaultValue;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Creates a new object without the specified keys.\n * @param obj - The source object\n * @param keys - The keys to omit\n * @returns A new object without the omitted keys\n * @example\n * omit({ a: 1, b: 2, c: 3 }, ['b'])\n * // => { a: 1, c: 3 }\n * @since 2.0.0\n */\nexport function omit<T extends Record<string, unknown>, K extends keyof T>(obj: T, keys: readonly K[]): Omit<T, K>;\nexport function omit(obj: undefined, keys: readonly string[]): undefined;\nexport function omit(obj: null, keys: readonly string[]): null;\nexport function omit<T extends Record<string, unknown>, K extends keyof T>(\n obj: T | undefined | null,\n keys: readonly K[]\n): Omit<T, K> | undefined | null {\n if (obj === undefined || obj === null) return obj;\n const result = { ...obj };\n for (const key of keys) {\n delete result[key];\n }\n return result as Omit<T, K>;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Creates a new object with only the specified keys.\n * @param obj - The source object\n * @param keys - The keys to pick\n * @returns A new object with only the picked keys\n * @example\n * pick({ a: 1, b: 2, c: 3 }, ['a', 'c'])\n * // => { a: 1, c: 3 }\n * @since 2.0.0\n */\nexport function pick<T extends Record<string, unknown>, K extends keyof T>(obj: T, keys: readonly K[]): Pick<T, K>;\nexport function pick(obj: undefined, keys: readonly string[]): undefined;\nexport function pick(obj: null, keys: readonly string[]): null;\nexport function pick<T extends Record<string, unknown>, K extends keyof T>(\n obj: T | undefined | null,\n keys: readonly K[]\n): Pick<T, K> | undefined | null {\n if (obj === undefined || obj === null) return obj;\n const result = {} as Pick<T, K>;\n for (const key of keys) {\n if (Object.prototype.hasOwnProperty.call(obj, key)) {\n result[key] = obj[key];\n }\n }\n return result;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Checks if a value is null or undefined (nullish).\n * @param value - The value to check\n * @returns True if value is null or undefined\n * @example\n * isNullish(null) // => true\n * isNullish(undefined) // => true\n * isNullish(0) // => false\n * isNullish('') // => false\n *\n * @see {@link isDefined} for the inverse check (`!isNullish`)\n * @see {@link isFalsy} to also catch `0`, `\"\"`, `false`, and `NaN`\n * @since 2.0.0\n */\nexport function isNullish(value: unknown): value is null | undefined {\n return value === null || value === undefined;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\nimport { isNullish } from '../type/isNullish';\n\n/**\n * Remove null and undefined values from an object.\n *\n * @param obj an object\n * @returns A shallow copy of the object without null or undefined values\n * @since 1.0.0\n */\nexport function removeUndefinedNull<T extends Record<string, string | number | boolean | null | undefined>>(obj: T): Partial<T>;\n\n/**\n * Remove null and undefined values from an object.\n *\n * @param obj a null object\n * @returns null\n * @since 1.0.0\n */\nexport function removeUndefinedNull(obj: null): null;\n\n/**\n * Remove null and undefined values from an object.\n *\n * @param obj an undefined object\n * @returns undefined\n * @since 1.0.0\n */\nexport function removeUndefinedNull(obj: undefined): undefined;\n\n/**\n * Remove null and undefined values from an object.\n *\n * @param obj an object\n * @returns A shallow copy of the object without null or undefined values\n * @since 1.0.0\n */\nexport function removeUndefinedNull<T extends Record<string, string | number | boolean | null | undefined>>(obj: T | null | undefined): Partial<T> | null | undefined {\n if (!obj) return obj;\n const result: Record<string, unknown> = {};\n for (const [k, v] of Object.entries(obj)) {\n if (!isNullish(v)) { result[k] = v; }\n }\n return result as Partial<T>;\n}\n\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\nconst UNSAFE_KEYS = new Set(['__proto__', 'constructor', 'prototype']);\n\n/**\n * Sets a value in an object using a dot-notated path\n * @param obj - The object to set value in\n * @param path - The dot-notated path (e.g., 'a.b.c')\n * @param value - The value to set\n * @returns The modified object\n * @since 1.9.0\n */\nexport function set(obj: Record<string, unknown>, path: string, value: unknown): Record<string, unknown> {\n const keys = path.split('.');\n\n if (keys.some((k) => UNSAFE_KEYS.has(k))) return obj;\n\n let current: Record<string, unknown> = obj;\n\n for (let i = 0; i < keys.length - 1; i++) {\n const key = keys[i];\n\n if (!(key in current) || typeof current[key] !== 'object' || current[key] === null) {\n current[key] = {};\n }\n\n current = current[key] as Record<string, unknown>;\n }\n\n current[keys[keys.length - 1]] = value;\n return obj;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Quick comparison of two objects using JSON.stringify.\n * This is a fast but simple comparison that may not work for all edge cases.\n *\n * @param objA - First object to compare\n * @param objB - Second object to compare\n * @returns `true` if objects are identical according to JSON.stringify, `false` otherwise\n * @since 2.0.0\n */\nexport function shallowEquals(objA: unknown, objB: unknown): boolean {\n // Quick reference equality check\n if (objA === objB) {\n return true;\n }\n\n // Handle functions - they can't be JSON.stringified reliably\n if (typeof objA === 'function' || typeof objB === 'function') {\n return objA === objB;\n }\n\n try {\n return JSON.stringify(objA) === JSON.stringify(objB);\n } catch {\n // If JSON.stringify fails (e.g., circular references), fall back to basic comparison\n return objA === objB;\n }\n}\n"],"mappings":";AAkBA,SAAgB,QAA2C,KAA0D;AACnH,KAAI,QAAQ,KAAA,KAAa,QAAQ,KAAM,QAAO;CAC9C,MAAM,SAAqB,EAAE;AAC7B,MAAK,MAAM,OAAO,OAAO,KAAK,IAAI,CAChC,KAAI,IAAI,KACN,QAAO,OAAO,IAAI;AAGtB,QAAO;;;;;;;;;ACpBT,IAAM,gBAAc,IAAI,IAAI;CAAC;CAAa;CAAe;CAAY,CAAC;;;;;;;AAQtE,SAAgB,UAAa,KAAW;AACtC,KAAI,QAAQ,QAAQ,OAAO,QAAQ,SACjC,QAAO;AAGT,KAAI,eAAe,KACjB,QAAO,IAAI,KAAK,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