(buffer: Buffer)
| 38 | * Parse YAML from buffer |
| 39 | */ |
| 40 | export async function parseYAMLBuffer(buffer: Buffer): Promise<FileParseResult> { |
| 41 | const content = buffer.toString('utf-8') |
| 42 | |
| 43 | try { |
| 44 | const yamlData = yaml.load(content) |
| 45 | const jsonContent = JSON.stringify(yamlData, null, 2) |
| 46 | |
| 47 | const metadata = { |
| 48 | type: 'yaml', |
| 49 | isArray: Array.isArray(yamlData), |
| 50 | keys: Array.isArray(yamlData) ? [] : Object.keys(yamlData || {}), |
| 51 | itemCount: Array.isArray(yamlData) ? yamlData.length : undefined, |
| 52 | depth: getYamlDepth(yamlData), |
| 53 | } |
| 54 | |
| 55 | return { |
| 56 | content: jsonContent, |
| 57 | metadata, |
| 58 | } |
| 59 | } catch (error) { |
| 60 | throw new Error(`Invalid YAML: ${getErrorMessage(error, 'Unknown error')}`) |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Calculate the depth of a YAML/JSON object |
nothing calls this directly
no test coverage detected