lbry-desktop/ui/util/intlNumberFormat.js

15 lines
495 B
JavaScript
Raw Permalink Normal View History

2022-05-06 15:31:36 +02:00
// @flow
const formatterCache = {};
// Creating multiple Intl.NumberFormat instances can
// be expensive, that's why we perform a very simple
// cache.
// See https://github.com/formatjs/formatjs/issues/27#issuecomment-61148808
export function getFormatter(language?: string, options: any) {
const key = `${language || ''}:${JSON.stringify(options || {})}`;
if (!formatterCache[key]) {
formatterCache[key] = new Intl.NumberFormat(language, options);
}
return formatterCache[key];
}