MCPcopy
hub / github.com/formatjs/formatjs / constructor

Method constructor

packages/intl-listformat/index.ts:191–271  ·  view source on GitHub ↗
(locales?: string | string[], options?: IntlListFormatOptions)

Source from the content-addressed store, hash-verified

189
190export default class ListFormat {
191 constructor(locales?: string | string[], options?: IntlListFormatOptions) {
192 // test262/test/intl402/ListFormat/constructor/constructor/newtarget-undefined.js
193 // Cannot use `new.target` bc of IE11 & TS transpiles it to something else
194 const newTarget =
195 this && this instanceof ListFormat ? this.constructor : void 0
196 if (!newTarget) {
197 throw new TypeError("Intl.ListFormat must be called with 'new'")
198 }
199 setInternalSlot(
200 ListFormat.__INTERNAL_SLOT_MAP__,
201 this,
202 'initializedListFormat',
203 true
204 )
205 const requestedLocales = CanonicalizeLocaleList(locales)
206 const opt: any = Object.create(null)
207 const opts = GetOptionsObject(options)
208 const matcher = GetOption(
209 opts,
210 'localeMatcher',
211 'string',
212 ['best fit', 'lookup'],
213 'best fit'
214 )
215 opt.localeMatcher = matcher
216 const {localeData} = ListFormat
217 const r = ResolveLocale(
218 ListFormat.availableLocales,
219 requestedLocales,
220 opt,
221 ListFormat.relevantExtensionKeys,
222 localeData,
223 ListFormat.getDefaultLocale
224 )
225 setInternalSlot(ListFormat.__INTERNAL_SLOT_MAP__, this, 'locale', r.locale)
226 const type: keyof ListPatternFieldsData = GetOption(
227 opts,
228 'type',
229 'string',
230 ['conjunction', 'disjunction', 'unit'],
231 'conjunction'
232 )
233 setInternalSlot(ListFormat.__INTERNAL_SLOT_MAP__, this, 'type', type)
234 const style: keyof ListPatternData = GetOption(
235 opts,
236 'style',
237 'string',
238 ['long', 'short', 'narrow'],
239 'long'
240 )
241 setInternalSlot(ListFormat.__INTERNAL_SLOT_MAP__, this, 'style', style)
242 const {dataLocale} = r
243 const dataLocaleData = localeData[dataLocale]
244 invariant(!!dataLocaleData, `Missing locale data for ${dataLocale}`)
245 const dataLocaleTypes = dataLocaleData[type]
246 const templates = dataLocaleTypes![style]!
247 setInternalSlot(
248 ListFormat.__INTERNAL_SLOT_MAP__,

Callers

nothing calls this directly

Calls 6

ResolveLocaleFunction · 0.90
setInternalSlotFunction · 0.85
GetOptionsObjectFunction · 0.85
GetOptionFunction · 0.85
CanonicalizeLocaleListFunction · 0.50
invariantFunction · 0.50

Tested by

no test coverage detected