UNPKG

@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

16 lines (15 loc) 914 B
/** * Projects the fields of an object based on a specified fields configuration. * Supports inclusion (`1`) and exclusion (`0`) of specific fields. Creates a new object * with the desired fields included or excluded, based on the configuration. * @template T - The type of the object being projected. * @param item - The original object to project fields from. * @param fields - An object defining the fields to include (`1`) or exclude (`0`). * - Keys are the field names, and values are either `1` (include) or `0` (exclude). * @returns A new object with the specified fields included or excluded. * - If all fields are set to `0`, the excluded fields are removed from the result. * - If fields are set to `1`, only the included fields are retained. */ export default function project<T extends Record<string, any>>(item: T, fields: { [P in keyof T]?: 0 | 1; } & Record<string, 0 | 1>): T;