All files / src/assets/icons utils.ts

21.42% Statements 3/14
0% Branches 0/10
50% Functions 1/2
21.42% Lines 3/14

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 32 33 34 35 36 37 38 39 40 41 42 43    519x 139x                     519x                                                        
import { palette } from "@palette";
 
export const getDefaults = () => {
  return {
    fill: palette.primary.main,
    stroke: palette.primary.main,
    size: "24px",
  };
};
 
interface handleFractionProps {
  digits: number | string | undefined;
}
 
export const handleFraction = ({ digits }: handleFractionProps) => {
  if (typeof digits === "number" || typeof digits === "string") {
    if (typeof digits === "string") {
      return digits;
    }
    // to not show fractions if number is large
    const digitsString = digits.toString();
    if (digitsString.includes(".")) {
      // find length before dot
      const lengthBeforeDot = digitsString.split(".")[0].length;
 
      // if length is 4 or more, then we don't need to show all fraction
      if (lengthBeforeDot >= 4) {
        return digits?.toLocaleString("en-US", {
          maximumFractionDigits: 2,
        });
      } else {
        return digits?.toLocaleString("en-US", {
          maximumFractionDigits: 4,
        });
      }
    } else {
      return digitsString;
    }
  } else {
    return "";
  }
};