UNPKG

@sgnl-pro/react-tree

Version:

A tree view component for React

62 lines (55 loc) 1.12 kB
export type ClassValue = | ClassArray | ClassDictionary | string | number | null | boolean | undefined; export interface ClassDictionary { [id: string]: any; } export interface ClassArray extends Array<ClassValue> {} function toVal(mix: ClassValue) { var k, y, str = ''; if (typeof mix === 'string' || typeof mix === 'number') { str += mix; } else if (typeof mix === 'object') { if (Array.isArray(mix)) { for (k = 0; k < mix.length; k++) { if (mix[k]) { if ((y = toVal(mix[k]))) { str && (str += ' '); str += y; } } } } else { for (k in mix) { if (mix !== null && mix[k]) { str && (str += ' '); str += k; } } } } return str; } export default function (...classes: ClassValue[]): string { let i = 0, tmp, x, str = ''; const classesCount = classes.length; while (i < classesCount) { if ((tmp = classes[i++])) { if ((x = toVal(tmp))) { str && (str += ' '); str += x; } } } return str; }