web / lib/utils/object-path
lib/utils/object-path
Dot-notation path utilities for nested object access.
Provides get, set, and delete operations on objects using dot-separated path strings (e.g., “user.email”).
Functions
getByPath()
getByPath(
obj,path):unknown
Get value at path using dot notation.
Returns undefined if any part of the path doesn’t exist.
Parameters
obj
unknown
path
string
Returns
unknown
Example
const obj = { user: { email: "test@example.com" } };
getByPath(obj, "user.email"); // "test@example.com"
getByPath(obj, "user.phone"); // undefinedsetByPath()
setByPath(
obj,path,value):void
Set value at path using dot notation.
Creates nested objects as needed along the path. Mutates the input object in place.
Parameters
obj
Record<string, unknown>
path
string
value
unknown
Returns
void
Example
const obj = {};
setByPath(obj, "user.email", "test@example.com");
// Result: { user: { email: "test@example.com" } }deleteByPath()
deleteByPath(
obj,path):void
Delete value at path using dot notation.
Removes the property at the specified path. Does nothing if the path doesn’t exist.
Parameters
obj
Record<string, unknown>
path
string
Returns
void
Example
const obj = { user: { email: "test@example.com", name: "John" } };
deleteByPath(obj, "user.email");
// Result: { user: { name: "John" } }Last updated on