(value: unknown)
| 4 | // plain objects, arrays, and anything with a `toJSON` method — but not typed |
| 5 | // arrays/buffers, FormData, or URLSearchParams, which are sent as-is. |
| 6 | export function isJSONSerializable(value: unknown): boolean { |
| 7 | if (value === undefined) |
| 8 | return false |
| 9 | if (value === null) |
| 10 | return true |
| 11 | const t = typeof value |
| 12 | if (t === 'string' || t === 'number' || t === 'boolean') |
| 13 | return true |
| 14 | if (t !== 'object') |
| 15 | return false |
| 16 | if (Array.isArray(value)) |
| 17 | return true |
| 18 | const obj = value as { buffer?: unknown, constructor?: { name?: string }, toJSON?: unknown } |
| 19 | if (obj.buffer !== undefined) |
| 20 | return false |
| 21 | if (value instanceof FormData || value instanceof URLSearchParams) |
| 22 | return false |
| 23 | if (obj.constructor?.name === 'Object') |
| 24 | return true |
| 25 | return typeof obj.toJSON === 'function' |
| 26 | } |
| 27 | |
| 28 | export type BuildBodyInput = { |
| 29 | readonly json?: unknown |
no outgoing calls
no test coverage detected