UNPKG

@formatjs/intl-relativetimeformat

Version:

Formats JavaScript dates to relative time strings.

17 lines (16 loc) 537 B
import RelativeTimeFormat from "./index.js"; import { shouldPolyfill } from "./should-polyfill.js"; if (shouldPolyfill()) { Object.defineProperty(Intl, "RelativeTimeFormat", { value: RelativeTimeFormat, writable: true, enumerable: false, configurable: true }); // Drain any locale data that was buffered before polyfill loaded const buf = globalThis.__FORMATJS_RELATIVETIMEFORMAT_DATA__; if (buf) { for (const d of buf) RelativeTimeFormat.__addLocaleData(d); delete globalThis.__FORMATJS_RELATIVETIMEFORMAT_DATA__; } }