Amount
getCurrency
1.0.0- Dependencies:
- ∟Direct: 0
- ∟Peer: 0
- Source code ↗
- Check on NPM ↗
Hidden
Overview
Section titled “Overview”Gets the currency code of an amount, which represents the three-letter ISO currency code (e.g., ‘USD’, ‘EUR’, ‘GBP’).
amount.getCurrency();Features
Section titled “Features”- Returns the currency code as a string
- Always returns a valid CurrencyCode type
- Useful for currency validation and comparison
- Essential for multi-currency operations
- Simple and intuitive API
- No side effects - read-only operation
- Comprehensive testing
Arguments
Section titled “Arguments”| Arg | Type | Default Value | Required |
| No arguments required | |||
From an Amount instance, use the getCurrency() method to get the currency code.
import { amount } from '@inpulse-ui/utils';
const myAmount = amount(123.45, 'USD');const currency = myAmount.getCurrency();
console.log(currency); // 'USD'Works with different currencies:
const usdAmount = amount(99.99, 'USD');const eurAmount = amount(85.50, 'EUR');const gbpAmount = amount(75.25, 'GBP');
console.log(usdAmount.getCurrency()); // 'USD'console.log(eurAmount.getCurrency()); // 'EUR'console.log(gbpAmount.getCurrency()); // 'GBP'Currency validation before operations:
const amount1 = amount(100, 'USD');const amount2 = amount(50, 'EUR');
if (amount1.getCurrency() === amount2.getCurrency()) { console.log('Same currency - can perform operations');} else { console.log(`Currency mismatch: ${amount1.getCurrency()} vs ${amount2.getCurrency()}`);}// Output: "Currency mismatch: USD vs EUR"Multi-currency processing:
const amounts = [ amount(100, 'USD'), amount(85, 'EUR'), amount(75, 'GBP'), amount(200, 'USD')];
// Group by currencyconst byCurrency = amounts.reduce((acc, amt) => { const currency = amt.getCurrency(); if (!acc[currency]) acc[currency] = []; acc[currency].push(amt); return acc;}, {});
console.log(Object.keys(byCurrency)); // ['USD', 'EUR', 'GBP']Currency-specific formatting:
const amounts = [ amount(1234.56, 'USD'), amount(1234.56, 'EUR'), amount(1234.56, 'JPY')];
amounts.forEach(amt => { const currency = amt.getCurrency(); console.log(`${currency}: ${amt.format()}`);});// USD: $1,234.56// EUR: €1,234.56// JPY: ¥1,235 (typically no decimal places)Built with by Jo Santana in Brazil.
© 2026 Inpulse. All rights reserved.