(label)
| 269 | * @returns {Encoding | null} |
| 270 | */ |
| 271 | export function getEncodingFromLabel(label) { |
| 272 | const formattedLabel = trimAsciiWhitespace(label.toLowerCase()); |
| 273 | |
| 274 | let canonicalLabel = encodings.get(formattedLabel); |
| 275 | |
| 276 | // Lookup an internal mapping using the canonical name, if found, or |
| 277 | // the formatted label otherwise. |
| 278 | // |
| 279 | // x-mac-ukrainian > x-mac-cyrillic > MacCyrillic |
| 280 | // (canonical label) (internal label) |
| 281 | // |
| 282 | // big5-hkscs > undefined > big5-hkscs |
| 283 | // (canonical label) (internal label) |
| 284 | // |
| 285 | let internalLabel = internalEncodings.get( |
| 286 | canonicalLabel ?? formattedLabel |
| 287 | ); |
| 288 | |
| 289 | // If both the canonical label and the internal encoding |
| 290 | // are not found, this encoding is unsupported. |
| 291 | if (!canonicalLabel && !internalLabel) |
| 292 | return null; |
| 293 | |
| 294 | if (internalLabel) { |
| 295 | return { |
| 296 | label: canonicalLabel ?? formattedLabel, |
| 297 | internalLabel, |
| 298 | }; |
| 299 | } |
| 300 | |
| 301 | return { |
| 302 | label: canonicalLabel, |
| 303 | internalLabel: canonicalLabel, |
| 304 | }; |
| 305 | } |
no test coverage detected