// Copyright (c) 2026 Modelware. All rights reserved.

import { parse } from 'yaml';

export function parseYamlMap(input: string): Record<string, unknown> | undefined {
    try {
        const parsed = parse(input);
        return isPlainObject(parsed) ? parsed : undefined;
    } catch {
        return undefined;
    }
}

function isPlainObject(value: unknown): value is Record<string, unknown> {
    return typeof value === 'object' && value !== null && !Array.isArray(value);
}

