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

Method constructor

packages/intl-displaynames/index.ts:45–149  ·  view source on GitHub ↗
(
    locales: string | string[] | undefined,
    options: DisplayNamesOptions
  )

Source from the content-addressed store, hash-verified

43
44export class DisplayNames {
45 constructor(
46 locales: string | string[] | undefined,
47 options: DisplayNamesOptions
48 ) {
49 if (new.target === undefined) {
50 throw TypeError(`Constructor Intl.DisplayNames requires 'new'`)
51 }
52 const requestedLocales = CanonicalizeLocaleList(locales)
53 options = GetOptionsObject(options)
54
55 const opt = Object.create(null)
56 const {localeData} = DisplayNames
57 const matcher = GetOption(
58 options,
59 'localeMatcher',
60 'string',
61 ['lookup', 'best fit'],
62 'best fit'
63 )
64 opt.localeMatcher = matcher
65
66 const r = ResolveLocale(
67 Array.from(DisplayNames.availableLocales),
68 requestedLocales,
69 opt,
70 [], // there is no relevantExtensionKeys
71 DisplayNames.localeData,
72 DisplayNames.getDefaultLocale
73 )
74
75 const style = GetOption(
76 options,
77 'style',
78 'string',
79 ['narrow', 'short', 'long'],
80 'long'
81 )
82 setSlot(this, 'style', style)
83
84 const type = GetOption(
85 options,
86 'type',
87 'string',
88 ['language', 'region', 'script', 'currency', 'calendar', 'dateTimeField'],
89 undefined
90 )
91 if (type === undefined) {
92 throw TypeError(`Intl.DisplayNames constructor requires "type" option`)
93 }
94
95 setSlot(this, 'type', type)
96
97 const fallback = GetOption(
98 options,
99 'fallback',
100 'string',
101 ['code', 'none'],
102 'code'

Callers

nothing calls this directly

Calls 6

ResolveLocaleFunction · 0.90
GetOptionsObjectFunction · 0.85
GetOptionFunction · 0.85
setSlotFunction · 0.70
CanonicalizeLocaleListFunction · 0.50
invariantFunction · 0.50

Tested by

no test coverage detected