ec-sri-invoice-signer
Version:
Ecuador SRI invoice signer.
44 lines (43 loc) • 1.37 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseXml = exports.buildXml = void 0;
const fast_xml_parser_1 = require("fast-xml-parser");
const errors_1 = require("./errors");
const utils_1 = require("../canonicalization/utils");
const parseXml = (xml) => {
const parserOptions = {
commentPropName: '#comment',
ignoreAttributes: false,
ignoreDeclaration: true,
parseTagValue: false,
preserveOrder: true,
trimValues: false,
processEntities: false,
ignorePiTags: true,
attributeValueProcessor: (name, value) => {
return (0, utils_1.processAttributeValue)(value);
},
tagValueProcessor: (name, value) => {
return (0, utils_1.processTagValue)(value);
}
};
try {
const parser = new fast_xml_parser_1.XMLParser(parserOptions);
return parser.parse(xml);
}
catch (err) {
throw new errors_1.XmlFormatError();
}
};
exports.parseXml = parseXml;
const buildXml = (data) => {
const builderOptions = {
ignoreAttributes: false,
preserveOrder: true,
processEntities: false,
suppressEmptyNode: false
};
const builder = new fast_xml_parser_1.XMLBuilder(builderOptions);
return builder.build(data);
};
exports.buildXml = buildXml;