Amount
configure
1.0.0- Dependencies:
- ∟Direct: 0
- ∟Peer: 0
- Source code ↗
- Check on NPM ↗
Hidden
Overview
Section titled “Overview”Configures global defaults for Amount operations such as default currency and rounding behavior. This is a static method that affects all Amount instances. It has aliases named config() and setConfig() for convenience.
Amount.configure(/config/);// or using aliasesAmount.config(/config/);Amount.setConfig(/config/);Features
Section titled “Features”- Sets global configuration for all Amount instances
- Configures default currency and rounding behavior
- Has convenient
config()andsetConfig()aliases - Affects operations like multiply, divide, and convert
- Persists until explicitly changed or reset
- Static method - called on the Amount class
- Simple and intuitive API
- Comprehensive testing
Arguments
Section titled “Arguments”| Arg | Type | Default Value | Required |
config | AmountConfig | - | Yes |
Configure global defaults for Amount operations using the static configure() method.
import { Amount } from '@inpulse-ui/utils';
// Set global configurationAmount.configure({ defaultCurrency: 'USD', defaultRounding: 'bank'});
// Now all Amount operations use these defaultsconst amount1 = Amount.set(100); // Uses USD as default currencyconst result = amount1.multiply(1.5); // Uses bank rounding by defaultUsing the config() alias:
// Equivalent to configure()Amount.config({ defaultCurrency: 'EUR', defaultRounding: 'math'});Using the setConfig() alias:
// Also equivalent to configure()Amount.setConfig({ defaultCurrency: 'GBP', defaultRounding: 'bank'});Configure default currency:
// Set EUR as default currencyAmount.configure({ defaultCurrency: 'EUR'});
// Now Amount.set() uses EUR when no currency is specifiedconst price = Amount.set(99.99); // Creates amount in EURconsole.log(price.getCurrency()); // 'EUR'Configure default rounding:
// Set mathematical rounding as defaultAmount.configure({ defaultRounding: 'math'});
// All multiply/divide operations use math rounding by defaultconst amount = Amount.set(10, 'USD');const result = amount.multiply(1.333); // Uses math roundingExamples
Section titled “Examples”Imagine an e-commerce platform operating in Brazil:
Amount.configure({ defaultCurrency: 'BRL', defaultLocale: 'pt-BR' });const total = Amount.set(299.90).add(25.50).format(); // "R$ 325,40"Now, imagine its usage in a US-based SaaS application:
Amount.configure({ defaultCurrency: 'USD', defaultLocale: 'en-US' });const monthly = Amount.set(49.99).divideBy(30).multiply(15); // Prorated billingNow, imagine its usage in a German payment application:
Amount.configure({ defaultCurrency: 'EUR', defaultLocale: 'de-DE', defaultRounding: 'bank' });const vatPrice = Amount.set(100).multiply(1.19); // German VATYou could config at the application initialization:
// Set up global defaults at application startfunction initializeApp() { Amount.configure({ defaultCurrency: 'USD', defaultRounding: 'bank' });
// Rest of application initialization}
// Later in the applicationconst orderAmount = Amount.set(299.99); // Automatically uses USDconst tax = orderAmount.multiply(0.08); // Uses bank roundingHere’s how you might configure based on user region:
// Configure based on user's regionconst userRegion = getUserRegion();
switch (userRegion) { case 'US': Amount.config({ defaultCurrency: 'USD', defaultRounding: 'math' }); break; case 'EU': Amount.config({ defaultCurrency: 'EUR', defaultRounding: 'bank' }); break; case 'UK': Amount.config({ defaultCurrency: 'GBP', defaultRounding: 'bank' }); break;}Imagine different configurations for development and production environments:
// Different configurations for different environmentsif (process.env.NODE_ENV === 'development') { Amount.configure({ defaultCurrency: 'USD', defaultRounding: 'math' });} else { Amount.configure({ defaultCurrency: process.env.DEFAULT_CURRENCY || 'USD', defaultRounding: 'bank' // More conservative for production });}Built with by Jo Santana in Brazil.
© 2026 Inpulse. All rights reserved.