2020-10-08 20:39:51 +00:00
|
|
|
// License: LGPL-3.0-or-later
|
|
|
|
import {shouldPolyfill} from '@formatjs/intl-numberformat/should-polyfill';
|
|
|
|
|
|
|
|
import pluralRules from './pluralRules';
|
|
|
|
|
|
|
|
import type {Polyfilled} from './types';
|
|
|
|
|
2021-01-11 18:28:16 +00:00
|
|
|
type PolyfilledNumberFormat = Polyfilled<typeof Intl.NumberFormat>;
|
2020-10-08 20:39:51 +00:00
|
|
|
|
|
|
|
export default async function numberFormat(locales:string[]) :Promise<void> {
|
|
|
|
await pluralRules(locales);
|
|
|
|
if (shouldPolyfill()) {
|
|
|
|
// Load the polyfill 1st BEFORE loading data
|
|
|
|
await import('@formatjs/intl-numberformat/polyfill');
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((Intl.NumberFormat as PolyfilledNumberFormat).polyfilled) {
|
|
|
|
await Promise.all(
|
|
|
|
locales.map(l => import("@formatjs/intl-numberformat/locale-data/"+ l))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|