Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
formatCurrency: (valueToFormat = 0, options = {}) => {
const locale = options.locale || I18n.locale || 'en';
const format = I18nHelper.format(locale);
let { precision } = options;
const unit = options.unit || format.unit;
const structure = options.format || format.format;
// Checking explicitly as 0 is a valid precision
if (typeof precision === 'undefined' || precision === null) {
precision = 2;
}
return I18n.toCurrency(valueToFormat, {
precision,
delimiter: format.delimiter,
separator: format.separator,
unit,
format: structure
});
},