@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
24 lines (23 loc) • 828 B
JavaScript
import deepClone from "./index6.mjs";
import { update } from "mingo";
//#region src/utils/modify.ts
/**
* Applies a modifier to an object and returns a new modified object.
* @template T - The type of the object to be modified.
* @param item - The object to be modified.
* @param modifier - The modifier to apply. This can be any transformation logic.
* @returns - Returns a new object with the modifications applied.
* @example
* const item = { a: 1, b: 2 }
* const modifier = { $set: { b: 3, c: 4 } }
* const result = modify(item, modifier)
* // result: { a: 1, b: 3, c: 4 }
*/
function modify(item, modifier) {
if (!Object.keys(modifier).some((key) => key.startsWith("$"))) return modifier;
const clonedItem = deepClone(item);
update(clonedItem, modifier);
return clonedItem;
}
//#endregion
export { modify as default };