(value: string | Record<string, unknown>)
| 11 | * it is returned as-is. If it is a plain string, it is wrapped in a single-paragraph ADF doc. |
| 12 | */ |
| 13 | export function toAdf(value: string | Record<string, unknown>): Record<string, unknown> { |
| 14 | if (typeof value === 'object') { |
| 15 | if (value.type === 'doc') { |
| 16 | return value |
| 17 | } |
| 18 | if (value.type && Array.isArray(value.content)) { |
| 19 | return { type: 'doc', version: 1, content: [value] } |
| 20 | } |
| 21 | } |
| 22 | if (typeof value === 'string') { |
| 23 | try { |
| 24 | const parsed = JSON.parse(value) |
| 25 | if (typeof parsed === 'object' && parsed !== null && parsed.type === 'doc') { |
| 26 | return parsed |
| 27 | } |
| 28 | if ( |
| 29 | typeof parsed === 'object' && |
| 30 | parsed !== null && |
| 31 | parsed.type && |
| 32 | Array.isArray(parsed.content) |
| 33 | ) { |
| 34 | return { type: 'doc', version: 1, content: [parsed] } |
| 35 | } |
| 36 | } catch { |
| 37 | // Not JSON — treat as plain text below |
| 38 | } |
| 39 | } |
| 40 | return { |
| 41 | type: 'doc', |
| 42 | version: 1, |
| 43 | content: [ |
| 44 | { |
| 45 | type: 'paragraph', |
| 46 | content: [ |
| 47 | { type: 'text', text: typeof value === 'string' ? value : JSON.stringify(value) }, |
| 48 | ], |
| 49 | }, |
| 50 | ], |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Extracts plain text from Atlassian Document Format (ADF) content. |
no test coverage detected