legends810/testingnew
0
1/**2 * Copyright (c) 2018 Jed Watson.3 * Licensed under the MIT License (MIT), see:4 *5 * @link http://jedwatson.github.io/classnames6 */7 8type ClassNamesArg = undefined | string | Record<string, boolean> | ClassNamesArg[];9 10/**11 * A simple JavaScript utility for conditionally joining classNames together.12 *13 * @param args A series of classes or object with key that are class and values14 * that are interpreted as boolean to decide whether or not the class15 * should be included in the final class.16 */17export function classNames(...args: ClassNamesArg[]): string {18 let classes = '';19 20 for (const arg of args) {21 classes = appendClass(classes, parseValue(arg));22 }23 24 return classes;25}26 27function parseValue(arg: ClassNamesArg) {28 if (typeof arg === 'string' || typeof arg === 'number') {29 return arg;30 }31 32 if (typeof arg !== 'object') {33 return '';34 }35 36 if (Array.isArray(arg)) {37 return classNames(...arg);38 }39 40 let classes = '';41 42 for (const key in arg) {43 if (arg[key]) {44 classes = appendClass(classes, key);45 }46 }47 48 return classes;49}50 51function appendClass(value: string, newClass: string | undefined) {52 if (!newClass) {53 return value;54 }55 56 if (value) {57 return value + ' ' + newClass;58 }59 60 return value + newClass;61}62 