(filePath: string)
| 6 | * Parse YAML files |
| 7 | */ |
| 8 | export async function parseYAML(filePath: string): Promise<FileParseResult> { |
| 9 | const fs = await import('fs/promises') |
| 10 | const content = await fs.readFile(filePath, 'utf-8') |
| 11 | |
| 12 | try { |
| 13 | // Parse YAML to validate and extract structure |
| 14 | const yamlData = yaml.load(content) |
| 15 | |
| 16 | // Convert to JSON for consistent processing |
| 17 | const jsonContent = JSON.stringify(yamlData, null, 2) |
| 18 | |
| 19 | // Extract metadata about the YAML structure |
| 20 | const metadata = { |
| 21 | type: 'yaml', |
| 22 | isArray: Array.isArray(yamlData), |
| 23 | keys: Array.isArray(yamlData) ? [] : Object.keys(yamlData || {}), |
| 24 | itemCount: Array.isArray(yamlData) ? yamlData.length : undefined, |
| 25 | depth: getYamlDepth(yamlData), |
| 26 | } |
| 27 | |
| 28 | return { |
| 29 | content: jsonContent, |
| 30 | metadata, |
| 31 | } |
| 32 | } catch (error) { |
| 33 | throw new Error(`Invalid YAML: ${getErrorMessage(error, 'Unknown error')}`) |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Parse YAML from buffer |
nothing calls this directly
no test coverage detected