(text: string)
| 98 | } |
| 99 | |
| 100 | function extractJsonPayload(text: string): |
| 101 | | { |
| 102 | jsonText: string |
| 103 | wrap: (jsonText: string) => string |
| 104 | pretty: boolean |
| 105 | } |
| 106 | | null { |
| 107 | const trimmed = text.trim() |
| 108 | const fenced = trimmed.match(/^```(?:json)?\s*\n([\s\S]*?)\n```$/) |
| 109 | if (fenced?.[1]) { |
| 110 | return { |
| 111 | jsonText: fenced[1], |
| 112 | wrap: jsonText => `\`\`\`json\n${jsonText}\n\`\`\``, |
| 113 | pretty: true, |
| 114 | } |
| 115 | } |
| 116 | if ( |
| 117 | (trimmed.startsWith('{') && trimmed.endsWith('}')) || |
| 118 | (trimmed.startsWith('[') && trimmed.endsWith(']')) |
| 119 | ) { |
| 120 | return { |
| 121 | jsonText: trimmed, |
| 122 | wrap: jsonText => jsonText, |
| 123 | pretty: trimmed.includes('\n'), |
| 124 | } |
| 125 | } |
| 126 | return null |
| 127 | } |
| 128 | |
| 129 | function sourceMap( |
| 130 | sources: readonly WebFetchSourceMetadata[], |
no outgoing calls
no test coverage detected