MCPcopy Index your code
hub / github.com/formatjs/formatjs / createFormatters

Function createFormatters

packages/intl/utils.ts:114–170  ·  view source on GitHub ↗
(
  cache: IntlCache = createIntlCache()
)

Source from the content-addressed store, hash-verified

112 * @param cache explicit cache to prevent leaking memory
113 */
114export function createFormatters(
115 cache: IntlCache = createIntlCache()
116): Formatters {
117 const RelativeTimeFormat = (Intl as any).RelativeTimeFormat
118 const ListFormat = (Intl as any).ListFormat
119 const DisplayNames = (Intl as any).DisplayNames
120 const getDateTimeFormat = memoize(
121 (...args) => new Intl.DateTimeFormat(...args),
122 {
123 cache: createFastMemoizeCache(cache.dateTime),
124 strategy: strategies.variadic,
125 }
126 )
127 const getNumberFormat = memoize((...args) => new Intl.NumberFormat(...args), {
128 cache: createFastMemoizeCache(cache.number),
129 strategy: strategies.variadic,
130 })
131 const getPluralRules = memoize((...args) => new Intl.PluralRules(...args), {
132 cache: createFastMemoizeCache(cache.pluralRules),
133 strategy: strategies.variadic,
134 })
135 return {
136 getDateTimeFormat,
137 getNumberFormat,
138 getMessageFormat: memoize(
139 (message, locales, overrideFormats, opts) =>
140 new IntlMessageFormat(message, locales, overrideFormats, {
141 formatters: {
142 getNumberFormat,
143 getDateTimeFormat,
144 getPluralRules,
145 },
146 ...opts,
147 }),
148 {
149 cache: createFastMemoizeCache(cache.message),
150 strategy: strategies.variadic,
151 }
152 ),
153 getRelativeTimeFormat: memoize(
154 (...args) => new RelativeTimeFormat(...args),
155 {
156 cache: createFastMemoizeCache(cache.relativeTime),
157 strategy: strategies.variadic,
158 }
159 ),
160 getPluralRules,
161 getListFormat: memoize((...args) => new ListFormat(...args), {
162 cache: createFastMemoizeCache(cache.list),
163 strategy: strategies.variadic,
164 }),
165 getDisplayNames: memoize((...args) => new DisplayNames(...args), {
166 cache: createFastMemoizeCache(cache.displayNames),
167 strategy: strategies.variadic,
168 }),
169 }
170}
171

Callers 1

createIntlFunction · 0.85

Calls 3

memoizeFunction · 0.90
createIntlCacheFunction · 0.85
createFastMemoizeCacheFunction · 0.70

Tested by

no test coverage detected