partial-xml-stream-parser
Version:
A lenient XML stream parser for Node.js and browsers that can handle incomplete or malformed XML data, with depth control, CDATA support for XML serialization and round-trip parsing, wildcard pattern support for stopNodes, and CDATA handling within stopNo
25 lines • 971 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.addValueToObject = addValueToObject;
function addValueToObject(obj, key, value, customOptions) {
const effectiveTextNodeName = customOptions.textNodeName;
const alwaysCreate = customOptions.alwaysCreateTextNode;
// Early return if key doesn't exist
if (!Object.prototype.hasOwnProperty.call(obj, key)) {
obj[key] = value;
return;
}
// Handle string concatenation case
const isTextNode = key === effectiveTextNodeName;
const areStrings = typeof obj[key] === "string" && typeof value === "string";
if (isTextNode && areStrings && (!alwaysCreate || (alwaysCreate && isTextNode))) {
obj[key] += value;
return;
}
// Convert to array if needed and push new value
if (!Array.isArray(obj[key])) {
obj[key] = [obj[key]];
}
obj[key][obj[key].length] = value;
}
//# sourceMappingURL=dom-builder.js.map