Currency handling patterns for the Dinero.js money library. Use when working with multiple currencies, converting between currencies, defining custom currencies, storing monetary values in databases, or integrating with payment services like Stripe or PayPal. Triggers on currency conversion, database schema design for money, or payment API integration with Dinero objects.
Patterns for handling currencies with Dinero.js: type safety, conversions, custom currencies, database storage, and payment service integration.
Reference these guidelines when:
convert| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Type Safety |
| HIGH |
types- |
| 2 | Conversion | HIGH | convert- |
| 3 | Storage | HIGH | storage- |
| 4 | Payment Integration | MEDIUM | payment- |
types-as-const - Define custom currencies with as const satisfies for compile-time safetytypes-currency-mismatch - TypeScript catches currency mismatches in operations at compile timetypes-lookup-validation - Validate currency codes from external sources at runtimeconvert-scaled-rates - Use scaled amounts for fractional exchange rates, not floatsconvert-reusable - Build reusable converter functions with higher-order patternsstorage-database - Store amount, currency code, and scale as separate columnsstorage-no-money-type - Avoid PostgreSQL's money type for multi-currency applicationspayment-services - Map Dinero objects to payment service formats with dedicated helpersRead individual rule files for detailed explanations and code examples:
rules/types-as-const.md
rules/convert-scaled-rates.md
Each rule file contains: