@base-ui/react
Version:
Base UI is a library of headless ('unstyled') React components and low-level hooks. You gain complete control over your app's CSS and accessibility features.
21 lines • 615 B
JavaScript
import { stringifyLocale } from "./stringifyLocale.mjs";
export const cache = new Map();
export function getFormatter(locale, options) {
const optionsString = JSON.stringify({
locale: stringifyLocale(locale),
options
});
const cachedFormatter = cache.get(optionsString);
if (cachedFormatter) {
return cachedFormatter;
}
const formatter = new Intl.NumberFormat(locale, options);
cache.set(optionsString, formatter);
return formatter;
}
export function formatNumber(value, locale, options) {
if (value == null) {
return '';
}
return getFormatter(locale, options).format(value);
}