UNPKG

@naturalcycles/js-lib

Version:

Standard library for universal (browser + Node.js) javascript

68 lines (67 loc) 1.99 kB
import { __decorate } from "tslib"; import { _Memo } from '../decorators/memo.decorator.js'; // oxlint-disable no-restricted-globals /** * Returns cached Intl.* formatters, because they are known to be * very slow to create. * * See https://github.com/poppinss/intl-formatter * * Methods accept non-optional arguments consciously, * to be able to cache them better. Just pass {} for options. */ class MemoizedIntl { /** * Returns the IANA timezone e.g `Europe/Stockholm`. * https://en.wikipedia.org/wiki/List_of_tz_database_time_zones */ getTimezone() { return Intl.DateTimeFormat().resolvedOptions().timeZone; } DateTimeFormat(locales, options) { return new Intl.DateTimeFormat(locales, options); } RelativeTimeFormat(locales, options) { return new Intl.RelativeTimeFormat(locales, options); } NumberFormat(locales, options) { return new Intl.NumberFormat(locales, options); } Collator(locales, options) { return new Intl.Collator(locales, options); } PluralRules(locales, options) { return new Intl.PluralRules(locales, options); } ListFormat(locales, options) { return new Intl.ListFormat(locales, options); } DisplayNames(locales, options) { return new Intl.DisplayNames(locales, options); } } __decorate([ _Memo() ], MemoizedIntl.prototype, "getTimezone", null); __decorate([ _Memo() ], MemoizedIntl.prototype, "DateTimeFormat", null); __decorate([ _Memo() ], MemoizedIntl.prototype, "RelativeTimeFormat", null); __decorate([ _Memo() ], MemoizedIntl.prototype, "NumberFormat", null); __decorate([ _Memo() ], MemoizedIntl.prototype, "Collator", null); __decorate([ _Memo() ], MemoizedIntl.prototype, "PluralRules", null); __decorate([ _Memo() ], MemoizedIntl.prototype, "ListFormat", null); __decorate([ _Memo() ], MemoizedIntl.prototype, "DisplayNames", null); export const Intl2 = new MemoizedIntl();