All files / src/utils formatUtils.ts

77.77% Statements 14/18
100% Branches 6/6
50% Functions 1/2
85.71% Lines 12/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 142x 2x 2x 2x 2x 2x 2x 2x   29x 18x   16x 2x
// src/utils/formatUtils.ts
 
/**
 * Formats a numeric value in cents into a currency string (e.g., $4.99).
 * Handles different locales and currency symbols gracefully.
 *
 * @param amountInCents The amount in cents to format. Can be null or undefined.
 * @returns A formatted currency string (e.g., "$4.99"), or 'N/A' if the input is null/undefined.
 */
export const formatCurrency = (amountInCents: number | null | undefined): string => {
  if (amountInCents === null || amountInCents === undefined) return 'N/A';

  return new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(amountInCents / 100);
};