import has from 'lodash/has'; import isArray from 'lodash/isArray'; export const mapOptions = (values) => { let first = values[0]; if (!isArray(values)) { values = flatScale(values); } if (has(first, 'id')) { return values.map((step) => { let icon = null; let additionalAttributes = {}; if (has(step, 'icon')) { icon = step.icon; } return { label: step.label, value: step.id.toString(), icon: icon, ...additionalAttributes, }; }); } else { return values.map((step) => { if (step == null) { console.log('Blockbite mapOptions step is undefined', values); throw new Error('Blockbite mapOptions step is undefined'); } return { label: step.toString(), value: step.toString(), icon: null, }; }); } }; export const flatScale = (values) => { let valueList = []; for (let key in values) { valueList.push(key); } return valueList; }; export default { mapOptions, flatScale };