Money is a Currency Localizer
// First Require Money
let Money = require('@whym/money');
// To do a simple Localization just call `localize`
let str = Money.localize(10.99, 'fr_FR'); // 10,99€
// You can set the Default Locale with
Money.setDefaultLocale('en_US');
// Now if you call `localize` it will fallback to default
let str = Money.localize(10.99); // $10.99
// Want a different format? Uses http://numeraljs.com/
let money = (new Money('en_US')).format('$0,0[.]00');
let str = money.toString(10.00); // $10
To make things easier in requests there is a middle
app.use(function(req, res, next) {
Money.setLocale(req, 'en_GB');
});;
// From there you can just do:
let str = req.money(10.99); // £10.99
// Set locales to JSON object at this path
Money.loadLocales(path);
// Set Locales to JSON object
Money.useLocales(locales);