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

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/README.md CHANGED
@@ -12,11 +12,13 @@ A set of helpers for working with URLs.
12
12
  [https://helpers4.js.org/object](https://helpers4.js.org/object)
13
13
 
14
14
  <!-- AUTOMATIC-METHODS -->
15
- - get
16
- - set
15
+ - deepClone
16
+ - deepCompare
17
17
  - deepMerge
18
+ - get
19
+ - quickCompare
18
20
  - removeUndefinedNull
19
- - deepClone
21
+ - set
20
22
  <!-- /AUTOMATIC-METHODS -->
21
23
 
22
24
  ## See
@@ -25,6 +27,7 @@ A set of helpers for working with URLs.
25
27
  - [array](../array)
26
28
  - [date](../date)
27
29
  - [function](../function)
30
+ - [math](../math)
28
31
  - [number](../number)
29
32
  - [observable](../observable)
30
33
  - [promise](../promise)
@@ -42,6 +45,7 @@ A set of helpers for working with URLs.
42
45
  | array | [@helpers4/array](https://www.npmjs.com/package/@helpers4/array) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/array) | Array manipulation utilities |
43
46
  | date | [@helpers4/date](https://www.npmjs.com/package/@helpers4/date) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/date) | date utilities |
44
47
  | function | [@helpers4/function](https://www.npmjs.com/package/@helpers4/function) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/function) | Function utilities and type guards |
48
+ | math | [@helpers4/math](https://www.npmjs.com/package/@helpers4/math) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/math) | math utilities |
45
49
  | number | [@helpers4/number](https://www.npmjs.com/package/@helpers4/number) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/number) | number utilities |
46
50
  | object | [@helpers4/object](https://www.npmjs.com/package/@helpers4/object) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/object) | Object manipulation utilities |
47
51
  | observable | [@helpers4/observable](https://www.npmjs.com/package/@helpers4/observable) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/observable) | Observable utilities and combinators |
package/api.json ADDED
@@ -0,0 +1,143 @@
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
+ }
package/examples.json ADDED
@@ -0,0 +1,85 @@
1
+ {
2
+ "category": "object",
3
+ "helpers": [
4
+ {
5
+ "helper": "deepClone",
6
+ "examples": [
7
+ {
8
+ "title": "Clone a nested object",
9
+ "description": "Creates a deep copy — modifying the clone does not affect the original.",
10
+ "code": "const original = { a: { b: 1 } };\nconst cloned = deepClone(original);\ncloned.a.b = 2;\n// original.a.b is still 1"
11
+ }
12
+ ]
13
+ },
14
+ {
15
+ "helper": "deepCompare",
16
+ "examples": [
17
+ {
18
+ "title": "Compare nested objects",
19
+ "description": "Deeply compares two objects, returning true when they are structurally equal.",
20
+ "code": "deepCompare({ a: { b: 1 } }, { a: { b: 1 } })\n// => true"
21
+ },
22
+ {
23
+ "title": "Detect deep differences",
24
+ "description": "Returns a detailed diff object when nested values differ.",
25
+ "code": "deepCompare({ a: { b: 1 } }, { a: { b: 2 } })\n// => { a: { b: false } }"
26
+ }
27
+ ]
28
+ },
29
+ {
30
+ "helper": "deepMerge",
31
+ "examples": [
32
+ {
33
+ "title": "Merge two objects deeply",
34
+ "description": "Recursively merges source properties into the target object.",
35
+ "code": "deepMerge({ a: 1, b: { c: 2 } }, { b: { d: 3 }, e: 4 })\n// => { a: 1, b: { c: 2, d: 3 }, e: 4 }"
36
+ }
37
+ ]
38
+ },
39
+ {
40
+ "helper": "get",
41
+ "examples": [
42
+ {
43
+ "title": "Access a nested property",
44
+ "description": "Uses a dot-notated path to retrieve a deeply nested value.",
45
+ "code": "get({ a: { b: { c: 42 } } }, 'a.b.c')\n// => 42"
46
+ },
47
+ {
48
+ "title": "Return default for missing path",
49
+ "description": "Returns the default value when the path does not exist.",
50
+ "code": "get({ a: 1 }, 'b.c', 'default')\n// => 'default'"
51
+ }
52
+ ]
53
+ },
54
+ {
55
+ "helper": "quickCompare",
56
+ "examples": [
57
+ {
58
+ "title": "Compare two equal objects",
59
+ "description": "Uses JSON.stringify for a fast comparison.",
60
+ "code": "quickCompare({ a: 1, b: 2 }, { a: 1, b: 2 })\n// => true"
61
+ }
62
+ ]
63
+ },
64
+ {
65
+ "helper": "removeUndefinedNull",
66
+ "examples": [
67
+ {
68
+ "title": "Strip null and undefined values",
69
+ "description": "Returns a shallow copy of the object without null or undefined properties.",
70
+ "code": "removeUndefinedNull({ a: 1, b: null, c: undefined, d: 'ok' })\n// => { a: 1, d: 'ok' }"
71
+ }
72
+ ]
73
+ },
74
+ {
75
+ "helper": "set",
76
+ "examples": [
77
+ {
78
+ "title": "Set a nested property",
79
+ "description": "Creates intermediate objects as needed along the dot-notated path.",
80
+ "code": "set({}, 'a.b.c', 42)\n// => { a: { b: { c: 42 } } }"
81
+ }
82
+ ]
83
+ }
84
+ ]
85
+ }
package/lib/index.d.ts CHANGED
@@ -1,5 +1,117 @@
1
- export declare function get<T = any>(obj: any, path: string, defaultValue?: T): T | undefined;
2
- export declare function set(obj: Record<string, any>, path: string, value: any): Record<string, any>;
3
- export declare function deepMerge<T extends Record<string, any>>(target: T, ...sources: Record<string, any>[]): T;
4
- export declare function removeUndefinedNull<T extends Record<string, string | boolean | number>>(obj: T): T; /** * Remove null and undefined values from an object. * * @param obj a null object * @returns null */ export function removeUndefinedNull<T extends Record<string, string | boolean | number>>(obj: null): null; /** * Remove null and undefined values from an object. * * @param obj an undefined object * @returns undefined */ export function removeUndefinedNull<T extends Record<string, string | boolean | number>>(obj: undefined): undefined; /** * Remove null and undefined values from an object. * * @param obj an object * @returns A shallow copy of the object without null or undefined values */ export function removeUndefinedNull<T extends Record<string, string | boolean | number>>(obj: T | null | undefined): T | null | undefined;
5
- export declare function deepClone<T>(obj: T): T;
1
+ /**
2
+ * This file is part of helpers4.
3
+ * Copyright (C) 2025 baxyz
4
+ * SPDX-License-Identifier: LGPL-3.0-or-later
5
+ */
6
+ /**
7
+ * Creates a deep copy of an object or array
8
+ * @param obj - The object to clone
9
+ * @returns Deep cloned object
10
+ */
11
+ declare function deepClone<T>(obj: T): T;
12
+
13
+ /**
14
+ * This file is part of helpers4.
15
+ * Copyright (C) 2025 baxyz
16
+ * SPDX-License-Identifier: LGPL-3.0-or-later
17
+ */
18
+ /**
19
+ * Result type for deep comparison when objects are not identical
20
+ */
21
+ interface DeepCompareResult {
22
+ [key: string]: "onlyA" | "onlyB" | false | DeepCompareResult;
23
+ }
24
+ /**
25
+ * Deep comparison of two objects that returns detailed information about differences.
26
+ *
27
+ * @param objA - First object to compare (can be object, undefined, or null)
28
+ * @param objB - Second object to compare (can be object, undefined, or null)
29
+ * @returns `true` if objects are identical, `false` if incompatible types, or a `DeepCompareResult` object detailing differences
30
+ */
31
+ declare function deepCompare(objA: object | undefined | null, objB: object | undefined | null): true | false | DeepCompareResult;
32
+
33
+ /**
34
+ * This file is part of helpers4.
35
+ * Copyright (C) 2025 baxyz
36
+ * SPDX-License-Identifier: LGPL-3.0-or-later
37
+ */
38
+ /**
39
+ * Merges two or more objects deeply
40
+ * @param target - The target object
41
+ * @param sources - The source objects to merge
42
+ * @returns The merged object
43
+ */
44
+ declare function deepMerge<T extends Record<string, any>>(target: T, ...sources: Record<string, any>[]): T;
45
+
46
+ /**
47
+ * This file is part of helpers4.
48
+ * Copyright (C) 2025 baxyz
49
+ * SPDX-License-Identifier: LGPL-3.0-or-later
50
+ */
51
+ /**
52
+ * Gets a value from an object using a dot-notated path
53
+ * @param obj - The object to get value from
54
+ * @param path - The dot-notated path (e.g., 'a.b.c')
55
+ * @param defaultValue - Default value if path doesn't exist
56
+ * @returns The value at the path or default value
57
+ */
58
+ declare function get<T = any>(obj: any, path: string, defaultValue?: T): T | undefined;
59
+
60
+ /**
61
+ * This file is part of helpers4.
62
+ * Copyright (C) 2025 baxyz
63
+ * SPDX-License-Identifier: LGPL-3.0-or-later
64
+ */
65
+ /**
66
+ * Quick comparison of two objects using JSON.stringify.
67
+ * This is a fast but simple comparison that may not work for all edge cases.
68
+ *
69
+ * @param objA - First object to compare
70
+ * @param objB - Second object to compare
71
+ * @returns `true` if objects are identical according to JSON.stringify, `false` otherwise
72
+ */
73
+ declare function quickCompare(objA: unknown, objB: unknown): boolean;
74
+
75
+ /**
76
+ * This file is part of helpers4.
77
+ * Copyright (C) 2025 baxyz
78
+ * SPDX-License-Identifier: LGPL-3.0-or-later
79
+ */
80
+ /**
81
+ * Remove null and undefined values from an object.
82
+ *
83
+ * @param obj an object
84
+ * @returns A shallow copy of the object without null or undefined values
85
+ */
86
+ declare function removeUndefinedNull<T extends Record<string, string | number | boolean | null | undefined>>(obj: T): Partial<T>;
87
+ /**
88
+ * Remove null and undefined values from an object.
89
+ *
90
+ * @param obj a null object
91
+ * @returns null
92
+ */
93
+ declare function removeUndefinedNull(obj: null): null;
94
+ /**
95
+ * Remove null and undefined values from an object.
96
+ *
97
+ * @param obj an undefined object
98
+ * @returns undefined
99
+ */
100
+ declare function removeUndefinedNull(obj: undefined): undefined;
101
+
102
+ /**
103
+ * This file is part of helpers4.
104
+ * Copyright (C) 2025 baxyz
105
+ * SPDX-License-Identifier: LGPL-3.0-or-later
106
+ */
107
+ /**
108
+ * Sets a value in an object using a dot-notated path
109
+ * @param obj - The object to set value in
110
+ * @param path - The dot-notated path (e.g., 'a.b.c')
111
+ * @param value - The value to set
112
+ * @returns The modified object
113
+ */
114
+ declare function set(obj: Record<string, any>, path: string, value: any): Record<string, any>;
115
+
116
+ export { deepClone, deepCompare, deepMerge, get, quickCompare, removeUndefinedNull, set };
117
+ export type { DeepCompareResult };