MCPcopy Index your code
hub / github.com/angular/angular / _toJsonBody

Function _toJsonBody

packages/common/http/testing/src/request.ts:181–208  ·  view source on GitHub ↗

* Helper function to convert a response body to JSON data.

(
  body:
    | ArrayBuffer
    | Blob
    | boolean
    | string
    | number
    | Object
    | (boolean | string | number | Object | null)[],
  format: string = 'JSON',
)

Source from the content-addressed store, hash-verified

179 * Helper function to convert a response body to JSON data.
180 */
181function _toJsonBody(
182 body:
183 | ArrayBuffer
184 | Blob
185 | boolean
186 | string
187 | number
188 | Object
189 | (boolean | string | number | Object | null)[],
190 format: string = 'JSON',
191): Object | string | number | (Object | string | number)[] {
192 if (typeof ArrayBuffer !== 'undefined' && body instanceof ArrayBuffer) {
193 throw new Error(`Automatic conversion to ${format} is not supported for ArrayBuffers.`);
194 }
195 if (typeof Blob !== 'undefined' && body instanceof Blob) {
196 throw new Error(`Automatic conversion to ${format} is not supported for Blobs.`);
197 }
198 if (
199 typeof body === 'string' ||
200 typeof body === 'number' ||
201 typeof body === 'object' ||
202 typeof body === 'boolean' ||
203 Array.isArray(body)
204 ) {
205 return body;
206 }
207 throw new Error(`Automatic conversion to ${format} is not supported for response type.`);
208}
209
210/**
211 * Helper function to convert a response body to a string.

Callers 2

_toTextBodyFunction · 0.85
_maybeConvertBodyFunction · 0.85

Calls 1

isArrayMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…