currency.js
Replacing currency.js currency(1).format()
Vanilla JavaScript
const currency = (val, code = 'USD', locale = 'en-US') => ({
format: () => new Intl.NumberFormat(locale, {
style: 'currency',
currency: code
}).format(val)
});
// Usage:
// currency(2500.50).format(); // "$2,500.50"
Why Use This?
The `Intl` (Internationalization) object is a vastly underutilized native utility that provides robust and extremely complex capabilities for formatting dates, numbers, relative times, and currency seamlessly taking the user's localized browser language into account. No third-party bundle needed.