All files / lib format.ts

100% Statements 5/5
100% Branches 2/2
100% Functions 2/2
100% Lines 5/5

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 256x                     15x 1x     14x             61x    
const euroFormatter = new Intl.NumberFormat("it-IT", {
  currency: "EUR",
  style: "currency",
});
 
export type ClassNameValue = false | null | string | undefined;
 
/**
 * Formats an integer cent amount for shopper-facing prices.
 */
export function formatPrice(amountCents: number): string {
  if (!Number.isFinite(amountCents)) {
    throw new TypeError("Price amount must be a finite number of cents.");
  }
 
  return euroFormatter.format(amountCents / 100);
}
 
/**
 * Small dependency-free class name combiner for UI components.
 */
export function cx(...classes: readonly ClassNameValue[]): string {
  return classes.filter(Boolean).join(" ");
}