MCPcopy
hub / github.com/formatjs/formatjs / emitUnicodeLocaleId

Function emitUnicodeLocaleId

packages/intl-getcanonicallocales/emitter.ts:15–42  ·  view source on GitHub ↗
({
  lang,
  extensions,
}: UnicodeLocaleId)

Source from the content-addressed store, hash-verified

13}
14
15export function emitUnicodeLocaleId({
16 lang,
17 extensions,
18}: UnicodeLocaleId): string {
19 const chunks = [emitUnicodeLanguageId(lang)]
20 for (const ext of extensions) {
21 chunks.push(ext.type)
22 switch (ext.type) {
23 case 'u':
24 chunks.push(
25 ...ext.attributes,
26 ...ext.keywords.reduce((all: string[], kv) => all.concat(kv), [])
27 )
28 break
29 case 't':
30 chunks.push(
31 emitUnicodeLanguageId(ext.lang),
32 ...ext.fields.reduce((all: string[], kv) => all.concat(kv), [])
33 )
34 break
35 default:
36 chunks.push(ext.value)
37 break
38 }
39 }
40
41 return chunks.filter(Boolean).join('-')
42}

Callers 5

applyOptionsToTagFunction · 0.90
addLikelySubtagsFunction · 0.90
removeLikelySubtagsFunction · 0.90
CanonicalizeLocaleListFunction · 0.85

Calls 1

emitUnicodeLanguageIdFunction · 0.85

Tested by

no test coverage detected