Amount
add
1.0.0- Dependencies:
- ∟Direct: 0
- ∟Peer: 0
- Source code ↗
- Check on NPM ↗
Hidden
Overview
Section titled “Overview”Adds an amount to another amount.
amount.add(/amount/);Features
Section titled “Features”- Returns a single
Amountas result - Accepts mixed parameter types
- Automatically inherits currency from the current Amount instance
- Maintains type safety with proper error handling for currency mismatches
- Simple and intuitive API
- Comprehensive testing
Arguments
Section titled “Arguments”| Arg | Type | Default Value | Required |
amount | Amount | number | string | - | Yes |
From an initial Amount instance, use the add() method to add an Amount, number, or string value to it.
import { amount } from '@inpulse-ui/utils';
const amount1 = amount(100.00, 'USD');const amount2 = amount('50.00', 'USD'); // You can also use string valuesconst amount3 = amount(25); // Inherits the current currency when not providedconst result = amount1.add(amount2).add(amount3).add(50).add('25');
console.log(result); // Results an Amount instance with value 250 USDIt handles negative values correctly:
const value = amount(10.50, 'USD');const result = value.add(-5.25); // Subtracts 5.25 from 10.50 USDIt will throw an error if you try to add an amount with a different currency:
const value = amount(100, 'USD');const result = value.add(50, 'EUR'); // Currency mismatch: USD vs EURBuilt with by Jo Santana in Brazil.
© 2026 Inpulse. All rights reserved.