MCPcopy
hub / github.com/tinyhttp/tinyhttp / json

Function json

packages/send/src/json.ts:9–20  ·  view source on GitHub ↗
(res: Response)

Source from the content-addressed store, hash-verified

7 * @param res Response
8 */
9export 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}

Callers 7

sendFunction · 0.90
send.test.tsFile · 0.90
rollup.config.jsFile · 0.85
extendMiddlewareFunction · 0.85
index.jsFile · 0.85
index.jsFile · 0.85
index.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected