"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var common_1 = require("../common");
function parseJson(input) {
    if (!input) {
        return {};
    }
    try {
        var data = JSON.parse(input);
        return { data: data, error: undefined };
    }
    catch (err) {
        var message = "Failed to parse JSON. " + err.message;
        return { data: undefined, error: { message: message } };
    }
}
exports.parseJson = parseJson;
function parseYaml(input) {
    if (!input) {
        return {};
    }
    try {
        input = input.replace(/\t/g, '  ');
        var data = common_1.yaml.safeLoad(input);
        return { data: data, error: undefined };
    }
    catch (err) {
        var message = "Failed to parse YAML. " + err.message;
        return { data: undefined, error: { message: message } };
    }
}
exports.parseYaml = parseYaml;
function parseYamlFile(path) {
    return tslib_1.__awaiter(this, void 0, void 0, function () {
        var file;
        return tslib_1.__generator(this, function (_a) {
            switch (_a.label) {
                case 0: return [4, common_1.fs.readFile(path)];
                case 1:
                    file = _a.sent();
                    return [2, parseYaml(file.toString())];
            }
        });
    });
}
exports.parseYamlFile = parseYamlFile;
//# sourceMappingURL=util.parse.js.map