@spaced-out/ui-design-system
Version:
Sense UI components library
30 lines (25 loc) • 661 B
Flow
// @flow strict
import isPlainObject from 'lodash/isPlainObject';
import map from 'lodash/map';
export function classify(...args: Array<mixed>): string {
return args
.map((arg) => {
let mappedArg = arg;
if (isPlainObject(arg)) {
// $FlowFixMe[incompatible-call]
mappedArg = map(arg, (test, name: string) => (test ? name : null));
}
return mappedArg;
})
.reduce((array, current) => {
if (Array.isArray(current)) {
array.push(...current);
} else {
array.push(current);
}
return array;
}, [])
.filter((val) => val)
.join(' ');
}
export default classify;