@payloadcms/plugin-import-export
Version:
Import-Export plugin for Payload
23 lines (22 loc) • 732 B
JavaScript
/**
* Takes an input of array of string paths in dot notation and returns a select object
* example args: ['id', 'title', 'group.value', 'createdAt', 'updatedAt']
*/ export const getSelect = (fields)=>{
const select = {};
fields.forEach((field)=>{
const segments = field.split('.');
let selectRef = select;
segments.forEach((segment, i)=>{
if (i === segments.length - 1) {
selectRef[segment] = true;
} else {
if (!selectRef[segment]) {
selectRef[segment] = {};
}
selectRef = selectRef[segment];
}
});
});
return select;
};
//# sourceMappingURL=getSelect.js.map