How davidfranco3/intl-currency-helper works
This repository is a small, single-purpose JavaScript package: a currency-formatting helper built on top of the native Intl.NumberFormat API. Its architecture is intentionally thin, with almost all behavior centered in a single formatting module and a small set of supporting utilities.
1. Public API surface
- The package exports one core formatter, formatCurrency, plus convenience shorthands for common currencies: formatMXN, formatUSD, and formatEUR.
- It also exports configure, which mutates shared defaults used by later formatting calls.
- TypeScript consumers are supported through index.d.ts, which mirrors the runtime API.
2. Entry-point boundary
- index.js is the package entry point and likely re-exports the library’s public functions.
- This is the boundary between consumers and internal implementation details.
- The README indicates the library is meant to be imported directly from the package root, so the internal module layout is hidden from users.
3. Formatting pipeline
- The core data flow is: input amount + options → validation/normalization → Intl.NumberFormat formatting → optional currency code suffix.
- The formatter appears to support both explicit per-call options and globally configured defaults.
- The final string output is the only product of the library; there are no side effects beyond optional global configuration.
4. Global configuration model
- configure(...) establishes process-wide defaults for currency and locale.
- This means the library has a shared state layer, but it is intentionally narrow: it only affects subsequent formatting calls.
- In an architecture diagram, this is the main mutable state boundary in an otherwise stateless formatter.
5. Locale and currency abstractions
- The README references CURRENCIES and LOCALES, which suggests the library exposes constants/enums for common values.
- These constants form a small configuration vocabulary that reduces string literals in consumer code.
- The formatting engine still accepts raw locale and currency strings, so the abstraction is convenience-oriented rather than restrictive.
6. Validation and normalization
- The library advertises input validation, so numeric inputs and option values are checked before formatting.
- utils.js is the likely home for this shared logic: coercion, defaults, validation, and any helper functions used by both the core formatter and shorthand wrappers.
- This is a clear internal utility boundary separate from the public API.
7. Shorthand wrappers
- formatMXN, formatUSD, and formatEUR are thin convenience layers over the core formatter.
- Their role is to prefill currency and, in some cases, locale defaults while still allowing override options.
- In a diagram, these should be shown as wrappers feeding into the same core formatting path rather than separate subsystems.
8. Platform/runtime scope
- The package is runtime-agnostic and depends only on standard JavaScript internationalization support.
- It is explicitly compatible with both Node.js and browser/React environments, which means there is no framework coupling and no server/client split in the architecture.
- There are no external services, databases, or network calls.
9. Dependency profile
- The project is zero-dependency, so all behavior is implemented in-repo.
- That makes the architecture especially flat: one public entry point, one core formatter, one utility module, and type definitions/tests around them.
10. Testing boundary
- test.js and test_intl.js indicate two layers of verification: general library behavior and Intl-specific behavior.
- These tests likely validate formatting outputs, configuration behavior, and edge cases around locale/currency formatting.
- For architecture purposes, tests are an outer quality gate around the formatting core.
11. Package shape
- package.json defines the library metadata and package entry wiring.
- Together with index.js and index.d.ts, it forms a standard publishable npm library structure rather than an application runtime.
12. What is not in the architecture
- There are no UI components, routing layers, persistence layers, API clients, or background workers.
- The entire repository is centered on a single deterministic transformation: numbers to localized currency strings.
If you are drawing this repository, the cleanest diagram is a small library box with:
• public API functions at the top,
• a shared configuration state,
• a core formatter using Intl.NumberFormat,
• a utility/helper layer for validation and defaults,
• and tests/type definitions surrounding the implementation.
Main entry points: index.js Entry point · utils.js Utilities · package.json package.json · index.d.ts index.d.ts
Components 12
Public API
Consumer-facing entry point, shorthands, and type surface.
- package.json · Package metadata and publish wiring.
package.json - Entry point · Root export surface for the package.
index.js - formatCurrency · Core currency formatting API.
- formatMXN · MXN convenience wrapper over the core formatter.
- formatUSD · USD convenience wrapper over the core formatter.
- formatEUR · EUR convenience wrapper over the core formatter.
- index.d.ts · TypeScript declaration surface mirroring the runtime API.
index.d.ts
Core formatting
Shared state and the formatting pipeline built on Intl.NumberFormat.
- configure · Mutates shared defaults for later formatting calls.
- Defaults · Process-wide currency and locale defaults.
- Utilities · Validation, normalization, and shared helper logic.
utils.js - Intl.NumberFormat · Native internationalization formatter used for output rendering.
Quality gates
Tests that verify library behavior and Intl-specific output.
- Tests · General behavior and Intl-specific verification.
Connections 17
- package.json → Entry point: entry · Package metadata points consumers to the entry module.
- Entry point → formatCurrency: exports · Root module exposes the core formatter.
- Entry point → configure: exports · Root module exposes shared configuration.
- Entry point → formatMXN: exports · Root module exposes the MXN shorthand.
- Entry point → formatUSD: exports · Root module exposes the USD shorthand.
- Entry point → formatEUR: exports · Root module exposes the EUR shorthand.
- Entry point → index.d.ts: typed by · Declaration file mirrors the public runtime API.
- formatMXN → formatCurrency: wraps · Prefills currency before calling the core formatter.
- formatUSD → formatCurrency: wraps · Prefills currency before calling the core formatter.
- formatEUR → formatCurrency: wraps · Prefills currency before calling the core formatter.
- configure → Defaults: updates · Sets process-wide defaults for later calls.
- formatCurrency → Defaults: reads · Uses configured defaults when explicit options are absent.
- formatCurrency → Utilities: uses · Delegates validation and normalization to shared helpers.
- Utilities → Intl.NumberFormat: feeds · Prepares options for native formatting.
- formatCurrency → Intl.NumberFormat: formats · Produces the localized currency string via the native API.
- Tests → Entry point: verifies · Exercises the public API surface.
- Tests → Intl.NumberFormat: verifies · Checks Intl-specific formatting behavior.