@bamotf/utils
A typescript utility library to help with formatting and stuff like that.
Getting started
npm install @bamotf/utils
Usage
import { ... } from '@bamotf/utils';
API
format
format(locale: string, opts: FormatOpts): string
format(opts: FormatOpts): string
Formats a currency amount visually.
locale
(optional): The locale to use for formatting. Defaults to'en-US'
.opts
: The formatting options.amount
: The amount to be formatted (as abigint
).currency
: The currency code.
Returns the formatted currency amount as a string.
getFractionDigits
getFractionDigits(currency: CurrencyCode): { minimumFractionDigits: number, maximumFractionDigits: number }
Returns the minimum and maximum fraction digits for a given currency.
currency
: The currency code.
Returns an object with the following properties:
minimumFractionDigits
: The minimum number of fraction digits.maximumFractionDigits
: The maximum number of fraction digits.
fractionate
fractionate(opts: { amount: bigint, currency: CurrencyCode }): number
Converts a bigint
amount to a fractionated number based on the currency
decimal places.
opts
: The conversion options.amount
: The amount to be converted (as abigint
).currency
: The currency code.
removeFraction
removeFraction(opts: { amount: number, currency: CurrencyCode }): bigint
Convert the given amount to a bigint
based on the currency decimal places.
opts
: The conversion options.amount
: The amount of satoshis to be converted (as abigint
).currency
: The currency code.