All files / js userLabel.tsx

16.66% Statements 2/12
0% Branches 0/10
0% Functions 0/1
16.66% Lines 2/12

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 281x 1x                                                    
import React from "react";
import { trans_obj, Translatable } from "./i18n";
 
/**
 * Formats a user label appropriately
 */
export function formatUserLabel(
  inputConfig: Translatable | string
): JSX.Element {
  const label =
    typeof inputConfig === "string" ? inputConfig : trans_obj(inputConfig);
 
  if (!label) {
    return <span />;
  }
 
  const iconData = label.match(/^\[\[\s*(.*?)\s*(;\s*(.*?))?\s*\]\]$/);
  if (iconData) {
    let className = "fa fa-" + iconData[1];
    if ((iconData[3] || "").match(/90|180|270/)) {
      className += " fa-rotate-" + iconData[3];
    }
    return <i className={className} />;
  }
 
  return <span>{label}</span>;
}