@signaldb/core
Version:
SignalDB is a client-side database that provides a simple MongoDB-like interface to the data with first-class typescript support to achieve an optimistic UI. Data persistence can be achieved by using storage providers that store the data through a JSON in
14 lines (13 loc) • 858 B
TypeScript
/**
* Sets a value at a specified path within an object. Creates nested structures
* (arrays or objects) as needed to set the value at the correct location. Supports
* deleting the key if the value is `undefined` and the `deleteIfUndefined` flag is set to `true`.
* @template T - The type of the object to modify.
* @template K - The type of the value to set.
* @param object - The object to modify. The object is mutated directly.
* @param path - The path (dot or bracket notation) where the value should be set.
* @param value - The value to set at the specified path.
* @param deleteIfUndefined - A boolean indicating whether to delete the key if the value is `undefined` (default: `false`).
* @returns The modified object.
*/
export default function set<T extends object, K>(object: T, path: string, value: K, deleteIfUndefined?: boolean): T;