(res: Response)
| 7 | * @param res Response |
| 8 | */ |
| 9 | export const json = <Response extends Res = Res>(res: Response) => (body: any, ...args: any[]): Response => { |
| 10 | res.setHeader('Content-Type', 'application/json') |
| 11 | if (typeof body === 'object' && body != null) res.end(JSON.stringify(body, null, 2), ...args) |
| 12 | else if (typeof body === 'string') res.end(body, ...args) |
| 13 | else if (body == null) { |
| 14 | res.removeHeader('Content-Length') |
| 15 | res.removeHeader('Transfer-Encoding') |
| 16 | res.end(null, ...args) |
| 17 | } |
| 18 | |
| 19 | return res |
| 20 | } |
no outgoing calls
no test coverage detected