MCPcopy Create free account
hub / github.com/angular/angular / getTextDecoder

Function getTextDecoder

packages/common/http/src/fetch.ts:484–497  ·  view source on GitHub ↗

* Creates a `TextDecoder` instance using the charset extracted from the `Content-Type` header, * falling back to the default (`utf-8`) if no valid charset is specified or supported.

(contentType: string)

Source from the content-addressed store, hash-verified

482 * falling back to the default (`utf-8`) if no valid charset is specified or supported.
483 */
484function getTextDecoder(contentType: string): TextDecoder {
485 const match = contentType.match(CHARSET_REGEX);
486 if (match !== null) {
487 try {
488 return new TextDecoder(match[1]);
489 } catch {
490 // Catching `RangeError` thrown by `new TextDecoder(...)` when the encoding label is invalid or
491 // unsupported. There is no synchronous inspection API on `TextDecoder` to verify whether an
492 // encoding is supported without executing the constructor, so catching the error is required
493 // before falling back to default UTF-8.
494 }
495 }
496 return new TextDecoder();
497}

Callers 2

doRequestMethod · 0.85
parseBodyMethod · 0.85

Calls 1

matchMethod · 0.45

Tested by

no test coverage detected