Amount
isEqualTo
1.0.0- Dependencies:
- ∟Direct: 0
- ∟Peer: 0
- Source code ↗
- Check on NPM ↗
Hidden
Overview
Section titled “Overview”Checks if an amount is equal to another amount by comparing both the cents value and currency. This method has an alias named equals() for convenience.
amount.isEqualTo(/amount/);// or using the aliasamount.equals(/amount/);Features
Section titled “Features”- Returns a boolean value indicating if amounts are equal
- Compares both cents value and currency for exact equality
- Requires both amounts to have the same currency
- Has a convenient
equals()alias method - Simple and intuitive API
- No side effects - read-only operation
- Comprehensive testing
Arguments
Section titled “Arguments”| Arg | Type | Default Value | Required |
amount | Amount | - | Yes |
From an Amount instance, use the isEqualTo() method to check if it equals another amount.
import { amount } from '@inpulse-ui/utils';
const amount1 = amount(100, 'USD');const amount2 = amount(100, 'USD');const result = amount1.isEqualTo(amount2);
console.log(result); // trueUsing the equals() alias:
const amount1 = amount(50.75, 'EUR');const amount2 = amount(50.75, 'EUR');
console.log(amount1.equals(amount2)); // true - same as isEqualTo()It returns false for different values:
const amount1 = amount(100, 'USD');const amount2 = amount(50, 'USD');
console.log(amount1.isEqualTo(amount2)); // falseconsole.log(amount1.equals(amount2)); // falseIt returns false for different currencies:
const amount1 = amount(100, 'USD');const amount2 = amount(100, 'EUR'); // Same value, different currency
console.log(amount1.isEqualTo(amount2)); // falseUseful for conditional logic:
const expectedPayment = amount(250.00, 'USD');const receivedPayment = amount(250.00, 'USD');
if (receivedPayment.equals(expectedPayment)) { console.log('Payment received in full');} else { console.log('Payment amount mismatch');}// Output: "Payment received in full"Validation in business logic:
const orderTotal = amount(99.99, 'USD');const paymentAmount = amount(99.99, 'USD');
if (paymentAmount.isEqualTo(orderTotal)) { console.log('Processing order...'); // Proceed with order processing} else { console.log('Payment amount does not match order total');}// Output: "Processing order..."Built with by Jo Santana in Brazil.
© 2026 Inpulse. All rights reserved.