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

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
@@ -9,22 +9,30 @@ A set of helpers for working with URLs.
9
9
 
10
10
  ## Documentation
11
11
 
12
- [https://helpers4.js.org/object](https://helpers4.js.org/object)
12
+ [https://helpers4.dev/typescript/categories/object/](https://helpers4.dev/typescript/categories/object/)
13
13
 
14
14
  <!-- AUTOMATIC-METHODS -->
15
- - get
16
- - set
15
+ - compact
16
+ - deepClone
17
+ - deepCompare
17
18
  - deepMerge
19
+ - get
20
+ - omit
21
+ - pick
18
22
  - removeUndefinedNull
19
- - deepClone
23
+ - safeJsonParse
24
+ - set
25
+ - shallowEquals
20
26
  <!-- /AUTOMATIC-METHODS -->
21
27
 
22
28
  ## See
23
29
 
24
30
  <!-- AUTOMATIC-SIBLINGS -->
25
31
  - [array](../array)
32
+ - [commit](../commit)
26
33
  - [date](../date)
27
34
  - [function](../function)
35
+ - [math](../math)
28
36
  - [number](../number)
29
37
  - [observable](../observable)
30
38
  - [promise](../promise)
@@ -40,14 +48,16 @@ A set of helpers for working with URLs.
40
48
  | Name | Package | Source Code | Description |
41
49
  |------|---------|-------------|-------------|
42
50
  | array | [@helpers4/array](https://www.npmjs.com/package/@helpers4/array) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/array) | Array manipulation utilities |
43
- | date | [@helpers4/date](https://www.npmjs.com/package/@helpers4/date) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/date) | date utilities |
51
+ | commit | [@helpers4/commit](https://www.npmjs.com/package/@helpers4/commit) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/commit) | Conventional Commits parsing and analysis |
52
+ | date | [@helpers4/date](https://www.npmjs.com/package/@helpers4/date) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/date) | Date and time utility functions |
44
53
  | 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 |
45
- | number | [@helpers4/number](https://www.npmjs.com/package/@helpers4/number) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/number) | number utilities |
54
+ | math | [@helpers4/math](https://www.npmjs.com/package/@helpers4/math) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/math) | Mathematical utility functions and calculations |
55
+ | number | [@helpers4/number](https://www.npmjs.com/package/@helpers4/number) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/number) | Number utility functions and validation |
46
56
  | object | [@helpers4/object](https://www.npmjs.com/package/@helpers4/object) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/object) | Object manipulation utilities |
47
57
  | observable | [@helpers4/observable](https://www.npmjs.com/package/@helpers4/observable) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/observable) | Observable utilities and combinators |
48
58
  | promise | [@helpers4/promise](https://www.npmjs.com/package/@helpers4/promise) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/promise) | Promise utilities and error handling |
49
59
  | string | [@helpers4/string](https://www.npmjs.com/package/@helpers4/string) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/string) | String manipulation and formatting utilities |
50
- | type | [@helpers4/type](https://www.npmjs.com/package/@helpers4/type) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/type) | type utilities |
60
+ | type | [@helpers4/type](https://www.npmjs.com/package/@helpers4/type) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/type) | Type checking and validation utilities |
51
61
  | url | [@helpers4/url](https://www.npmjs.com/package/@helpers4/url) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/url) | URL parsing and manipulation utilities |
52
62
  | version | [@helpers4/version](https://www.npmjs.com/package/@helpers4/version) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/version) | Version string manipulation utilities |
53
63
  <!-- /AUTOMATIC-CATEGORIES-TABLE -->
package/lib/index.d.ts CHANGED
@@ -1,5 +1,208 @@
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
+ * Removes all entries with falsy values (`false`, `null`, `undefined`, `0`, `""`, `NaN`) from an object.
8
+ * @param obj - The source object
9
+ * @returns A new object containing only entries with truthy values
10
+ * @example
11
+ * compact({ a: 1, b: null, c: '', d: 0, e: 'hello' })
12
+ * // => { a: 1, e: 'hello' }
13
+ * @since 2.0.0
14
+ */
15
+ declare function compact<T extends Record<string, unknown>>(obj: T): Partial<T>;
16
+ declare function compact(obj: undefined): undefined;
17
+ declare function compact(obj: null): null;
18
+
19
+ /**
20
+ * This file is part of helpers4.
21
+ * Copyright (C) 2025 baxyz
22
+ * SPDX-License-Identifier: LGPL-3.0-or-later
23
+ */
24
+ /**
25
+ * Creates a deep copy of an object or array
26
+ * @param obj - The object to clone
27
+ * @returns Deep cloned object
28
+ * @since 1.9.0
29
+ */
30
+ declare function deepClone<T>(obj: T): T;
31
+
32
+ /**
33
+ * This file is part of helpers4.
34
+ * Copyright (C) 2025 baxyz
35
+ * SPDX-License-Identifier: LGPL-3.0-or-later
36
+ */
37
+ /**
38
+ * Result type for deep comparison when objects are not identical
39
+ * @since 2.0.0
40
+ */
41
+ interface DeepCompareResult {
42
+ [key: string]: "onlyA" | "onlyB" | false | DeepCompareResult;
43
+ }
44
+ /**
45
+ * Deep comparison of two objects that returns detailed information about differences.
46
+ *
47
+ * @param objA - First object to compare (can be object, undefined, or null)
48
+ * @param objB - Second object to compare (can be object, undefined, or null)
49
+ * @returns `true` if objects are identical, `false` if incompatible types, or a `DeepCompareResult` object detailing differences
50
+ * @since 2.0.0
51
+ */
52
+ declare function deepCompare(objA: object | undefined | null, objB: object | undefined | null): true | false | DeepCompareResult;
53
+
54
+ /**
55
+ * This file is part of helpers4.
56
+ * Copyright (C) 2025 baxyz
57
+ * SPDX-License-Identifier: LGPL-3.0-or-later
58
+ */
59
+ /**
60
+ * Merges two or more objects deeply
61
+ * @param target - The target object
62
+ * @param sources - The source objects to merge
63
+ * @returns The merged object
64
+ * @since 1.9.0
65
+ */
66
+ declare function deepMerge<T extends Record<string, unknown>>(target: T, ...sources: Record<string, unknown>[]): T;
67
+ declare function deepMerge(target: undefined, ...sources: Record<string, unknown>[]): undefined;
68
+ declare function deepMerge(target: null, ...sources: Record<string, unknown>[]): null;
69
+
70
+ /**
71
+ * This file is part of helpers4.
72
+ * Copyright (C) 2025 baxyz
73
+ * SPDX-License-Identifier: LGPL-3.0-or-later
74
+ */
75
+ /**
76
+ * Gets a value from an object using a dot-notated path
77
+ * @param obj - The object to get value from
78
+ * @param path - The dot-notated path (e.g., 'a.b.c')
79
+ * @param defaultValue - Default value if path doesn't exist
80
+ * @returns The value at the path or default value
81
+ * @since 1.9.0
82
+ */
83
+ declare function get<T = unknown>(obj: unknown, path: string, defaultValue?: T): T | undefined;
84
+
85
+ /**
86
+ * This file is part of helpers4.
87
+ * Copyright (C) 2025 baxyz
88
+ * SPDX-License-Identifier: LGPL-3.0-or-later
89
+ */
90
+ /**
91
+ * Creates a new object without the specified keys.
92
+ * @param obj - The source object
93
+ * @param keys - The keys to omit
94
+ * @returns A new object without the omitted keys
95
+ * @example
96
+ * omit({ a: 1, b: 2, c: 3 }, ['b'])
97
+ * // => { a: 1, c: 3 }
98
+ * @since 2.0.0
99
+ */
100
+ declare function omit<T extends Record<string, unknown>, K extends keyof T>(obj: T, keys: readonly K[]): Omit<T, K>;
101
+ declare function omit(obj: undefined, keys: readonly string[]): undefined;
102
+ declare function omit(obj: null, keys: readonly string[]): null;
103
+
104
+ /**
105
+ * This file is part of helpers4.
106
+ * Copyright (C) 2025 baxyz
107
+ * SPDX-License-Identifier: LGPL-3.0-or-later
108
+ */
109
+ /**
110
+ * Creates a new object with only the specified keys.
111
+ * @param obj - The source object
112
+ * @param keys - The keys to pick
113
+ * @returns A new object with only the picked keys
114
+ * @example
115
+ * pick({ a: 1, b: 2, c: 3 }, ['a', 'c'])
116
+ * // => { a: 1, c: 3 }
117
+ * @since 2.0.0
118
+ */
119
+ declare function pick<T extends Record<string, unknown>, K extends keyof T>(obj: T, keys: readonly K[]): Pick<T, K>;
120
+ declare function pick(obj: undefined, keys: readonly string[]): undefined;
121
+ declare function pick(obj: null, keys: readonly string[]): null;
122
+
123
+ /**
124
+ * This file is part of helpers4.
125
+ * Copyright (C) 2025 baxyz
126
+ * SPDX-License-Identifier: LGPL-3.0-or-later
127
+ */
128
+ /**
129
+ * Remove null and undefined values from an object.
130
+ *
131
+ * @param obj an object
132
+ * @returns A shallow copy of the object without null or undefined values
133
+ * @since 1.0.0
134
+ */
135
+ declare function removeUndefinedNull<T extends Record<string, string | number | boolean | null | undefined>>(obj: T): Partial<T>;
136
+ /**
137
+ * Remove null and undefined values from an object.
138
+ *
139
+ * @param obj a null object
140
+ * @returns null
141
+ * @since 1.0.0
142
+ */
143
+ declare function removeUndefinedNull(obj: null): null;
144
+ /**
145
+ * Remove null and undefined values from an object.
146
+ *
147
+ * @param obj an undefined object
148
+ * @returns undefined
149
+ * @since 1.0.0
150
+ */
151
+ declare function removeUndefinedNull(obj: undefined): undefined;
152
+
153
+ /**
154
+ * This file is part of helpers4.
155
+ * Copyright (C) 2025 baxyz
156
+ * SPDX-License-Identifier: LGPL-3.0-or-later
157
+ */
158
+ /**
159
+ * Parses a JSON string, returning `null` (or a fallback) on any parse failure.
160
+ *
161
+ * Unlike `JSON.parse`, this never throws. Invalid JSON strings and other
162
+ * parsing edge-cases resolve to `null` or the provided `fallback`.
163
+ *
164
+ * @param input - The JSON string to parse.
165
+ * @param fallback - Value returned on failure. Defaults to `null` when omitted.
166
+ * @returns The parsed value typed as `T`, or `fallback` on failure.
167
+ * @example
168
+ * safeJsonParse<{ a: number }>('{"a":1}') // => { a: 1 }
169
+ * safeJsonParse('invalid') // => null
170
+ * safeJsonParse('invalid', []) // => []
171
+ * @since next
172
+ */
173
+ declare function safeJsonParse<T>(input: string): T | null;
174
+ declare function safeJsonParse<T>(input: string, fallback: T): T;
175
+
176
+ /**
177
+ * This file is part of helpers4.
178
+ * Copyright (C) 2025 baxyz
179
+ * SPDX-License-Identifier: LGPL-3.0-or-later
180
+ */
181
+ /**
182
+ * Sets a value in an object using a dot-notated path
183
+ * @param obj - The object to set value in
184
+ * @param path - The dot-notated path (e.g., 'a.b.c')
185
+ * @param value - The value to set
186
+ * @returns The modified object
187
+ * @since 1.9.0
188
+ */
189
+ declare function set(obj: Record<string, unknown>, path: string, value: unknown): Record<string, unknown>;
190
+
191
+ /**
192
+ * This file is part of helpers4.
193
+ * Copyright (C) 2025 baxyz
194
+ * SPDX-License-Identifier: LGPL-3.0-or-later
195
+ */
196
+ /**
197
+ * Quick comparison of two objects using JSON.stringify.
198
+ * This is a fast but simple comparison that may not work for all edge cases.
199
+ *
200
+ * @param objA - First object to compare
201
+ * @param objB - Second object to compare
202
+ * @returns `true` if objects are identical according to JSON.stringify, `false` otherwise
203
+ * @since 2.0.0
204
+ */
205
+ declare function shallowEquals(objA: unknown, objB: unknown): boolean;
206
+
207
+ export { compact, deepClone, deepCompare, deepMerge, get, omit, pick, removeUndefinedNull, safeJsonParse, set, shallowEquals };
208
+ export type { DeepCompareResult };