( value: unknown, componentName?: string, pluginName?: string, )
| 302 | * @param pluginName - The plugin name, if this came from a plugin |
| 303 | */ |
| 304 | export function coerceDescriptionToString( |
| 305 | value: unknown, |
| 306 | componentName?: string, |
| 307 | pluginName?: string, |
| 308 | ): string | null { |
| 309 | if (value == null) { |
| 310 | return null |
| 311 | } |
| 312 | if (typeof value === 'string') { |
| 313 | return value.trim() || null |
| 314 | } |
| 315 | if (typeof value === 'number' || typeof value === 'boolean') { |
| 316 | return String(value) |
| 317 | } |
| 318 | // Non-scalar descriptions (arrays, objects) are invalid — log and omit |
| 319 | const source = pluginName |
| 320 | ? `${pluginName}:${componentName}` |
| 321 | : (componentName ?? 'unknown') |
| 322 | logForDebugging(`Description invalid for ${source} - omitting`, { |
| 323 | level: 'warn', |
| 324 | }) |
| 325 | return null |
| 326 | } |
| 327 | |
| 328 | /** |
| 329 | * Parse a boolean frontmatter value. |
no test coverage detected