Spaces:
Runtime error
Runtime error
Download apps/api/src/services/expense/slip-queue/amount-format.ts from ClaraSu/llm-router: direct link, hf CLI and curl.
- Browser
- Download file 977 Bytes
-
https://huggingface.co/spaces/ClaraSu/llm-router/resolve/main/apps/api/src/services/expense/slip-queue/amount-format.ts
- Command line
-
hf download hf://spaces/ClaraSu/llm-router/apps/api/src/services/expense/slip-queue/amount-format.ts
-
curl -L -o amount-format.ts https://huggingface.co/spaces/ClaraSu/llm-router/resolve/main/apps/api/src/services/expense/slip-queue/amount-format.ts
977 Bytes
| // 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 } | |