attranslate
Version:
Semi-automated Text Translator for Websites and Apps
39 lines (38 loc) • 1.13 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseYaml = void 0;
const yaml_1 = require("yaml");
const parse_utils_1 = require("../common/parse-utils");
const managed_utf8_1 = require("../common/managed-utf8");
function parseYaml(args) {
var _a;
const ymlString = (0, managed_utf8_1.readManagedUtf8)(args.path);
if (!ymlString) {
return null;
}
const options = {
keepCstNodes: true,
keepNodeTypes: true,
keepUndefined: true,
prettyErrors: true,
};
let document;
try {
document = (0, yaml_1.parseDocument)(ymlString, options);
}
catch (e) {
console.error(e);
(0, parse_utils_1.logParseError)("YAML parsing error", args);
}
if ((_a = document.errors) === null || _a === void 0 ? void 0 : _a.length) {
const errorMsg = document.errors
.map((e) => {
e.makePretty();
return e.message;
})
.join("\n");
(0, parse_utils_1.logParseError)(errorMsg, args);
}
return document;
}
exports.parseYaml = parseYaml;