import { NumberFormat } from "./src/core.js";
import { toLocaleString as _toLocaleString } from "./src/to_locale_string.js";
import { defineProperty } from "@formatjs/ecma402-abstract";
import { shouldPolyfill } from "./should-polyfill.js";
if (shouldPolyfill()) {
	defineProperty(Intl, "NumberFormat", { value: NumberFormat });
	defineProperty(Number.prototype, "toLocaleString", { value: function toLocaleString(locales, options) {
		return _toLocaleString(this, locales, options);
	} });
	// Drain any locale data that was buffered before polyfill loaded
	const buf = globalThis.__FORMATJS_NUMBERFORMAT_DATA__;
	if (buf) {
		for (const d of buf) NumberFormat.__addLocaleData(d);
		delete globalThis.__FORMATJS_NUMBERFORMAT_DATA__;
	}
}
