All files / helpers classNameHelpers.ts

100% Statements 31/31
100% Branches 12/12
100% Functions 2/2
100% Lines 31/31

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 321x 1x 1x 1x 1x 5314x 5314x 5314x 5087x 5089x 5056x 5056x 5087x 5314x 31x 31x 5087x 5087x 5087x 5087x 5087x 5087x 1x 1x 1932x 1932x 1932x 1932x 1932x 1932x 1932x  
type CssClassNameItem = string | undefined | null;
type CssClassName = CssClassNameItem | CssClassNameItem[];
type CssClassNameParams = CssClassName[];
 
const getCssClasses = (classNames: CssClassName): string => {
  let classNameList: CssClassNameItem[] = [];
 
  if (classNames == null) return '';
 
  if (typeof classNames === 'string') {
    classNameList = classNames.split(/[\s]+/g);
  }
 
  if (Array.isArray(classNames)) {
    classNameList = classNames;
  }
 
  return classNameList
    .map(className => (className ?? '').trim())
    .filter(Boolean)
    .join(' ');
};
 
export const c = (...params: CssClassNameParams): string => {
  const classNamesList = params
    .map(param => getCssClasses(param))
    .filter(Boolean)
    .join(' ');
 
  return getCssClasses(classNamesList);
};