Amount
min
1.0.0- Dependencies:
- ∟Direct: 0
- ∟Peer: 0
- Source code ↗
- Check on NPM ↗
Hidden
Overview
Section titled “Overview”Finds the minimum amount from an AmountArray by comparing the values of all amounts in the array.
amountArray.min();Features
Section titled “Features”- Returns a new
Amountinstance with the smallest value - Requires all amounts to have the same currency
- Maintains immutability - original array remains unchanged
- Compares amounts based on their cent values
- Throws error for empty arrays or mixed currencies
- Simple and intuitive API
- Comprehensive testing
Arguments
Section titled “Arguments”| Arg | Type | Default Value | Required |
| No arguments required | |||
From an AmountArray instance, use the min() method to find the amount with the smallest value.
import { amount, AmountArray } from '@inpulse-ui/utils';
const amounts = new AmountArray( amount(100, 'USD'), amount(50, 'USD'), // Minimum value amount(200, 'USD'), amount(75, 'USD'));
const result = amounts.min();
console.log(result); // Results in Amount instance with value 50 USDIt requires all amounts to have the same currency:
const validAmounts = new AmountArray( amount(33.33, 'EUR'), amount(33.34, 'EUR'), amount(33.32, 'EUR') // Minimum value);
const result = validAmounts.min();
console.log(result); // Results in Amount instance with value 33.32 EURIt throws an error for mixed currencies:
const mixedAmounts = new AmountArray( amount(100, 'USD'), amount(50, 'EUR') // Different currency);
// This will throw: "All amounts must have the same currency for min/max operations."const result = mixedAmounts.min();It throws an error for empty arrays:
const emptyArray = new AmountArray();
// This will throw: "AmountArray must be non-empty."const result = emptyArray.min();Works with negative values:
const amountsWithNegatives = new AmountArray( amount(100, 'GBP'), amount(-50, 'GBP'), // Minimum value amount(25, 'GBP'));
const result = amountsWithNegatives.min();
console.log(result); // Results in Amount instance with value -50 GBPExamples
Section titled “Examples”Imagine a scenario in an e-commerce application. Based on store settings, you need to find the lowest installment amount to present at checkout.
import { amount } from '@inpulse-ui/utils';
// Customer's shopping cart totalconst cartTotal = amount(1000, 'USD');
// Split into 6 installments using split() methodconst installments = cartTotal.split(6);
console.log(installments); // AmountArray with 6 installment amounts
// Store setting: Apply additional fee to the smallest installment// Find the lowest installment to adjust pricingconst lowestInstallment = installments.min();
console.log(`Lowest installment: ${lowestInstallment}`);// Use this value to add processing fees or adjust for rounding differencesBuilt with by Jo Santana in Brazil.
© 2026 Inpulse. All rights reserved.