All files / lib formatSalary.ts

91.66% Statements 11/12
40% Branches 2/5
100% Functions 2/2
91.66% Lines 11/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 131x 1x 1x 11x 11x 11x 11x   11x 11x 11x 11x  
import type { Salary } from "../types/job";
 
export function formatSalary(salary: Salary): string {
  const fmt = (n: number) => n.toLocaleString("en-US");
  const range =
    salary.min !== null && salary.max !== null && salary.min !== salary.max
      ? `${fmt(salary.min)}–${fmt(salary.max)}`
      : fmt(salary.min ?? salary.max ?? 0);
  const currency = salary.currency ? `${salary.currency} ` : "";
  const period = salary.period ? ` / ${salary.period}` : "";
  return `${currency}${range}${period}`;
}