"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.dump = exports.parseSingleYaml = exports.parseYaml = void 0;
const js_yaml_1 = require("js-yaml");
const regex_1 = require("./regex");
function parseYaml(content, iterator, options) {
    const massagedContent = massageContent(content, options);
    const rawDocuments = (0, js_yaml_1.loadAll)(massagedContent, iterator, options);
    const schema = options?.customSchema;
    if (!schema) {
        return rawDocuments;
    }
    const parsed = [];
    for (const element of rawDocuments) {
        const singleParsed = schema.parse(element);
        parsed.push(singleParsed);
    }
    return parsed;
}
exports.parseYaml = parseYaml;
function parseSingleYaml(content, options) {
    const massagedContent = massageContent(content, options);
    const rawDocument = (0, js_yaml_1.load)(massagedContent, options);
    const schema = options?.customSchema;
    if (!schema) {
        return rawDocument;
    }
    return schema.parse(rawDocument);
}
exports.parseSingleYaml = parseSingleYaml;
function dump(obj, opts) {
    return (0, js_yaml_1.dump)(obj, opts);
}
exports.dump = dump;
function massageContent(content, options) {
    if (options?.removeTemplates) {
        return content
            .replace((0, regex_1.regEx)(/{{`.+?`}}/gs), '')
            .replace((0, regex_1.regEx)(/{{.+?}}/g), '')
            .replace((0, regex_1.regEx)(/{%`.+?`%}/gs), '')
            .replace((0, regex_1.regEx)(/{%.+?%}/g), '');
    }
    return content;
}
//# sourceMappingURL=yaml.js.map