(data: string)
| 153 | } |
| 154 | |
| 155 | function parseJSONLString<T>(data: string): T[] { |
| 156 | const stripped = stripBOM(data) |
| 157 | const len = stripped.length |
| 158 | let start = 0 |
| 159 | |
| 160 | const results: T[] = [] |
| 161 | while (start < len) { |
| 162 | let end = stripped.indexOf('\n', start) |
| 163 | if (end === -1) end = len |
| 164 | |
| 165 | const line = stripped.substring(start, end).trim() |
| 166 | start = end + 1 |
| 167 | if (!line) continue |
| 168 | try { |
| 169 | results.push(JSON.parse(line) as T) |
| 170 | } catch { |
| 171 | // Skip malformed lines |
| 172 | } |
| 173 | } |
| 174 | return results |
| 175 | } |
| 176 | |
| 177 | /** |
| 178 | * Parses JSONL data from a string or Buffer, skipping malformed lines. |
no test coverage detected