// Decimal-format handling shared between the legacy hardcoded RegexReceiptParser // (always 'us') and the country-agnostic TemplateReceiptParser, whose templates // carry their own `decimal_style`. See // docs/superpowers/specs/2026-08-08-country-agnostic-receipt-templates-design.md. export type DecimalStyle = 'us' | 'eu' export interface AmountFormat { // Matches a single decimal-shaped number, e.g. "1,234.56" (us) or "1.234,56" (eu). pattern: RegExp parse: (raw: string) => number } const US_AMOUNT_NUMBER = /\d{1,3}(?:,\d{3})*\.\d{1,2}/ const EU_AMOUNT_NUMBER = /\d{1,3}(?:\.\d{3})*,\d{1,2}/ export function amountFormatFor(style: DecimalStyle): AmountFormat { if (style === 'eu') { return { pattern: EU_AMOUNT_NUMBER, parse: (raw) => Number(raw.replace(/\./g, '').replace(',', '.')), } } return { pattern: US_AMOUNT_NUMBER, parse: (raw) => Number(raw.replace(/,/g, '')), } } export { US_AMOUNT_NUMBER, EU_AMOUNT_NUMBER }