@helpers4/object 2.0.0-alpha.7 → 2.0.0-alpha.8
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.d.ts +10 -0
- package/lib/index.js +10 -0
- package/lib/index.js.map +1 -1
- package/meta/api.json +331 -0
- package/{examples.json → meta/examples.json} +8 -8
- package/package.json +6 -8
- package/api.json +0 -143
- /package/{licenses.json → meta/licenses.json} +0 -0
package/lib/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* Creates a deep copy of an object or array
|
|
8
8
|
* @param obj - The object to clone
|
|
9
9
|
* @returns Deep cloned object
|
|
10
|
+
* @since 1.9.0
|
|
10
11
|
*/
|
|
11
12
|
declare function deepClone<T>(obj: T): T;
|
|
12
13
|
|
|
@@ -17,6 +18,7 @@ declare function deepClone<T>(obj: T): T;
|
|
|
17
18
|
*/
|
|
18
19
|
/**
|
|
19
20
|
* Result type for deep comparison when objects are not identical
|
|
21
|
+
* @since 2.0.0
|
|
20
22
|
*/
|
|
21
23
|
interface DeepCompareResult {
|
|
22
24
|
[key: string]: "onlyA" | "onlyB" | false | DeepCompareResult;
|
|
@@ -27,6 +29,7 @@ interface DeepCompareResult {
|
|
|
27
29
|
* @param objA - First object to compare (can be object, undefined, or null)
|
|
28
30
|
* @param objB - Second object to compare (can be object, undefined, or null)
|
|
29
31
|
* @returns `true` if objects are identical, `false` if incompatible types, or a `DeepCompareResult` object detailing differences
|
|
32
|
+
* @since 2.0.0
|
|
30
33
|
*/
|
|
31
34
|
declare function deepCompare(objA: object | undefined | null, objB: object | undefined | null): true | false | DeepCompareResult;
|
|
32
35
|
|
|
@@ -40,6 +43,7 @@ declare function deepCompare(objA: object | undefined | null, objB: object | und
|
|
|
40
43
|
* @param target - The target object
|
|
41
44
|
* @param sources - The source objects to merge
|
|
42
45
|
* @returns The merged object
|
|
46
|
+
* @since 1.9.0
|
|
43
47
|
*/
|
|
44
48
|
declare function deepMerge<T extends Record<string, any>>(target: T, ...sources: Record<string, any>[]): T;
|
|
45
49
|
|
|
@@ -54,6 +58,7 @@ declare function deepMerge<T extends Record<string, any>>(target: T, ...sources:
|
|
|
54
58
|
* @param path - The dot-notated path (e.g., 'a.b.c')
|
|
55
59
|
* @param defaultValue - Default value if path doesn't exist
|
|
56
60
|
* @returns The value at the path or default value
|
|
61
|
+
* @since 1.9.0
|
|
57
62
|
*/
|
|
58
63
|
declare function get<T = any>(obj: any, path: string, defaultValue?: T): T | undefined;
|
|
59
64
|
|
|
@@ -69,6 +74,7 @@ declare function get<T = any>(obj: any, path: string, defaultValue?: T): T | und
|
|
|
69
74
|
* @param objA - First object to compare
|
|
70
75
|
* @param objB - Second object to compare
|
|
71
76
|
* @returns `true` if objects are identical according to JSON.stringify, `false` otherwise
|
|
77
|
+
* @since 2.0.0
|
|
72
78
|
*/
|
|
73
79
|
declare function quickCompare(objA: unknown, objB: unknown): boolean;
|
|
74
80
|
|
|
@@ -82,6 +88,7 @@ declare function quickCompare(objA: unknown, objB: unknown): boolean;
|
|
|
82
88
|
*
|
|
83
89
|
* @param obj an object
|
|
84
90
|
* @returns A shallow copy of the object without null or undefined values
|
|
91
|
+
* @since 1.0.0
|
|
85
92
|
*/
|
|
86
93
|
declare function removeUndefinedNull<T extends Record<string, string | number | boolean | null | undefined>>(obj: T): Partial<T>;
|
|
87
94
|
/**
|
|
@@ -89,6 +96,7 @@ declare function removeUndefinedNull<T extends Record<string, string | number |
|
|
|
89
96
|
*
|
|
90
97
|
* @param obj a null object
|
|
91
98
|
* @returns null
|
|
99
|
+
* @since 1.0.0
|
|
92
100
|
*/
|
|
93
101
|
declare function removeUndefinedNull(obj: null): null;
|
|
94
102
|
/**
|
|
@@ -96,6 +104,7 @@ declare function removeUndefinedNull(obj: null): null;
|
|
|
96
104
|
*
|
|
97
105
|
* @param obj an undefined object
|
|
98
106
|
* @returns undefined
|
|
107
|
+
* @since 1.0.0
|
|
99
108
|
*/
|
|
100
109
|
declare function removeUndefinedNull(obj: undefined): undefined;
|
|
101
110
|
|
|
@@ -110,6 +119,7 @@ declare function removeUndefinedNull(obj: undefined): undefined;
|
|
|
110
119
|
* @param path - The dot-notated path (e.g., 'a.b.c')
|
|
111
120
|
* @param value - The value to set
|
|
112
121
|
* @returns The modified object
|
|
122
|
+
* @since 1.9.0
|
|
113
123
|
*/
|
|
114
124
|
declare function set(obj: Record<string, any>, path: string, value: any): Record<string, any>;
|
|
115
125
|
|
package/lib/index.js
CHANGED
|
@@ -9,6 +9,7 @@ import { isNullish } from "radashi";
|
|
|
9
9
|
* Creates a deep copy of an object or array
|
|
10
10
|
* @param obj - The object to clone
|
|
11
11
|
* @returns Deep cloned object
|
|
12
|
+
* @since 1.9.0
|
|
12
13
|
*/
|
|
13
14
|
function deepClone(obj) {
|
|
14
15
|
if (obj === null || typeof obj !== "object") return obj;
|
|
@@ -32,6 +33,7 @@ function deepClone(obj) {
|
|
|
32
33
|
* @param arrA - First array to compare
|
|
33
34
|
* @param arrB - Second array to compare
|
|
34
35
|
* @returns `true` if arrays are identical according to JSON.stringify, `false` otherwise
|
|
36
|
+
* @since 2.0.0
|
|
35
37
|
*/
|
|
36
38
|
function quickCompare$1(arrA, arrB) {
|
|
37
39
|
try {
|
|
@@ -49,6 +51,7 @@ function quickCompare$1(arrA, arrB) {
|
|
|
49
51
|
* @param dateB - Second date to compare
|
|
50
52
|
* @param options - Comparison options
|
|
51
53
|
* @returns `true` if dates are identical according to the specified precision, `false` otherwise
|
|
54
|
+
* @since 2.0.0
|
|
52
55
|
*/
|
|
53
56
|
function compare(dateA, dateB, options = {}) {
|
|
54
57
|
const { precision = "milliseconds" } = options;
|
|
@@ -75,6 +78,7 @@ function compare(dateA, dateB, options = {}) {
|
|
|
75
78
|
*
|
|
76
79
|
* @param value - The value to check
|
|
77
80
|
* @returns `true` if the value is a special object, `false` otherwise
|
|
81
|
+
* @since 2.0.0
|
|
78
82
|
*/
|
|
79
83
|
function isSpecialObject(value) {
|
|
80
84
|
if (value === null || value === void 0) return false;
|
|
@@ -113,6 +117,7 @@ function isSpecialObject(value) {
|
|
|
113
117
|
* @param objA - First object to compare (can be object, undefined, or null)
|
|
114
118
|
* @param objB - Second object to compare (can be object, undefined, or null)
|
|
115
119
|
* @returns `true` if objects are identical, `false` if incompatible types, or a `DeepCompareResult` object detailing differences
|
|
120
|
+
* @since 2.0.0
|
|
116
121
|
*/
|
|
117
122
|
function deepCompare(objA, objB) {
|
|
118
123
|
if (objA === objB) return true;
|
|
@@ -157,6 +162,7 @@ function deepCompare(objA, objB) {
|
|
|
157
162
|
* @param target - The target object
|
|
158
163
|
* @param sources - The source objects to merge
|
|
159
164
|
* @returns The merged object
|
|
165
|
+
* @since 1.9.0
|
|
160
166
|
*/
|
|
161
167
|
function deepMerge(target, ...sources) {
|
|
162
168
|
if (!sources.length) return target;
|
|
@@ -186,6 +192,7 @@ function isObject(item) {
|
|
|
186
192
|
* @param path - The dot-notated path (e.g., 'a.b.c')
|
|
187
193
|
* @param defaultValue - Default value if path doesn't exist
|
|
188
194
|
* @returns The value at the path or default value
|
|
195
|
+
* @since 1.9.0
|
|
189
196
|
*/
|
|
190
197
|
function get(obj, path, defaultValue) {
|
|
191
198
|
const keys = path.split(".");
|
|
@@ -210,6 +217,7 @@ function get(obj, path, defaultValue) {
|
|
|
210
217
|
* @param objA - First object to compare
|
|
211
218
|
* @param objB - Second object to compare
|
|
212
219
|
* @returns `true` if objects are identical according to JSON.stringify, `false` otherwise
|
|
220
|
+
* @since 2.0.0
|
|
213
221
|
*/
|
|
214
222
|
function quickCompare(objA, objB) {
|
|
215
223
|
if (objA === objB) return true;
|
|
@@ -232,6 +240,7 @@ function quickCompare(objA, objB) {
|
|
|
232
240
|
*
|
|
233
241
|
* @param obj an object
|
|
234
242
|
* @returns A shallow copy of the object without null or undefined values
|
|
243
|
+
* @since 1.0.0
|
|
235
244
|
*/
|
|
236
245
|
function removeUndefinedNull(obj) {
|
|
237
246
|
return obj ? Object.entries(obj).filter(([_, v]) => !isNullish(v)).reduce((acc, [k, v]) => ({
|
|
@@ -252,6 +261,7 @@ function removeUndefinedNull(obj) {
|
|
|
252
261
|
* @param path - The dot-notated path (e.g., 'a.b.c')
|
|
253
262
|
* @param value - The value to set
|
|
254
263
|
* @returns The modified object
|
|
264
|
+
* @since 1.9.0
|
|
255
265
|
*/
|
|
256
266
|
function set(obj, path, value) {
|
|
257
267
|
const keys = path.split(".");
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../helpers/object/deepClone.ts","../../../helpers/array/quickCompare.ts","../../../helpers/date/compare.ts","../../../helpers/type/isSpecialObject.ts","../../../helpers/object/deepCompare.ts","../../../helpers/object/deepMerge.ts","../../../helpers/object/get.ts","../../../helpers/object/quickCompare.ts","../../../helpers/object/removeUndefinedNull.ts","../../../helpers/object/set.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 * Creates a deep copy of an object or array\n * @param obj - The object to clone\n * @returns Deep cloned object\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 (obj.hasOwnProperty(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 */\nexport function quickCompare<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\n/**\n * Options for date comparison\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 */\n precision?: 'milliseconds' | 'seconds' | 'minutes' | 'hours' | 'days';\n}\n\n/**\n * Comparison of two dates.\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 */\nexport function compare(dateA: Date, dateB: Date, options: DateCompareOptions = {}): boolean {\n const { precision = 'milliseconds' } = options;\n\n if (!(dateA instanceof Date) || !(dateB instanceof Date)) {\n return dateA === dateB;\n }\n\n // Handle invalid dates\n if (isNaN(dateA.getTime()) || isNaN(dateB.getTime())) {\n return isNaN(dateA.getTime()) && isNaN(dateB.getTime());\n }\n\n switch (precision) {\n case 'days':\n return dateA.toDateString() === dateB.toDateString();\n\n case 'hours':\n const hoursA = Math.floor(dateA.getTime() / (1000 * 60 * 60));\n const hoursB = Math.floor(dateB.getTime() / (1000 * 60 * 60));\n return hoursA === hoursB;\n\n case 'minutes':\n const minutesA = Math.floor(dateA.getTime() / (1000 * 60));\n const minutesB = Math.floor(dateB.getTime() / (1000 * 60));\n return minutesA === minutesB;\n\n case 'seconds':\n const secondsA = Math.floor(dateA.getTime() / 1000);\n const secondsB = Math.floor(dateB.getTime() / 1000);\n return secondsA === secondsB;\n\n case 'milliseconds':\n default:\n return dateA.getTime() === dateB.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 */\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 { quickCompare as quickCompareArray } from '../array/quickCompare';\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 */\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 */\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 quickCompare\n if (Array.isArray(objA) && Array.isArray(objB)) {\n return quickCompareArray(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 any)[key];\n const valueB = (objB as any)[key];\n\n // For arrays, use quickCompare\n if (Array.isArray(valueA) && Array.isArray(valueB)) {\n if (!quickCompareArray(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 * 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 */\nexport function deepMerge<T extends Record<string, any>>(target: T, ...sources: Record<string, any>[]): T {\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 const targetValue = target[key];\n const sourceValue = source[key];\n\n if (isObject(targetValue) && isObject(sourceValue)) {\n (target as any)[key] = deepMerge(targetValue, sourceValue);\n } else if (sourceValue !== undefined) {\n (target as any)[key] = sourceValue;\n }\n }\n\n return deepMerge(target, ...sources);\n}\n\nfunction isObject(item: any): item is object {\n return item && typeof item === 'object' && !Array.isArray(item);\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 */\nexport function get<T = any>(obj: any, path: string, defaultValue?: T): T | undefined {\n const keys = path.split('.');\n let result = obj;\n\n for (const key of keys) {\n if (result == null || typeof result !== 'object') {\n return defaultValue;\n }\n result = result[key];\n }\n\n return result !== undefined ? result : 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 * 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 */\nexport function quickCompare(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","/**\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 \"radashi\";\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 */\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 */\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 */\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 */\nexport function removeUndefinedNull<T extends Record<string, string | number | boolean | null | undefined>>(obj: T | null | undefined): Partial<T> | null | undefined {\n return obj ? Object.entries(obj)\n .filter(([_, v]) => !isNullish(v))\n .reduce((acc, [k, v]) => ({ ...acc, [k]: v }), {} as Partial<T>) : obj;\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 * 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 */\nexport function set(obj: Record<string, any>, path: string, value: any): Record<string, any> {\n const keys = path.split('.');\n let current = 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];\n }\n\n current[keys[keys.length - 1]] = value;\n return obj;\n}\n"],"mappings":";;;;;;;;;;;;AAWA,SAAgB,UAAa,KAAW;AACtC,KAAI,QAAQ,QAAQ,OAAO,QAAQ,SACjC,QAAO;AAGT,KAAI,eAAe,KACjB,QAAO,IAAI,KAAK,IAAI,SAAS,CAAC;AAGhC,KAAI,MAAM,QAAQ,IAAI,CACpB,QAAO,IAAI,KAAI,SAAQ,UAAU,KAAK,CAAC;CAGzC,MAAM,SAAS,EAAE;AACjB,MAAK,MAAM,OAAO,IAChB,KAAI,IAAI,eAAe,IAAI,CACzB,QAAO,OAAO,UAAU,IAAI,KAAK;AAIrC,QAAO;;;;;;;;;;;;;;;;;ACjBT,SAAgB,eAAgB,MAAW,MAAoB;AAC7D,KAAI;AACF,SAAO,KAAK,UAAU,KAAK,KAAK,KAAK,UAAU,KAAK;SAC9C;AAEN,SAAO,SAAS;;;;;;;;;;;;;ACUpB,SAAgB,QAAQ,OAAa,OAAa,UAA8B,EAAE,EAAW;CAC3F,MAAM,EAAE,YAAY,mBAAmB;AAEvC,KAAI,EAAE,iBAAiB,SAAS,EAAE,iBAAiB,MACjD,QAAO,UAAU;AAInB,KAAI,MAAM,MAAM,SAAS,CAAC,IAAI,MAAM,MAAM,SAAS,CAAC,CAClD,QAAO,MAAM,MAAM,SAAS,CAAC,IAAI,MAAM,MAAM,SAAS,CAAC;AAGzD,SAAQ,WAAR;EACE,KAAK,OACH,QAAO,MAAM,cAAc,KAAK,MAAM,cAAc;EAEtD,KAAK,QAGH,QAFe,KAAK,MAAM,MAAM,SAAS,IAAI,MAAO,KAAK,IAAI,KAC9C,KAAK,MAAM,MAAM,SAAS,IAAI,MAAO,KAAK,IAAI;EAG/D,KAA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xC,MAAM,MAAM,KAAK;AAEjB,MAAI,EAAE,OAAO,YAAY,OAAO,QAAQ,SAAS,YAAY,QAAQ,SAAS,KAC5E,SAAQ,OAAO,EAAE;AAGnB,YAAU,QAAQ;;AAGpB,SAAQ,KAAK,KAAK,SAAS,MAAM;AACjC,QAAO"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../helpers/object/deepClone.ts","../../../helpers/array/quickCompare.ts","../../../helpers/date/compare.ts","../../../helpers/type/isSpecialObject.ts","../../../helpers/object/deepCompare.ts","../../../helpers/object/deepMerge.ts","../../../helpers/object/get.ts","../../../helpers/object/quickCompare.ts","../../../helpers/object/removeUndefinedNull.ts","../../../helpers/object/set.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 * 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 (obj.hasOwnProperty(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 quickCompare<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\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 */\n precision?: 'milliseconds' | 'seconds' | 'minutes' | 'hours' | 'days';\n}\n\n/**\n * Comparison of two dates.\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 * @since 2.0.0\n */\nexport function compare(dateA: Date, dateB: Date, options: DateCompareOptions = {}): boolean {\n const { precision = 'milliseconds' } = options;\n\n if (!(dateA instanceof Date) || !(dateB instanceof Date)) {\n return dateA === dateB;\n }\n\n // Handle invalid dates\n if (isNaN(dateA.getTime()) || isNaN(dateB.getTime())) {\n return isNaN(dateA.getTime()) && isNaN(dateB.getTime());\n }\n\n switch (precision) {\n case 'days':\n return dateA.toDateString() === dateB.toDateString();\n\n case 'hours':\n const hoursA = Math.floor(dateA.getTime() / (1000 * 60 * 60));\n const hoursB = Math.floor(dateB.getTime() / (1000 * 60 * 60));\n return hoursA === hoursB;\n\n case 'minutes':\n const minutesA = Math.floor(dateA.getTime() / (1000 * 60));\n const minutesB = Math.floor(dateB.getTime() / (1000 * 60));\n return minutesA === minutesB;\n\n case 'seconds':\n const secondsA = Math.floor(dateA.getTime() / 1000);\n const secondsB = Math.floor(dateB.getTime() / 1000);\n return secondsA === secondsB;\n\n case 'milliseconds':\n default:\n return dateA.getTime() === dateB.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 { quickCompare as quickCompareArray } from '../array/quickCompare';\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 quickCompare\n if (Array.isArray(objA) && Array.isArray(objB)) {\n return quickCompareArray(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 any)[key];\n const valueB = (objB as any)[key];\n\n // For arrays, use quickCompare\n if (Array.isArray(valueA) && Array.isArray(valueB)) {\n if (!quickCompareArray(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 * 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, any>>(target: T, ...sources: Record<string, any>[]): T {\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 const targetValue = target[key];\n const sourceValue = source[key];\n\n if (isObject(targetValue) && isObject(sourceValue)) {\n (target as any)[key] = deepMerge(targetValue, sourceValue);\n } else if (sourceValue !== undefined) {\n (target as any)[key] = sourceValue;\n }\n }\n\n return deepMerge(target, ...sources);\n}\n\nfunction isObject(item: any): item is object {\n return item && typeof item === 'object' && !Array.isArray(item);\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 = any>(obj: any, path: string, defaultValue?: T): T | undefined {\n const keys = path.split('.');\n let result = obj;\n\n for (const key of keys) {\n if (result == null || typeof result !== 'object') {\n return defaultValue;\n }\n result = result[key];\n }\n\n return result !== undefined ? result : 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 * 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 quickCompare(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","/**\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 \"radashi\";\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 return obj ? Object.entries(obj)\n .filter(([_, v]) => !isNullish(v))\n .reduce((acc, [k, v]) => ({ ...acc, [k]: v }), {} as Partial<T>) : obj;\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 * 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, any>, path: string, value: any): Record<string, any> {\n const keys = path.split('.');\n let current = 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];\n }\n\n current[keys[keys.length - 1]] = value;\n return obj;\n}\n"],"mappings":";;;;;;;;;;;;;AAYA,SAAgB,UAAa,KAAW;AACtC,KAAI,QAAQ,QAAQ,OAAO,QAAQ,SACjC,QAAO;AAGT,KAAI,eAAe,KACjB,QAAO,IAAI,KAAK,IAAI,SAAS,CAAC;AAGhC,KAAI,MAAM,QAAQ,IAAI,CACpB,QAAO,IAAI,KAAI,SAAQ,UAAU,KAAK,CAAC;CAGzC,MAAM,SAAS,EAAE;AACjB,MAAK,MAAM,OAAO,IAChB,KAAI,IAAI,eAAe,IAAI,CACzB,QAAO,OAAO,UAAU,IAAI,KAAK;AAIrC,QAAO;;;;;;;;;;;;;;;;;;ACjBT,SAAgB,eAAgB,MAAW,MAAoB;AAC7D,KAAI;AACF,SAAO,KAAK,UAAU,KAAK,KAAK,KAAK,UAAU,KAAK;SAC9C;AAEN,SAAO,SAAS;;;;;;;;;;;;;;ACWpB,SAAgB,QAAQ,OAAa,OAAa,UAA8B,EAAE,EAAW;CAC3F,MAAM,EAAE,YAAY,mBAAmB;AAEvC,KAAI,EAAE,iBAAiB,SAAS,EAAE,iBAAiB,MACjD,QAAO,UAAU;AAInB,KAAI,MAAM,MAAM,SAAS,CAAC,IAAI,MAAM,MAAM,SAAS,CAAC,CAClD,QAAO,MAAM,MAAM,SAAS,CAAC,IAAI,MAAM,MAAM,SAAS,CAAC;AAGzD,SAAQ,WAAR;EACE,KAAK,OACH,QAAO,MAAM,cAAc,KAAK,MAAM,cAAc;EAEtD,KAAK,QAGH,QAFe,KAAK,MAAM,MAAM,SAAS,IAAI,MAAO,KAA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;CAC5B,IAAI,UAAU;AAEd,MAAK,IAAI,IAAI,GAAG,IAAI,KAAK,SAAS,GAAG,KAAK;EACxC,MAAM,MAAM,KAAK;AAEjB,MAAI,EAAE,OAAO,YAAY,OAAO,QAAQ,SAAS,YAAY,QAAQ,SAAS,KAC5E,SAAQ,OAAO,EAAE;AAGnB,YAAU,QAAQ;;AAGpB,SAAQ,KAAK,KAAK,SAAS,MAAM;AACjC,QAAO"}
|
package/meta/api.json
ADDED
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
{
|
|
2
|
+
"category": "object",
|
|
3
|
+
"version": "2.0.0-alpha.8",
|
|
4
|
+
"functions": [
|
|
5
|
+
{
|
|
6
|
+
"name": "deepClone",
|
|
7
|
+
"kind": "function",
|
|
8
|
+
"description": "Creates a deep copy of an object or array",
|
|
9
|
+
"since": "1.9.0",
|
|
10
|
+
"signatures": [
|
|
11
|
+
{
|
|
12
|
+
"signature": "deepClone<T>(obj: T): T",
|
|
13
|
+
"description": "Creates a deep copy of an object or array",
|
|
14
|
+
"params": [
|
|
15
|
+
{
|
|
16
|
+
"name": "obj",
|
|
17
|
+
"type": "T",
|
|
18
|
+
"description": "The object to clone"
|
|
19
|
+
}
|
|
20
|
+
],
|
|
21
|
+
"returns": {
|
|
22
|
+
"type": "T",
|
|
23
|
+
"description": "Deep cloned object"
|
|
24
|
+
},
|
|
25
|
+
"typeParameters": [
|
|
26
|
+
{
|
|
27
|
+
"name": "T"
|
|
28
|
+
}
|
|
29
|
+
]
|
|
30
|
+
}
|
|
31
|
+
],
|
|
32
|
+
"examples": [
|
|
33
|
+
{
|
|
34
|
+
"title": "Clone a nested object",
|
|
35
|
+
"description": "Creates a deep copy — modifying the clone does not affect the original.",
|
|
36
|
+
"code": "const original = { a: { b: 1 } };\nconst cloned = deepClone(original);\ncloned.a.b = 2;\n// original.a.b is still 1"
|
|
37
|
+
}
|
|
38
|
+
],
|
|
39
|
+
"sourceFile": "deepClone.ts"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"name": "deepCompare",
|
|
43
|
+
"kind": "function",
|
|
44
|
+
"description": "Deep comparison of two objects that returns detailed information about differences.",
|
|
45
|
+
"since": "2.0.0",
|
|
46
|
+
"signatures": [
|
|
47
|
+
{
|
|
48
|
+
"signature": "deepCompare(objA: object | null | undefined, objB: object | null | undefined): boolean | DeepCompareResult",
|
|
49
|
+
"description": "Deep comparison of two objects that returns detailed information about differences.",
|
|
50
|
+
"params": [
|
|
51
|
+
{
|
|
52
|
+
"name": "objA",
|
|
53
|
+
"type": "object | null | undefined",
|
|
54
|
+
"description": "First object to compare (can be object, undefined, or null)"
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"name": "objB",
|
|
58
|
+
"type": "object | null | undefined",
|
|
59
|
+
"description": "Second object to compare (can be object, undefined, or null)"
|
|
60
|
+
}
|
|
61
|
+
],
|
|
62
|
+
"returns": {
|
|
63
|
+
"type": "boolean | DeepCompareResult",
|
|
64
|
+
"description": "`true` if objects are identical, `false` if incompatible types, or a `DeepCompareResult` object detailing differences"
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
],
|
|
68
|
+
"examples": [
|
|
69
|
+
{
|
|
70
|
+
"title": "Compare nested objects",
|
|
71
|
+
"description": "Deeply compares two objects, returning true when they are structurally equal.",
|
|
72
|
+
"code": "deepCompare({ a: { b: 1 } }, { a: { b: 1 } })\n// => true"
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
"title": "Detect deep differences",
|
|
76
|
+
"description": "Returns a detailed diff object when nested values differ.",
|
|
77
|
+
"code": "deepCompare({ a: { b: 1 } }, { a: { b: 2 } })\n// => { a: { b: false } }"
|
|
78
|
+
}
|
|
79
|
+
],
|
|
80
|
+
"sourceFile": "deepCompare.ts"
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
"name": "DeepCompareResult",
|
|
84
|
+
"kind": "interface",
|
|
85
|
+
"description": "Result type for deep comparison when objects are not identical",
|
|
86
|
+
"since": "2.0.0",
|
|
87
|
+
"signatures": [],
|
|
88
|
+
"examples": [],
|
|
89
|
+
"sourceFile": "deepCompare.ts"
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
"name": "deepMerge",
|
|
93
|
+
"kind": "function",
|
|
94
|
+
"description": "Merges two or more objects deeply",
|
|
95
|
+
"since": "1.9.0",
|
|
96
|
+
"signatures": [
|
|
97
|
+
{
|
|
98
|
+
"signature": "deepMerge<T extends Record<string, any>>(target: T, sources: Record<string, any>[]): T",
|
|
99
|
+
"description": "Merges two or more objects deeply",
|
|
100
|
+
"params": [
|
|
101
|
+
{
|
|
102
|
+
"name": "target",
|
|
103
|
+
"type": "T",
|
|
104
|
+
"description": "The target object"
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
"name": "sources",
|
|
108
|
+
"type": "Record<string, any>[]",
|
|
109
|
+
"description": "The source objects to merge"
|
|
110
|
+
}
|
|
111
|
+
],
|
|
112
|
+
"returns": {
|
|
113
|
+
"type": "T",
|
|
114
|
+
"description": "The merged object"
|
|
115
|
+
},
|
|
116
|
+
"typeParameters": [
|
|
117
|
+
{
|
|
118
|
+
"name": "T",
|
|
119
|
+
"constraint": "Record<string, any>"
|
|
120
|
+
}
|
|
121
|
+
]
|
|
122
|
+
}
|
|
123
|
+
],
|
|
124
|
+
"examples": [
|
|
125
|
+
{
|
|
126
|
+
"title": "Merge two objects deeply",
|
|
127
|
+
"description": "Recursively merges source properties into the target object.",
|
|
128
|
+
"code": "deepMerge({ a: 1, b: { c: 2 } }, { b: { d: 3 }, e: 4 })\n// => { a: 1, b: { c: 2, d: 3 }, e: 4 }"
|
|
129
|
+
}
|
|
130
|
+
],
|
|
131
|
+
"sourceFile": "deepMerge.ts"
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
"name": "get",
|
|
135
|
+
"kind": "function",
|
|
136
|
+
"description": "Gets a value from an object using a dot-notated path",
|
|
137
|
+
"since": "1.9.0",
|
|
138
|
+
"signatures": [
|
|
139
|
+
{
|
|
140
|
+
"signature": "get<T = any>(obj: any, path: string, defaultValue?: T): T | undefined",
|
|
141
|
+
"description": "Gets a value from an object using a dot-notated path",
|
|
142
|
+
"params": [
|
|
143
|
+
{
|
|
144
|
+
"name": "obj",
|
|
145
|
+
"type": "any",
|
|
146
|
+
"description": "The object to get value from"
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
"name": "path",
|
|
150
|
+
"type": "string",
|
|
151
|
+
"description": "The dot-notated path (e.g., 'a.b.c')"
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
"name": "defaultValue",
|
|
155
|
+
"type": "T",
|
|
156
|
+
"description": "Default value if path doesn't exist",
|
|
157
|
+
"optional": true
|
|
158
|
+
}
|
|
159
|
+
],
|
|
160
|
+
"returns": {
|
|
161
|
+
"type": "T | undefined",
|
|
162
|
+
"description": "The value at the path or default value"
|
|
163
|
+
},
|
|
164
|
+
"typeParameters": [
|
|
165
|
+
{
|
|
166
|
+
"name": "T",
|
|
167
|
+
"default": "any"
|
|
168
|
+
}
|
|
169
|
+
]
|
|
170
|
+
}
|
|
171
|
+
],
|
|
172
|
+
"examples": [
|
|
173
|
+
{
|
|
174
|
+
"title": "Access a nested property",
|
|
175
|
+
"description": "Uses a dot-notated path to retrieve a deeply nested value.",
|
|
176
|
+
"code": "get({ a: { b: { c: 42 } } }, 'a.b.c')\n// => 42"
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
"title": "Return default for missing path",
|
|
180
|
+
"description": "Returns the default value when the path does not exist.",
|
|
181
|
+
"code": "get({ a: 1 }, 'b.c', 'default')\n// => 'default'"
|
|
182
|
+
}
|
|
183
|
+
],
|
|
184
|
+
"sourceFile": "get.ts"
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
"name": "quickCompare",
|
|
188
|
+
"kind": "function",
|
|
189
|
+
"description": "Quick comparison of two objects using JSON.stringify.\nThis is a fast but simple comparison that may not work for all edge cases.",
|
|
190
|
+
"since": "2.0.0",
|
|
191
|
+
"signatures": [
|
|
192
|
+
{
|
|
193
|
+
"signature": "quickCompare(objA: unknown, objB: unknown): boolean",
|
|
194
|
+
"description": "Quick comparison of two objects using JSON.stringify.\nThis is a fast but simple comparison that may not work for all edge cases.",
|
|
195
|
+
"params": [
|
|
196
|
+
{
|
|
197
|
+
"name": "objA",
|
|
198
|
+
"type": "unknown",
|
|
199
|
+
"description": "First object to compare"
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
"name": "objB",
|
|
203
|
+
"type": "unknown",
|
|
204
|
+
"description": "Second object to compare"
|
|
205
|
+
}
|
|
206
|
+
],
|
|
207
|
+
"returns": {
|
|
208
|
+
"type": "boolean",
|
|
209
|
+
"description": "`true` if objects are identical according to JSON.stringify, `false` otherwise"
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
],
|
|
213
|
+
"examples": [
|
|
214
|
+
{
|
|
215
|
+
"title": "Compare two equal objects",
|
|
216
|
+
"description": "Uses JSON.stringify for a fast comparison.",
|
|
217
|
+
"code": "quickCompare({ a: 1, b: 2 }, { a: 1, b: 2 })\n// => true"
|
|
218
|
+
}
|
|
219
|
+
],
|
|
220
|
+
"sourceFile": "quickCompare.ts"
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
"name": "removeUndefinedNull",
|
|
224
|
+
"kind": "function",
|
|
225
|
+
"description": "Remove null and undefined values from an object.",
|
|
226
|
+
"since": "1.0.0",
|
|
227
|
+
"signatures": [
|
|
228
|
+
{
|
|
229
|
+
"signature": "removeUndefinedNull<T extends Record<string, string | number | boolean | null | undefined>>(obj: T): Partial<T>",
|
|
230
|
+
"description": "Remove null and undefined values from an object.",
|
|
231
|
+
"params": [
|
|
232
|
+
{
|
|
233
|
+
"name": "obj",
|
|
234
|
+
"type": "T",
|
|
235
|
+
"description": "an object"
|
|
236
|
+
}
|
|
237
|
+
],
|
|
238
|
+
"returns": {
|
|
239
|
+
"type": "Partial<T>",
|
|
240
|
+
"description": "A shallow copy of the object without null or undefined values"
|
|
241
|
+
},
|
|
242
|
+
"typeParameters": [
|
|
243
|
+
{
|
|
244
|
+
"name": "T",
|
|
245
|
+
"constraint": "Record<string, string | number | boolean | null | undefined>"
|
|
246
|
+
}
|
|
247
|
+
]
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
"signature": "removeUndefinedNull(obj: null): null",
|
|
251
|
+
"description": "Remove null and undefined values from an object.",
|
|
252
|
+
"params": [
|
|
253
|
+
{
|
|
254
|
+
"name": "obj",
|
|
255
|
+
"type": "null",
|
|
256
|
+
"description": "a null object"
|
|
257
|
+
}
|
|
258
|
+
],
|
|
259
|
+
"returns": {
|
|
260
|
+
"type": "null",
|
|
261
|
+
"description": "null"
|
|
262
|
+
}
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
"signature": "removeUndefinedNull(obj: undefined): undefined",
|
|
266
|
+
"description": "Remove null and undefined values from an object.",
|
|
267
|
+
"params": [
|
|
268
|
+
{
|
|
269
|
+
"name": "obj",
|
|
270
|
+
"type": "undefined",
|
|
271
|
+
"description": "an undefined object"
|
|
272
|
+
}
|
|
273
|
+
],
|
|
274
|
+
"returns": {
|
|
275
|
+
"type": "undefined",
|
|
276
|
+
"description": "undefined"
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
],
|
|
280
|
+
"examples": [
|
|
281
|
+
{
|
|
282
|
+
"title": "Strip null and undefined values",
|
|
283
|
+
"description": "Returns a shallow copy of the object without null or undefined properties.",
|
|
284
|
+
"code": "removeUndefinedNull({ a: 1, b: null, c: undefined, d: 'ok' })\n// => { a: 1, d: 'ok' }"
|
|
285
|
+
}
|
|
286
|
+
],
|
|
287
|
+
"sourceFile": "removeUndefinedNull.ts"
|
|
288
|
+
},
|
|
289
|
+
{
|
|
290
|
+
"name": "set",
|
|
291
|
+
"kind": "function",
|
|
292
|
+
"description": "Sets a value in an object using a dot-notated path",
|
|
293
|
+
"since": "1.9.0",
|
|
294
|
+
"signatures": [
|
|
295
|
+
{
|
|
296
|
+
"signature": "set(obj: Record<string, any>, path: string, value: any): Record<string, any>",
|
|
297
|
+
"description": "Sets a value in an object using a dot-notated path",
|
|
298
|
+
"params": [
|
|
299
|
+
{
|
|
300
|
+
"name": "obj",
|
|
301
|
+
"type": "Record<string, any>",
|
|
302
|
+
"description": "The object to set value in"
|
|
303
|
+
},
|
|
304
|
+
{
|
|
305
|
+
"name": "path",
|
|
306
|
+
"type": "string",
|
|
307
|
+
"description": "The dot-notated path (e.g., 'a.b.c')"
|
|
308
|
+
},
|
|
309
|
+
{
|
|
310
|
+
"name": "value",
|
|
311
|
+
"type": "any",
|
|
312
|
+
"description": "The value to set"
|
|
313
|
+
}
|
|
314
|
+
],
|
|
315
|
+
"returns": {
|
|
316
|
+
"type": "Record<string, any>",
|
|
317
|
+
"description": "The modified object"
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
],
|
|
321
|
+
"examples": [
|
|
322
|
+
{
|
|
323
|
+
"title": "Set a nested property",
|
|
324
|
+
"description": "Creates intermediate objects as needed along the dot-notated path.",
|
|
325
|
+
"code": "set({}, 'a.b.c', 42)\n// => { a: { b: { c: 42 } } }"
|
|
326
|
+
}
|
|
327
|
+
],
|
|
328
|
+
"sourceFile": "set.ts"
|
|
329
|
+
}
|
|
330
|
+
]
|
|
331
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"category": "object",
|
|
3
|
-
"
|
|
3
|
+
"functions": [
|
|
4
4
|
{
|
|
5
|
-
"
|
|
5
|
+
"name": "deepClone",
|
|
6
6
|
"examples": [
|
|
7
7
|
{
|
|
8
8
|
"title": "Clone a nested object",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
]
|
|
13
13
|
},
|
|
14
14
|
{
|
|
15
|
-
"
|
|
15
|
+
"name": "deepCompare",
|
|
16
16
|
"examples": [
|
|
17
17
|
{
|
|
18
18
|
"title": "Compare nested objects",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
]
|
|
28
28
|
},
|
|
29
29
|
{
|
|
30
|
-
"
|
|
30
|
+
"name": "deepMerge",
|
|
31
31
|
"examples": [
|
|
32
32
|
{
|
|
33
33
|
"title": "Merge two objects deeply",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
]
|
|
38
38
|
},
|
|
39
39
|
{
|
|
40
|
-
"
|
|
40
|
+
"name": "get",
|
|
41
41
|
"examples": [
|
|
42
42
|
{
|
|
43
43
|
"title": "Access a nested property",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
]
|
|
53
53
|
},
|
|
54
54
|
{
|
|
55
|
-
"
|
|
55
|
+
"name": "quickCompare",
|
|
56
56
|
"examples": [
|
|
57
57
|
{
|
|
58
58
|
"title": "Compare two equal objects",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
]
|
|
63
63
|
},
|
|
64
64
|
{
|
|
65
|
-
"
|
|
65
|
+
"name": "removeUndefinedNull",
|
|
66
66
|
"examples": [
|
|
67
67
|
{
|
|
68
68
|
"title": "Strip null and undefined values",
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
]
|
|
73
73
|
},
|
|
74
74
|
{
|
|
75
|
-
"
|
|
75
|
+
"name": "set",
|
|
76
76
|
"examples": [
|
|
77
77
|
{
|
|
78
78
|
"title": "Set a nested property",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@helpers4/object",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.8",
|
|
4
4
|
"description": "A set of helpers in TS/JS, compatible with tree-shaking, for object.",
|
|
5
5
|
"author": "baxyz <baxy@etik.com>",
|
|
6
6
|
"license": "LGPL-3.0",
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
"types": "./lib/index.d.ts",
|
|
18
18
|
"import": "./lib/index.js"
|
|
19
19
|
},
|
|
20
|
-
"./
|
|
21
|
-
"./
|
|
22
|
-
"./licenses.json": "./licenses.json",
|
|
20
|
+
"./meta/api.json": "./meta/api.json",
|
|
21
|
+
"./meta/examples.json": "./meta/examples.json",
|
|
22
|
+
"./meta/licenses.json": "./meta/licenses.json",
|
|
23
23
|
"./package.json": "./package.json"
|
|
24
24
|
},
|
|
25
25
|
"keywords": [
|
|
@@ -37,9 +37,7 @@
|
|
|
37
37
|
"lib/index.js",
|
|
38
38
|
"lib/index.d.ts",
|
|
39
39
|
"lib/index.js.map",
|
|
40
|
-
"
|
|
41
|
-
"api.json",
|
|
42
|
-
"licenses.json",
|
|
40
|
+
"meta/",
|
|
43
41
|
"LICENSE.md",
|
|
44
42
|
"package.json",
|
|
45
43
|
"README.md"
|
|
@@ -50,4 +48,4 @@
|
|
|
50
48
|
"peerDependencies": {
|
|
51
49
|
"radashi": "^12.7.2"
|
|
52
50
|
}
|
|
53
|
-
}
|
|
51
|
+
}
|
package/api.json
DELETED
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"category": "object",
|
|
3
|
-
"members": [
|
|
4
|
-
{
|
|
5
|
-
"name": "deepClone",
|
|
6
|
-
"kind": "function",
|
|
7
|
-
"description": "Creates a deep copy of an object or array",
|
|
8
|
-
"signature": "deepClone<T>(obj: T): T",
|
|
9
|
-
"params": [
|
|
10
|
-
{
|
|
11
|
-
"name": "obj",
|
|
12
|
-
"type": "T",
|
|
13
|
-
"description": "The object to clone"
|
|
14
|
-
}
|
|
15
|
-
],
|
|
16
|
-
"returns": "T"
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
"name": "deepCompare",
|
|
20
|
-
"kind": "function",
|
|
21
|
-
"description": "Deep comparison of two objects that returns detailed information about differences.",
|
|
22
|
-
"signature": "deepCompare(objA: object | null | undefined, objB: object | null | undefined): boolean | DeepCompareResult",
|
|
23
|
-
"params": [
|
|
24
|
-
{
|
|
25
|
-
"name": "objA",
|
|
26
|
-
"type": "object | null | undefined",
|
|
27
|
-
"description": "First object to compare (can be object, undefined, or null)"
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
"name": "objB",
|
|
31
|
-
"type": "object | null | undefined",
|
|
32
|
-
"description": "Second object to compare (can be object, undefined, or null)"
|
|
33
|
-
}
|
|
34
|
-
],
|
|
35
|
-
"returns": "boolean | DeepCompareResult"
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
"name": "DeepCompareResult",
|
|
39
|
-
"kind": "interface",
|
|
40
|
-
"description": "Result type for deep comparison when objects are not identical"
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
"name": "deepMerge",
|
|
44
|
-
"kind": "function",
|
|
45
|
-
"description": "Merges two or more objects deeply",
|
|
46
|
-
"signature": "deepMerge<T>(target: T, sources: Record<string, any>[]): T",
|
|
47
|
-
"params": [
|
|
48
|
-
{
|
|
49
|
-
"name": "target",
|
|
50
|
-
"type": "T",
|
|
51
|
-
"description": "The target object"
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
"name": "sources",
|
|
55
|
-
"type": "Record<string, any>[]",
|
|
56
|
-
"description": "The source objects to merge"
|
|
57
|
-
}
|
|
58
|
-
],
|
|
59
|
-
"returns": "T"
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
"name": "get",
|
|
63
|
-
"kind": "function",
|
|
64
|
-
"description": "Gets a value from an object using a dot-notated path",
|
|
65
|
-
"signature": "get<T>(obj: any, path: string, defaultValue: T): T | undefined",
|
|
66
|
-
"params": [
|
|
67
|
-
{
|
|
68
|
-
"name": "obj",
|
|
69
|
-
"type": "any",
|
|
70
|
-
"description": "The object to get value from"
|
|
71
|
-
},
|
|
72
|
-
{
|
|
73
|
-
"name": "path",
|
|
74
|
-
"type": "string",
|
|
75
|
-
"description": "The dot-notated path (e.g., 'a.b.c')"
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
"name": "defaultValue",
|
|
79
|
-
"type": "T",
|
|
80
|
-
"description": "Default value if path doesn't exist"
|
|
81
|
-
}
|
|
82
|
-
],
|
|
83
|
-
"returns": "T | undefined"
|
|
84
|
-
},
|
|
85
|
-
{
|
|
86
|
-
"name": "quickCompare",
|
|
87
|
-
"kind": "function",
|
|
88
|
-
"description": "Quick comparison of two objects using JSON.stringify.\nThis is a fast but simple comparison that may not work for all edge cases.",
|
|
89
|
-
"signature": "quickCompare(objA: unknown, objB: unknown): boolean",
|
|
90
|
-
"params": [
|
|
91
|
-
{
|
|
92
|
-
"name": "objA",
|
|
93
|
-
"type": "unknown",
|
|
94
|
-
"description": "First object to compare"
|
|
95
|
-
},
|
|
96
|
-
{
|
|
97
|
-
"name": "objB",
|
|
98
|
-
"type": "unknown",
|
|
99
|
-
"description": "Second object to compare"
|
|
100
|
-
}
|
|
101
|
-
],
|
|
102
|
-
"returns": "boolean"
|
|
103
|
-
},
|
|
104
|
-
{
|
|
105
|
-
"name": "removeUndefinedNull",
|
|
106
|
-
"kind": "function",
|
|
107
|
-
"description": "Remove null and undefined values from an object.",
|
|
108
|
-
"signature": "removeUndefinedNull<T>(obj: T): Partial<T>",
|
|
109
|
-
"params": [
|
|
110
|
-
{
|
|
111
|
-
"name": "obj",
|
|
112
|
-
"type": "T",
|
|
113
|
-
"description": "an object"
|
|
114
|
-
}
|
|
115
|
-
],
|
|
116
|
-
"returns": "Partial<T>"
|
|
117
|
-
},
|
|
118
|
-
{
|
|
119
|
-
"name": "set",
|
|
120
|
-
"kind": "function",
|
|
121
|
-
"description": "Sets a value in an object using a dot-notated path",
|
|
122
|
-
"signature": "set(obj: Record<string, any>, path: string, value: any): Record<string, any>",
|
|
123
|
-
"params": [
|
|
124
|
-
{
|
|
125
|
-
"name": "obj",
|
|
126
|
-
"type": "Record<string, any>",
|
|
127
|
-
"description": "The object to set value in"
|
|
128
|
-
},
|
|
129
|
-
{
|
|
130
|
-
"name": "path",
|
|
131
|
-
"type": "string",
|
|
132
|
-
"description": "The dot-notated path (e.g., 'a.b.c')"
|
|
133
|
-
},
|
|
134
|
-
{
|
|
135
|
-
"name": "value",
|
|
136
|
-
"type": "any",
|
|
137
|
-
"description": "The value to set"
|
|
138
|
-
}
|
|
139
|
-
],
|
|
140
|
-
"returns": "Record<string, any>"
|
|
141
|
-
}
|
|
142
|
-
]
|
|
143
|
-
}
|
|
File without changes
|