initial commit on github
This commit is contained in:
Executable
+31
@@ -0,0 +1,31 @@
|
||||
export interface ObjectClassNames {
|
||||
[index: string]: boolean;
|
||||
}
|
||||
|
||||
export type ClassName = number | string | ObjectClassNames | false | null | undefined;
|
||||
|
||||
export default function classNames(...classNames: ClassName[]) {
|
||||
let result: string[] = [];
|
||||
|
||||
classNames.forEach((item: ClassName): void => {
|
||||
if(!item) {
|
||||
return;
|
||||
}
|
||||
switch(typeof item) {
|
||||
case 'string':
|
||||
result.push(item);
|
||||
break;
|
||||
case 'object':
|
||||
Object.keys(item).forEach((key: string) => {
|
||||
if(item[key]) {
|
||||
result.push(key);
|
||||
}
|
||||
});
|
||||
break;
|
||||
default:
|
||||
result.push(`${item}`);
|
||||
}
|
||||
});
|
||||
|
||||
return result.join(' ');
|
||||
}
|
||||
Reference in New Issue
Block a user