(chunks: string[])
| 195 | return '' |
| 196 | } |
| 197 | function parseExtensions(chunks: string[]): Omit<UnicodeLocaleId, 'lang'> { |
| 198 | if (!chunks.length) { |
| 199 | return {extensions: []} |
| 200 | } |
| 201 | const extensions: UnicodeLocaleId['extensions'] = [] |
| 202 | let unicodeExtension |
| 203 | let transformedExtension |
| 204 | let puExtension |
| 205 | const otherExtensionMap: Record<string, OtherExtension> = {} |
| 206 | do { |
| 207 | const type = chunks.shift()! |
| 208 | switch (type) { |
| 209 | case 'u': |
| 210 | case 'U': |
| 211 | if (unicodeExtension) { |
| 212 | throw new RangeError('There can only be 1 -u- extension') |
| 213 | } |
| 214 | unicodeExtension = parseUnicodeExtension(chunks) |
| 215 | extensions.push(unicodeExtension) |
| 216 | break |
| 217 | case 't': |
| 218 | case 'T': |
| 219 | if (transformedExtension) { |
| 220 | throw new RangeError('There can only be 1 -t- extension') |
| 221 | } |
| 222 | transformedExtension = parseTransformedExtension(chunks) |
| 223 | extensions.push(transformedExtension) |
| 224 | break |
| 225 | case 'x': |
| 226 | case 'X': |
| 227 | if (puExtension) { |
| 228 | throw new RangeError('There can only be 1 -x- extension') |
| 229 | } |
| 230 | puExtension = parsePuExtension(chunks) |
| 231 | extensions.push(puExtension) |
| 232 | break |
| 233 | default: |
| 234 | if (!OTHER_EXTENSION_TYPE.test(type)) { |
| 235 | throw new RangeError('Malformed extension type') |
| 236 | } |
| 237 | if (type in otherExtensionMap) { |
| 238 | throw new RangeError(`There can only be 1 -${type}- extension`) |
| 239 | } |
| 240 | const extension: OtherExtension = { |
| 241 | type: type as 'a', |
| 242 | value: parseOtherExtensionValue(chunks), |
| 243 | } |
| 244 | otherExtensionMap[extension.type] = extension |
| 245 | extensions.push(extension) |
| 246 | break |
| 247 | } |
| 248 | } while (chunks.length) |
| 249 | return {extensions} |
| 250 | } |
| 251 | |
| 252 | export function parseUnicodeLocaleId(locale: string): UnicodeLocaleId { |
| 253 | const chunks = locale.split(SEPARATOR) |
no test coverage detected