(content: string)
| 296 | * objects get one-line JSON. Returns null if content doesn't qualify. |
| 297 | */ |
| 298 | export function tryFlattenJson(content: string): [string, string][] | null { |
| 299 | const entries = parseJsonEntries(content, { |
| 300 | maxChars: MAX_FLAT_JSON_CHARS, |
| 301 | maxKeys: MAX_FLAT_JSON_KEYS |
| 302 | }); |
| 303 | if (entries === null) return null; |
| 304 | const result: [string, string][] = []; |
| 305 | for (const [key, value] of entries) { |
| 306 | if (typeof value === 'string') { |
| 307 | result.push([key, value]); |
| 308 | } else if (value === null || typeof value === 'number' || typeof value === 'boolean') { |
| 309 | result.push([key, String(value)]); |
| 310 | } else if (typeof value === 'object') { |
| 311 | const compact = jsonStringify(value); |
| 312 | if (compact.length > 120) return null; |
| 313 | result.push([key, compact]); |
| 314 | } else { |
| 315 | return null; |
| 316 | } |
| 317 | } |
| 318 | return result; |
| 319 | } |
| 320 | |
| 321 | /** |
| 322 | * If content is a JSON object where one key holds a dominant string payload |
no test coverage detected