MCPcopy Index your code
hub / github.com/tinyhttp/tinyhttp / stringify

Function stringify

packages/jsonp/src/index.ts:10–34  ·  view source on GitHub ↗
(
  value: unknown,
  replacer: (this: any, key: string, value: any) => any,
  spaces: string | number,
  escape: boolean
)

Source from the content-addressed store, hash-verified

8}>
9
10function stringify(
11 value: unknown,
12 replacer: (this: any, key: string, value: any) => any,
13 spaces: string | number,
14 escape: boolean
15) {
16 let json = replacer || spaces ? JSON.stringify(value, replacer, spaces) : JSON.stringify(value)
17
18 if (escape) {
19 json = json.replace(/[<>&]/g, (c) => {
20 switch (c.charCodeAt(0)) {
21 case 0x3c:
22 return '\\u003c'
23 case 0x3e:
24 return '\\u003e'
25 case 0x26:
26 return '\\u0026'
27 default:
28 return c
29 }
30 })
31 }
32
33 return json
34}
35
36/**
37 * Send JSON response with JSONP callback support

Callers 1

jsonpFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected