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

Function getTextDecoder

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

517 * falling back to the default (`utf-8`) if no valid charset is specified or supported.
518 */
519function getTextDecoder(contentType: string): TextDecoder {
520 const match = contentType.match(CHARSET_REGEX);
521 if (match !== null) {
522 try {
523 return new TextDecoder(match[1]);
524 } catch {
525 // Catching `RangeError` thrown by `new TextDecoder(...)` when the encoding label is invalid or
526 // unsupported. There is no synchronous inspection API on `TextDecoder` to verify whether an
527 // encoding is supported without executing the constructor, so catching the error is required
528 // before falling back to default UTF-8.
529 }
530 }
531 return new TextDecoder();
532}

Callers 2

doRequestMethod · 0.85
parseBodyMethod · 0.85

Calls 1

matchMethod · 0.45

Tested by

no test coverage detected