@inpulse-ui/utils
v1.0.0
Published
Inpulse UI Utilities
Maintainers
Readme
@inpulse-ui/utils
An ever expanding utility library to help you deliver confident ecommerce and SaaS projects.
Installation
pnpm add @inpulse-ui/utils
# or
bun add @inpulse-ui/utils
# or
yarn add @inpulse-ui/utils
# or
npm install @inpulse-ui/utilsAbout Amount
The Amount utility can help you deal with monetary values when you're in a context of ecommerce stores, ERPs and simple reports. This utility converts all numbers to Int (cents) and is fast, simple and precise.
But if you're dealing with large numbers, complex calculations, compound interest and crypto currency, you'll be in better hands using libraries like Dinero.js or Big.js.
Convert method
The convert method inside Amount should consider a ratio value much like the ones exposed by common exchange APIs. For instance, here's one by Fixer:
{
"success": true,
"timestamp": 1519296206,
"base": "EUR",
"date": "2025-09-25",
"rates": {
"AUD": 1.566015,
"CAD": 1.560132,
"CHF": 1.154727,
"CNY": 7.827874,
"GBP": 0.882047,
"JPY": 132.360679,
"USD": 1.23396,
[...]
}
}Before using convert, you should fetch the ratios for a given currency and then, pass the proper value to the function.
import { amount } from '@inpulse-ui/utils';
const ratios = {
"base": "EUR",
"rates": {
"USD": 1.23396
}
};
const { rates } = ratios;
const value = amount.set(19.99, 'EUR');
const targetValue = amount.convert(value, 'USD', rates['USD']);Other services like FastForex, ExchangeRatiosAPI and Open Exchange Rates offer a similar API response and should work properly with our function.
Documentation
Visit https://ui.inpulse.cx/utils/getting-started to view the documentation.
License
Licensed under the MIT license.
