* 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',
)
| 179 | * Helper function to convert a response body to JSON data. |
| 180 | */ |
| 181 | function _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. |
no test coverage detected
searching dependent graphs…