@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
29 lines (28 loc) • 780 B
JavaScript
import get from "./index25.mjs";
import set from "./index28.mjs";
function project(item, fields) {
const allFieldsDeactivated = Object.values(fields).every((value) => value === 0);
if (allFieldsDeactivated) {
const result2 = { ...item };
Object.keys(fields).forEach((key) => {
const fieldValue = get(item, key);
if (fieldValue === void 0)
return;
set(result2, key, void 0, true);
});
return result2;
}
const result = {};
Object.entries(fields).forEach(([key, value]) => {
const fieldValue = get(item, key);
if (fieldValue === void 0)
return;
if (fieldValue == null && value !== 1)
return;
set(result, key, value === 1 ? fieldValue : void 0);
});
return result;
}
export {
project as default
};