@e-group/utils
Version:
eGroup team utils that share across projects.
39 lines (31 loc) • 771 B
JavaScript
/**
* Customized render function for each element.
*/
/**
* Defined displayValues schema.
*/
/**
* To displayValues by schema.
*/
export default function displayValues(schema, renderEach) {
return schema.map(item => {
const plainValue = item.value;
const valueType = typeof plainValue;
if (valueType === 'boolean' && !plainValue) {
return undefined;
}
if (valueType === 'undefined') {
return undefined;
}
if (Array.isArray(plainValue) && plainValue.filter(Boolean).length === 0) {
return undefined;
}
if (valueType === 'string' && plainValue === '') {
return undefined;
}
if (typeof item.render === 'function') {
return item.render(item);
}
return renderEach(item);
});
}