@bamotf/utils
A typescript utility library to help with formatting and stuff like that.
Getting started
npm install @bamotf/utilsUsage
import { ... } from '@bamotf/utils';API
format
format(locale: string, opts: FormatOpts): string
format(opts: FormatOpts): stringFormats 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 }): numberConverts 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 }): bigintConvert 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.