The npm country-currency-utils package allows developers to manage a list of over 200 countries and corresponding currencies without storing them within their codebase.
Country-specific data, including country name, dial code, currency code, and flag emojis, among other details, can be accessed through different functions of the package such as getAllCountryDetails(), getAllCountryData(), and getCountryData(countryCode: string).
Similarly, the package also provides information on currency codes, currency symbols, digit grouping, and decimal precision.
The package also has utility functions to handle monetary amounts such as rounding and formatting. These include getRoundedAmount(), getFormattedAmountOnCurrency(), and getDisplayAmountOnCurrency().
getRoundedAmount() can be used to round a monetary amount either up or down. The method getRoundedAmountOnCurrency() adjusts the rounding to suit the currency.
The function getFormattedAmountOnCurrency() retrieves the amount with fixed decimal places and comma-separated values. getDisplayAmountOnCurrency() adds the currency symbol to properly formatted amounts.
If the function getDisplayAmountOnCurrencyCode() is used instead of getDisplayAmountOnCurrency, it provides a promise which accepts only the currency symbol.
The country-currency-utils package offers promises to fetch country and currency data from a CDN, instead of carrying lists of the data into the codebase.
The package can help reduce the complexity of managing currencies in projects with clients in multiple countries.
Developers can find the package useful in making monetary amount displays more uniform across diverse client bases.