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

Function parseUnicodeExtension

packages/intl-getcanonicallocales/parser.ts:96–126  ·  view source on GitHub ↗
(chunks: string[])

Source from the content-addressed store, hash-verified

94}
95
96function parseUnicodeExtension(chunks: string[]): UnicodeExtension {
97 const keywords = []
98 let keyword
99 while (chunks.length && (keyword = parseKeyword(chunks))) {
100 keywords.push(keyword)
101 }
102 if (keywords.length) {
103 return {
104 type: 'u',
105 keywords,
106 attributes: [],
107 }
108 }
109 // Mix of attributes & keywords
110 // Check for attributes first
111 const attributes = []
112 while (chunks.length && ALPHANUM_3_8.test(chunks[0])) {
113 attributes.push(chunks.shift()!)
114 }
115 while (chunks.length && (keyword = parseKeyword(chunks))) {
116 keywords.push(keyword)
117 }
118 if (keywords.length || attributes.length) {
119 return {
120 type: 'u',
121 attributes,
122 keywords,
123 }
124 }
125 throw new RangeError('Malformed unicode_extension')
126}
127
128function parseKeyword(chunks: string[]): KV | undefined {
129 let key

Callers 1

parseExtensionsFunction · 0.85

Calls 1

parseKeywordFunction · 0.85

Tested by

no test coverage detected