Overview
TheObjectUtils class provides static methods for object manipulation, including deep cloning, merging, property access, filtering, and transformation operations.
Source: workspace/source/src/utils/helpers/ObjectUtils.ts:5
Methods
isEmpty
Check if value is empty (null, undefined, empty string, empty array, empty object).value: unknown- Value to check
boolean - True if value is empty
Example:
isNotEmpty
Check if value is NOT empty.value: unknown- Value to check
boolean - True if value is not empty
Example:
deepClone
Create a deep copy of an object.obj: T- Object to clone
T - Deep cloned copy
Example:
merge
Shallow merge objects (right overwrites left)....objects: Partial<T>[]- Objects to merge
T - Merged object
Example:
deepMerge
Deep merge objects recursively....objects: Array<Record<string, unknown>>- Objects to merge deeply
Record<string, unknown> - Deeply merged object
Example:
pick
Pick specific keys from object.obj: T- Source objectkeys: K[]- Keys to pick
Partial<T> - Object with only picked keys
Example:
omit
Omit specific keys from object.obj: T- Source objectkeys: K[]- Keys to omit
Partial<T> - Object without omitted keys
Example:
get
Get nested value using dot notation.obj: Record<string, unknown>- Source objectpath: string- Dot-notation path (e.g., ‘user.address.city’)defaultValue?: T- Default value if path doesn’t exist
T - Value at path or default value
Example:
set
Set nested value using dot notation.obj: Record<string, unknown>- Target objectpath: string- Dot-notation pathvalue: unknown- Value to set
Record<string, unknown> - Modified object
Example:
flatten
Flatten nested object to single level with dot-notation keys.obj: Record<string, unknown>- Object to flattenprefix: string- Prefix for keys (default: ”)
Record<string, unknown> - Flattened object
Example:
unflatten
Unflatten object (reverse of flatten).obj: Record<string, unknown>- Flattened object
Record<string, unknown> - Nested object
Example:
filter
Filter object properties by predicate.obj: T- Source objectpredicate: (key: string, value: unknown) => boolean- Filter function
Partial<T> - Filtered object
Example:
mapValues
Map object values with a transformation function.obj: T- Source objectmapper: (value: unknown, key: string) => R- Mapper function
Record<string, R> - Object with mapped values
Example:
hasKeys
Check if object has all specified keys.obj: T- Object to checkkeys: (keyof T)[]- Keys to look for
boolean - True if all keys exist
Example:
hasAnyKey
Check if object has any of the specified keys.obj: T- Object to checkkeys: (keyof T)[]- Keys to look for
boolean - True if any key exists
Example:
invert
Invert object keys and values.obj: T- Object to invert
Record<string | number, string> - Inverted object
Example:
groupBy
Group array of objects by key.arr: T[]- Array to groupkey: keyof T- Key to group by
Record<string, T[]> - Grouped object
Example:
indexBy
Index array of objects by key.arr: T[]- Array to indexkey: keyof T- Key to index by
Record<string, T> - Indexed object
Example:
deepEqual
Check if two objects are deeply equal.a: unknown- First valueb: unknown- Second value
boolean - True if deeply equal
Example:
size
Get object size (number of keys).obj: Record<string, unknown> | null | undefined- Object to measure
number - Number of keys
Example:
entries
Convert object to array of [key, value] pairs.obj: T | null | undefined- Object to convert
Array<[string, unknown]> - Array of entries
Example:
fromEntries
Convert array of [key, value] pairs to object.entries: Array<[string, unknown]>- Array of entries
Record<string, unknown> - Object created from entries
Example:
assign
Assign properties from sources to target (like Object.assign).target: T- Target object (will be modified)...sources: Partial<T>[]- Source objects
T - Modified target object
Example:
fromKeys
Create object from keys with same value.keys: T[]- Array of keysvalue: unknown- Value for all keys
Record<T, unknown> - Object with all keys set to value
Example: