Function
stringify
(
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 | |
| 10 | function 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 |
Tested by
no test coverage detected