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

Function getTextDecoder

packages/common/http/src/fetch.ts:483–496  ·  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

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

Callers 2

doRequestMethod · 0.85
parseBodyMethod · 0.85

Calls 1

matchMethod · 0.45

Tested by

no test coverage detected