Engineering
dinero-best-practices avatar

dinero-best-practices

Enforce best practices for Dinero.js. Use when handling monetary values, performing arithmetic, or refactoring code to ensure safe, type-safe, and accurate currency calculations in JS/TS applications.

Introduction

This skill acts as an expert advisor for developers working with the Dinero.js library to manage money in JavaScript and TypeScript environments. It is designed for software engineers, full-stack developers, and financial application architects who need to navigate the complexities of monetary precision, immutability, and type-safe financial logic. The skill provides actionable guidance on avoiding common pitfalls like floating-point errors, incorrect currency rounding, and improper scaling, ensuring that your financial primitives are robust and production-ready.

  • Validates object creation patterns, ensuring amounts are passed as integers in minor currency units to prevent precision loss.

  • Advises on proper arithmetic operations, enforcing the use of allocate over division and guiding the use of scaled amounts for percentages.

  • Enforces precision management, helping developers choose between standard number-based calculators and bigint calculators for large-scale financial applications.

  • Guides tree-shaking and module imports, ensuring that bundles remain small and dependencies are correctly matched for bigint vs standard precision.

  • Promotes immutability by reminding developers that every operation returns a new object, which is essential for predictable state management.

  • Provides clear rules for currency formatting, including how to handle zero-exponent currencies like JPY and how to trim scales correctly.

  • Triggers when importing from dinero.js, dinero.js/currencies, or dinero.js/bigint to maintain architectural consistency.

  • Supports debugging of complex financial calculations such as VAT distribution, multi-currency conversion, and percentage-based price adjustments.

  • Intended for use during code reviews, refactoring sessions, or when bootstrapping new financial modules in a project.

  • Operates under the principle that money is complex and requires specialized abstractions to avoid standard JavaScript numeric pitfalls.

  • Helps bridge the gap between business requirements for financial accuracy and the practical limitations of IEEE 754 floating-point numbers.

Repository Stats

Stars
6,732
Forks
201
Open Issues
12
Language
TypeScript
Default Branch
main
Sync Status
Idle
Last Synced
May 1, 2026, 09:26 AM
View on GitHub