tbleckert/react-select-search

View on GitHub
src/lib/flattenOptions.js

Summary

Maintainability
A
0 mins
Test Coverage
export default function flattenOptions(options) {
    let index = 0;

    return options.map((option) => {
        if (option.type === 'group') {
            return option.items.map((o) => ({
                ...o,
                group: option.name,
                index: index++,
            }));
        }

        return { ...option, index: index++ };
    }).flat();
}