Socket
Socket
Sign inDemoInstall

xmlbuilder2

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xmlbuilder2 - npm Package Compare versions

Comparing version 2.1.5 to 2.1.6

lib/builder/BuilderFunctions.d.ts

6

CHANGELOG.md

@@ -5,2 +5,7 @@ # Change Log

## [2.1.6] - 2020-07-02
### Bug Fixes
- Added minified browser from transpiled ES5 code so that the library can be used on old browsers (see [#28](https://github.com/oozcitak/xmlbuilder2/issues/28)). `Promise` and `Reflect` polyfills are required to use the library on IE 11.
## [2.1.5] - 2020-06-18

@@ -155,1 +160,2 @@

[2.1.5]: https://github.com/oozcitak/xmlbuilder2/compare/v2.1.4...v2.1.5
[2.1.6]: https://github.com/oozcitak/xmlbuilder2/compare/v2.1.5...v2.1.6

24

lib/builder/dom.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const dom_1 = require("@oozcitak/dom");
const dom_2 = require("@oozcitak/dom/lib/dom");
const util_1 = require("util");
var dom_1 = require("@oozcitak/dom");
var dom_2 = require("@oozcitak/dom/lib/dom");
var util_1 = require("@oozcitak/util");
dom_2.dom.setFeatures(false);

@@ -11,11 +11,11 @@ /**

function throwIfParserError(doc) {
const root = doc.documentElement;
var root = doc.documentElement;
if (root !== null &&
root.localName === "parsererror" &&
root.namespaceURI === "http://www.mozilla.org/newlayout/xml/parsererror.xml") {
const msgElement = root.firstElementChild;
var msgElement = root.firstElementChild;
/* istanbul ignore next */
if (msgElement === null)
throw new Error("Error parsing XML string.");
const msg = msgElement.getAttribute("message");
var msg = msgElement.getAttribute("message");
/* istanbul ignore next */

@@ -32,4 +32,4 @@ if (msg === null)

function createDocument() {
const impl = new dom_1.DOMImplementation();
const doc = impl.createDocument(null, 'root', null);
var impl = new dom_1.DOMImplementation();
var doc = impl.createDocument(null, 'root', null);
/* istanbul ignore else */

@@ -62,6 +62,6 @@ if (doc.documentElement) {

else {
let result = "";
var result = "";
str = str + "";
for (let i = 0; i < str.length; i++) {
let n = str.charCodeAt(i);
for (var i = 0; i < str.length; i++) {
var n = str.charCodeAt(i);
// #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]

@@ -75,3 +75,3 @@ if (n === 0x9 || n === 0xA || n === 0xD ||

else if (n >= 0xD800 && n <= 0xDBFF && i < str.length - 1) {
const n2 = str.charCodeAt(i + 1);
var n2 = str.charCodeAt(i + 1);
if (n2 >= 0xDC00 && n2 <= 0xDFFF) {

@@ -78,0 +78,0 @@ n = (n - 0xD800) * 0x400 + n2 - 0xDC00 + 0x10000;

export { XMLBuilderImpl } from "./XMLBuilderImpl";
export { XMLBuilderCBImpl } from "./XMLBuilderCBImpl";
export { builder, create, fragment, convert } from "./BuilderFunctions";
export { createCB, fragmentCB } from "./BuilderFunctionsCB";

@@ -7,2 +7,10 @@ "use strict";

exports.XMLBuilderCBImpl = XMLBuilderCBImpl_1.XMLBuilderCBImpl;
var BuilderFunctions_1 = require("./BuilderFunctions");
exports.builder = BuilderFunctions_1.builder;
exports.create = BuilderFunctions_1.create;
exports.fragment = BuilderFunctions_1.fragment;
exports.convert = BuilderFunctions_1.convert;
var BuilderFunctionsCB_1 = require("./BuilderFunctionsCB");
exports.createCB = BuilderFunctionsCB_1.createCB;
exports.fragmentCB = BuilderFunctionsCB_1.fragmentCB;
//# sourceMappingURL=index.js.map
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
Object.defineProperty(exports, "__esModule", { value: true });
const interfaces_1 = require("../interfaces");
const util_1 = require("@oozcitak/util");
const __1 = require("..");
const algorithm_1 = require("@oozcitak/dom/lib/algorithm");
const infra_1 = require("@oozcitak/infra");
const NamespacePrefixMap_1 = require("@oozcitak/dom/lib/serializer/NamespacePrefixMap");
const LocalNameSet_1 = require("@oozcitak/dom/lib/serializer/LocalNameSet");
const util_2 = require("@oozcitak/dom/lib/util");
const XMLCBWriter_1 = require("../writers/XMLCBWriter");
const JSONCBWriter_1 = require("../writers/JSONCBWriter");
const events_1 = require("events");
var interfaces_1 = require("../interfaces");
var util_1 = require("@oozcitak/util");
var BuilderFunctions_1 = require("./BuilderFunctions");
var algorithm_1 = require("@oozcitak/dom/lib/algorithm");
var infra_1 = require("@oozcitak/infra");
var NamespacePrefixMap_1 = require("@oozcitak/dom/lib/serializer/NamespacePrefixMap");
var LocalNameSet_1 = require("@oozcitak/dom/lib/serializer/LocalNameSet");
var util_2 = require("@oozcitak/dom/lib/util");
var XMLCBWriter_1 = require("../writers/XMLCBWriter");
var JSONCBWriter_1 = require("../writers/JSONCBWriter");
var events_1 = require("events");
/**
* Represents a readable XML document stream.
*/
class XMLBuilderCBImpl extends events_1.EventEmitter {
var XMLBuilderCBImpl = /** @class */ (function (_super) {
__extends(XMLBuilderCBImpl, _super);
/**

@@ -26,37 +67,40 @@ * Initializes a new instance of `XMLStream`.

*/
constructor(options, fragment = false) {
super();
this._hasDeclaration = false;
this._docTypeName = "";
this._hasDocumentElement = false;
this._currentElementSerialized = false;
this._openTags = [];
this._ended = false;
this._fragment = fragment;
function XMLBuilderCBImpl(options, fragment) {
if (fragment === void 0) { fragment = false; }
var _this = _super.call(this) || this;
_this._hasDeclaration = false;
_this._docTypeName = "";
_this._hasDocumentElement = false;
_this._currentElementSerialized = false;
_this._openTags = [];
_this._ended = false;
_this._fragment = fragment;
// provide default options
this._options = util_1.applyDefaults(options || {}, interfaces_1.DefaultXMLBuilderCBOptions);
this._builderOptions = {
defaultNamespace: this._options.defaultNamespace,
namespaceAlias: this._options.namespaceAlias
_this._options = util_1.applyDefaults(options || {}, interfaces_1.DefaultXMLBuilderCBOptions);
_this._builderOptions = {
defaultNamespace: _this._options.defaultNamespace,
namespaceAlias: _this._options.namespaceAlias
};
this._writer = this._options.format === "xml" ? new XMLCBWriter_1.XMLCBWriter(this._options) : new JSONCBWriter_1.JSONCBWriter(this._options);
_this._writer = _this._options.format === "xml" ? new XMLCBWriter_1.XMLCBWriter(_this._options) : new JSONCBWriter_1.JSONCBWriter(_this._options);
// automatically create listeners for callbacks passed via options
if (this._options.data !== undefined) {
this.on("data", this._options.data);
if (_this._options.data !== undefined) {
_this.on("data", _this._options.data);
}
if (this._options.end !== undefined) {
this.on("end", this._options.end);
if (_this._options.end !== undefined) {
_this.on("end", _this._options.end);
}
if (this._options.error !== undefined) {
this.on("error", this._options.error);
if (_this._options.error !== undefined) {
_this.on("error", _this._options.error);
}
this._prefixMap = new NamespacePrefixMap_1.NamespacePrefixMap();
this._prefixMap.set("xml", infra_1.namespace.XML);
this._prefixIndex = { value: 1 };
_this._prefixMap = new NamespacePrefixMap_1.NamespacePrefixMap();
_this._prefixMap.set("xml", infra_1.namespace.XML);
_this._prefixIndex = { value: 1 };
return _this;
}
/** @inheritdoc */
ele(p1, p2, p3) {
XMLBuilderCBImpl.prototype.ele = function (p1, p2, p3) {
var e_1, _a;
// parse if JS object or XML or JSON string
if (util_1.isObject(p1) || (util_1.isString(p1) && (/^\s*</.test(p1) || /^\s*[\{\[]/.test(p1)))) {
const frag = __1.fragment().set(this._options);
var frag = BuilderFunctions_1.fragment().set(this._options);
try {

@@ -69,5 +113,15 @@ frag.ele(p1);

}
for (const node of frag.node.childNodes) {
this._fromNode(node);
try {
for (var _b = __values(frag.node.childNodes), _c = _b.next(); !_c.done; _c = _b.next()) {
var node = _c.value;
this._fromNode(node);
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}
finally { if (e_1) throw e_1.error; }
}
return this;

@@ -81,3 +135,3 @@ }

try {
this._currentElement = __1.fragment(this._builderOptions).ele(p1, p2, p3);
this._currentElement = BuilderFunctions_1.fragment(this._builderOptions).ele(p1, p2, p3);
}

@@ -98,5 +152,5 @@ catch (err) {

return this;
}
};
/** @inheritdoc */
att(p1, p2, p3) {
XMLBuilderCBImpl.prototype.att = function (p1, p2, p3) {
if (this._currentElement === undefined) {

@@ -114,9 +168,9 @@ this.emit("error", new Error("Cannot insert an attribute node as child of a document node."));

return this;
}
};
/** @inheritdoc */
com(content) {
XMLBuilderCBImpl.prototype.com = function (content) {
this._serializeOpenTag(true);
let node;
var node;
try {
node = __1.fragment(this._builderOptions).com(content).first().node;
node = BuilderFunctions_1.fragment(this._builderOptions).com(content).first().node;
}

@@ -136,5 +190,5 @@ catch (err) {

return this;
}
};
/** @inheritdoc */
txt(content) {
XMLBuilderCBImpl.prototype.txt = function (content) {
if (!this._fragment && this._currentElement === undefined) {

@@ -145,5 +199,5 @@ this.emit("error", new Error("Cannot insert a text node as child of a document node."));

this._serializeOpenTag(true);
let node;
var node;
try {
node = __1.fragment(this._builderOptions).txt(content).first().node;
node = BuilderFunctions_1.fragment(this._builderOptions).txt(content).first().node;
}

@@ -160,3 +214,3 @@ catch (err) {

}
let markup = "";
var markup = "";
if (this._options.noDoubleEncoding) {

@@ -168,4 +222,4 @@ markup = node.data.replace(/(?!&(lt|gt|amp|apos|quot);)&/g, '&amp;')

else {
for (let i = 0; i < node.data.length; i++) {
const c = node.data[i];
for (var i = 0; i < node.data.length; i++) {
var c = node.data[i];
if (c === "&")

@@ -183,9 +237,10 @@ markup += "&amp;";

return this;
}
};
/** @inheritdoc */
ins(target, content = '') {
XMLBuilderCBImpl.prototype.ins = function (target, content) {
if (content === void 0) { content = ''; }
this._serializeOpenTag(true);
let node;
var node;
try {
node = __1.fragment(this._builderOptions).ins(target, content).first().node;
node = BuilderFunctions_1.fragment(this._builderOptions).ins(target, content).first().node;
}

@@ -208,9 +263,9 @@ catch (err) {

return this;
}
};
/** @inheritdoc */
dat(content) {
XMLBuilderCBImpl.prototype.dat = function (content) {
this._serializeOpenTag(true);
let node;
var node;
try {
node = __1.fragment(this._builderOptions).dat(content).first().node;
node = BuilderFunctions_1.fragment(this._builderOptions).dat(content).first().node;
}

@@ -223,5 +278,6 @@ catch (err) {

return this;
}
};
/** @inheritdoc */
dec(options = { version: "1.0" }) {
XMLBuilderCBImpl.prototype.dec = function (options) {
if (options === void 0) { options = { version: "1.0" }; }
if (this._fragment) {

@@ -238,5 +294,5 @@ this.emit("error", Error("Cannot insert an XML declaration into a document fragment."));

return this;
}
};
/** @inheritdoc */
dtd(options) {
XMLBuilderCBImpl.prototype.dtd = function (options) {
if (this._fragment) {

@@ -254,5 +310,5 @@ this.emit("error", Error("Cannot insert a DocType declaration into a document fragment."));

}
let node;
var node;
try {
node = __1.create().dtd(options).first().node;
node = BuilderFunctions_1.create().dtd(options).first().node;
}

@@ -276,11 +332,11 @@ catch (err) {

return this;
}
};
/** @inheritdoc */
up() {
XMLBuilderCBImpl.prototype.up = function () {
this._serializeOpenTag(false);
this._serializeCloseTag();
return this;
}
};
/** @inheritdoc */
end() {
XMLBuilderCBImpl.prototype.end = function () {
this._serializeOpenTag(false);

@@ -292,3 +348,3 @@ while (this._openTags.length > 0) {

return this;
}
};
/**

@@ -299,3 +355,3 @@ * Serializes the opening tag of an element node.

*/
_serializeOpenTag(hasChildren) {
XMLBuilderCBImpl.prototype._serializeOpenTag = function (hasChildren) {
if (this._currentElementSerialized)

@@ -305,3 +361,3 @@ return;

return;
const node = this._currentElement.node;
var node = this._currentElement.node;
if (this._options.wellFormed && (node.localName.indexOf(":") !== -1 ||

@@ -312,9 +368,9 @@ !algorithm_1.xml_isName(node.localName))) {

}
let qualifiedName = "";
let ignoreNamespaceDefinitionAttribute = false;
let map = this._prefixMap.copy();
let localPrefixesMap = {};
let localDefaultNamespace = this._recordNamespaceInformation(node, map, localPrefixesMap);
let inheritedNS = this._openTags.length === 0 ? null : this._openTags[this._openTags.length - 1][1];
let ns = node.namespaceURI;
var qualifiedName = "";
var ignoreNamespaceDefinitionAttribute = false;
var map = this._prefixMap.copy();
var localPrefixesMap = {};
var localDefaultNamespace = this._recordNamespaceInformation(node, map, localPrefixesMap);
var inheritedNS = this._openTags.length === 0 ? null : this._openTags[this._openTags.length - 1][1];
var ns = node.namespaceURI;
if (ns === null)

@@ -336,4 +392,4 @@ ns = inheritedNS;

else {
let prefix = node.prefix;
let candidatePrefix = null;
var prefix = node.prefix;
var candidatePrefix = null;
if (prefix !== null || ns !== localDefaultNamespace) {

@@ -387,3 +443,3 @@ candidatePrefix = map.get(prefix, ns);

this._serializeAttributes(node, map, this._prefixIndex, localPrefixesMap, ignoreNamespaceDefinitionAttribute, this._options.wellFormed);
const isHTML = (ns === infra_1.namespace.HTML);
var isHTML = (ns === infra_1.namespace.HTML);
if (isHTML && !hasChildren &&

@@ -419,9 +475,9 @@ XMLBuilderCBImpl._VoidElementNames.has(node.localName)) {

this._writer.level++;
}
};
/**
* Serializes the closing tag of an element node.
*/
_serializeCloseTag() {
XMLBuilderCBImpl.prototype._serializeCloseTag = function () {
this._writer.level--;
const lastEle = this._openTags.pop();
var lastEle = this._openTags.pop();
/* istanbul ignore next */

@@ -432,3 +488,3 @@ if (lastEle === undefined) {

}
const [qualifiedName, ns, map, hasChildren] = lastEle;
var _a = __read(lastEle, 4), qualifiedName = _a[0], ns = _a[1], map = _a[2], hasChildren = _a[3];
/**

@@ -442,3 +498,3 @@ * Restore original values of inherited namespace and prefix map.

this._writer.endElement(qualifiedName);
}
};
/**

@@ -449,3 +505,3 @@ * Pushes data to internal buffer.

*/
_push(data) {
XMLBuilderCBImpl.prototype._push = function (data) {
if (data === null) {

@@ -462,3 +518,3 @@ this._ended = true;

}
}
};
/**

@@ -469,5 +525,6 @@ * Reads and serializes an XML tree.

*/
_fromNode(node) {
XMLBuilderCBImpl.prototype._fromNode = function (node) {
var e_2, _a, e_3, _b;
if (util_2.Guard.isElementNode(node)) {
const name = node.prefix ? node.prefix + ":" + node.localName : node.localName;
var name = node.prefix ? node.prefix + ":" + node.localName : node.localName;
if (node.namespaceURI !== null) {

@@ -479,14 +536,34 @@ this.ele(node.namespaceURI, name);

}
for (const attr of node.attributes) {
const name = attr.prefix ? attr.prefix + ":" + attr.localName : attr.localName;
if (attr.namespaceURI !== null) {
this.att(attr.namespaceURI, name, attr.value);
try {
for (var _c = __values(node.attributes), _d = _c.next(); !_d.done; _d = _c.next()) {
var attr = _d.value;
var name_1 = attr.prefix ? attr.prefix + ":" + attr.localName : attr.localName;
if (attr.namespaceURI !== null) {
this.att(attr.namespaceURI, name_1, attr.value);
}
else {
this.att(name_1, attr.value);
}
}
else {
this.att(name, attr.value);
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
}
finally { if (e_2) throw e_2.error; }
}
for (const child of node.childNodes) {
this._fromNode(child);
try {
for (var _e = __values(node.childNodes), _f = _e.next(); !_f.done; _f = _e.next()) {
var child = _f.value;
this._fromNode(child);
}
}
catch (e_3_1) { e_3 = { error: e_3_1 }; }
finally {
try {
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
}
finally { if (e_3) throw e_3.error; }
}
this.up();

@@ -506,3 +583,3 @@ }

}
}
};
/**

@@ -519,70 +596,81 @@ * Produces an XML serialization of the attributes of an element node.

*/
_serializeAttributes(node, map, prefixIndex, localPrefixesMap, ignoreNamespaceDefinitionAttribute, requireWellFormed) {
const localNameSet = requireWellFormed ? new LocalNameSet_1.LocalNameSet() : undefined;
for (const attr of node.attributes) {
// Optimize common case
if (!requireWellFormed && !ignoreNamespaceDefinitionAttribute && attr.namespaceURI === null) {
this._push(this._writer.attribute(attr.localName, this._serializeAttributeValue(attr.value, this._options.wellFormed)));
continue;
}
if (requireWellFormed && localNameSet && localNameSet.has(attr.namespaceURI, attr.localName)) {
this.emit("error", new Error("Element contains duplicate attributes (well-formed required)."));
return;
}
if (requireWellFormed && localNameSet)
localNameSet.set(attr.namespaceURI, attr.localName);
let attributeNamespace = attr.namespaceURI;
let candidatePrefix = null;
if (attributeNamespace !== null) {
candidatePrefix = map.get(attr.prefix, attributeNamespace);
if (attributeNamespace === infra_1.namespace.XMLNS) {
if (attr.value === infra_1.namespace.XML ||
(attr.prefix === null && ignoreNamespaceDefinitionAttribute) ||
(attr.prefix !== null && (!(attr.localName in localPrefixesMap) ||
localPrefixesMap[attr.localName] !== attr.value) &&
map.has(attr.localName, attr.value)))
continue;
if (requireWellFormed && attr.value === infra_1.namespace.XMLNS) {
this.emit("error", new Error("XMLNS namespace is reserved (well-formed required)."));
return;
}
if (requireWellFormed && attr.value === '') {
this.emit("error", new Error("Namespace prefix declarations cannot be used to undeclare a namespace (well-formed required)."));
return;
}
if (attr.prefix === 'xmlns')
candidatePrefix = 'xmlns';
/**
* _Note:_ The (candidatePrefix === null) check is not in the spec.
* We deviate from the spec here. Otherwise a prefix is generated for
* all attributes with namespaces.
*/
XMLBuilderCBImpl.prototype._serializeAttributes = function (node, map, prefixIndex, localPrefixesMap, ignoreNamespaceDefinitionAttribute, requireWellFormed) {
var e_4, _a;
var localNameSet = requireWellFormed ? new LocalNameSet_1.LocalNameSet() : undefined;
try {
for (var _b = __values(node.attributes), _c = _b.next(); !_c.done; _c = _b.next()) {
var attr = _c.value;
// Optimize common case
if (!requireWellFormed && !ignoreNamespaceDefinitionAttribute && attr.namespaceURI === null) {
this._push(this._writer.attribute(attr.localName, this._serializeAttributeValue(attr.value, this._options.wellFormed)));
continue;
}
else if (candidatePrefix === null) {
if (attr.prefix !== null &&
(!map.hasPrefix(attr.prefix) ||
map.has(attr.prefix, attributeNamespace))) {
if (requireWellFormed && localNameSet && localNameSet.has(attr.namespaceURI, attr.localName)) {
this.emit("error", new Error("Element contains duplicate attributes (well-formed required)."));
return;
}
if (requireWellFormed && localNameSet)
localNameSet.set(attr.namespaceURI, attr.localName);
var attributeNamespace = attr.namespaceURI;
var candidatePrefix = null;
if (attributeNamespace !== null) {
candidatePrefix = map.get(attr.prefix, attributeNamespace);
if (attributeNamespace === infra_1.namespace.XMLNS) {
if (attr.value === infra_1.namespace.XML ||
(attr.prefix === null && ignoreNamespaceDefinitionAttribute) ||
(attr.prefix !== null && (!(attr.localName in localPrefixesMap) ||
localPrefixesMap[attr.localName] !== attr.value) &&
map.has(attr.localName, attr.value)))
continue;
if (requireWellFormed && attr.value === infra_1.namespace.XMLNS) {
this.emit("error", new Error("XMLNS namespace is reserved (well-formed required)."));
return;
}
if (requireWellFormed && attr.value === '') {
this.emit("error", new Error("Namespace prefix declarations cannot be used to undeclare a namespace (well-formed required)."));
return;
}
if (attr.prefix === 'xmlns')
candidatePrefix = 'xmlns';
/**
* Check if we can use the attribute's own prefix.
* We deviate from the spec here.
* TODO: This is not an efficient way of searching for prefixes.
* Follow developments to the spec.
* _Note:_ The (candidatePrefix === null) check is not in the spec.
* We deviate from the spec here. Otherwise a prefix is generated for
* all attributes with namespaces.
*/
candidatePrefix = attr.prefix;
}
else {
candidatePrefix = this._generatePrefix(attributeNamespace, map, prefixIndex);
else if (candidatePrefix === null) {
if (attr.prefix !== null &&
(!map.hasPrefix(attr.prefix) ||
map.has(attr.prefix, attributeNamespace))) {
/**
* Check if we can use the attribute's own prefix.
* We deviate from the spec here.
* TODO: This is not an efficient way of searching for prefixes.
* Follow developments to the spec.
*/
candidatePrefix = attr.prefix;
}
else {
candidatePrefix = this._generatePrefix(attributeNamespace, map, prefixIndex);
}
this._push(this._writer.attribute("xmlns:" + candidatePrefix, this._serializeAttributeValue(attributeNamespace, this._options.wellFormed)));
}
this._push(this._writer.attribute("xmlns:" + candidatePrefix, this._serializeAttributeValue(attributeNamespace, this._options.wellFormed)));
}
if (requireWellFormed && (attr.localName.indexOf(":") !== -1 ||
!algorithm_1.xml_isName(attr.localName) ||
(attr.localName === "xmlns" && attributeNamespace === null))) {
this.emit("error", new Error("Attribute local name contains invalid characters (well-formed required)."));
return;
}
this._push(this._writer.attribute((candidatePrefix !== null ? candidatePrefix + ":" : "") + attr.localName, this._serializeAttributeValue(attr.value, this._options.wellFormed)));
}
if (requireWellFormed && (attr.localName.indexOf(":") !== -1 ||
!algorithm_1.xml_isName(attr.localName) ||
(attr.localName === "xmlns" && attributeNamespace === null))) {
this.emit("error", new Error("Attribute local name contains invalid characters (well-formed required)."));
return;
}
catch (e_4_1) { e_4 = { error: e_4_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}
this._push(this._writer.attribute((candidatePrefix !== null ? candidatePrefix + ":" : "") + attr.localName, this._serializeAttributeValue(attr.value, this._options.wellFormed)));
finally { if (e_4) throw e_4.error; }
}
}
};
/**

@@ -594,3 +682,3 @@ * Produces an XML serialization of an attribute value.

*/
_serializeAttributeValue(value, requireWellFormed) {
XMLBuilderCBImpl.prototype._serializeAttributeValue = function (value, requireWellFormed) {
if (requireWellFormed && value !== null && !algorithm_1.xml_isLegalChar(value)) {

@@ -609,5 +697,5 @@ this.emit("error", new Error("Invalid characters in attribute value."));

else {
let result = "";
for (let i = 0; i < value.length; i++) {
const c = value[i];
var result = "";
for (var i = 0; i < value.length; i++) {
var c = value[i];
if (c === "\"")

@@ -626,3 +714,3 @@ result += "&quot;";

}
}
};
/**

@@ -636,31 +724,42 @@ * Records namespace information for the given element and returns the

*/
_recordNamespaceInformation(node, map, localPrefixesMap) {
let defaultNamespaceAttrValue = null;
for (const attr of node.attributes) {
let attributeNamespace = attr.namespaceURI;
let attributePrefix = attr.prefix;
if (attributeNamespace === infra_1.namespace.XMLNS) {
if (attributePrefix === null) {
defaultNamespaceAttrValue = attr.value;
continue;
}
else {
let prefixDefinition = attr.localName;
let namespaceDefinition = attr.value;
if (namespaceDefinition === infra_1.namespace.XML) {
XMLBuilderCBImpl.prototype._recordNamespaceInformation = function (node, map, localPrefixesMap) {
var e_5, _a;
var defaultNamespaceAttrValue = null;
try {
for (var _b = __values(node.attributes), _c = _b.next(); !_c.done; _c = _b.next()) {
var attr = _c.value;
var attributeNamespace = attr.namespaceURI;
var attributePrefix = attr.prefix;
if (attributeNamespace === infra_1.namespace.XMLNS) {
if (attributePrefix === null) {
defaultNamespaceAttrValue = attr.value;
continue;
}
if (namespaceDefinition === '') {
namespaceDefinition = null;
else {
var prefixDefinition = attr.localName;
var namespaceDefinition = attr.value;
if (namespaceDefinition === infra_1.namespace.XML) {
continue;
}
if (namespaceDefinition === '') {
namespaceDefinition = null;
}
if (map.has(prefixDefinition, namespaceDefinition)) {
continue;
}
map.set(prefixDefinition, namespaceDefinition);
localPrefixesMap[prefixDefinition] = namespaceDefinition || '';
}
if (map.has(prefixDefinition, namespaceDefinition)) {
continue;
}
map.set(prefixDefinition, namespaceDefinition);
localPrefixesMap[prefixDefinition] = namespaceDefinition || '';
}
}
}
catch (e_5_1) { e_5 = { error: e_5_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}
finally { if (e_5) throw e_5.error; }
}
return defaultNamespaceAttrValue;
}
};
/**

@@ -673,8 +772,8 @@ * Generates a new prefix for the given namespace.

*/
_generatePrefix(newNamespace, prefixMap, prefixIndex) {
let generatedPrefix = "ns" + prefixIndex.value;
XMLBuilderCBImpl.prototype._generatePrefix = function (newNamespace, prefixMap, prefixIndex) {
var generatedPrefix = "ns" + prefixIndex.value;
prefixIndex.value++;
prefixMap.set(generatedPrefix, newNamespace);
return generatedPrefix;
}
};
/**

@@ -686,15 +785,15 @@ * Determines if the namespace prefix map was modified from its original.

*/
_isPrefixMapModified(originalMap, newMap) {
const items1 = originalMap._items;
const items2 = newMap._items;
const nullItems1 = originalMap._nullItems;
const nullItems2 = newMap._nullItems;
for (const key in items2) {
const arr1 = items1[key];
XMLBuilderCBImpl.prototype._isPrefixMapModified = function (originalMap, newMap) {
var items1 = originalMap._items;
var items2 = newMap._items;
var nullItems1 = originalMap._nullItems;
var nullItems2 = newMap._nullItems;
for (var key in items2) {
var arr1 = items1[key];
if (arr1 === undefined)
return true;
const arr2 = items2[key];
var arr2 = items2[key];
if (arr1.length !== arr2.length)
return true;
for (let i = 0; i < arr1.length; i++) {
for (var i = 0; i < arr1.length; i++) {
if (arr1[i] !== arr2[i])

@@ -706,3 +805,3 @@ return true;

return true;
for (let i = 0; i < nullItems1.length; i++) {
for (var i = 0; i < nullItems1.length; i++) {
if (nullItems1[i] !== nullItems2[i])

@@ -712,8 +811,9 @@ return true;

return false;
}
}
};
XMLBuilderCBImpl._VoidElementNames = new Set(['area', 'base', 'basefont',
'bgsound', 'br', 'col', 'embed', 'frame', 'hr', 'img', 'input', 'keygen',
'link', 'menuitem', 'meta', 'param', 'source', 'track', 'wbr']);
return XMLBuilderCBImpl;
}(events_1.EventEmitter));
exports.XMLBuilderCBImpl = XMLBuilderCBImpl;
XMLBuilderCBImpl._VoidElementNames = new Set(['area', 'base', 'basefont',
'bgsound', 'br', 'col', 'embed', 'frame', 'hr', 'img', 'input', 'keygen',
'link', 'menuitem', 'meta', 'param', 'source', 'track', 'wbr']);
//# sourceMappingURL=XMLBuilderCBImpl.js.map
"use strict";
var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
Object.defineProperty(exports, "__esModule", { value: true });
const interfaces_1 = require("../interfaces");
const util_1 = require("@oozcitak/util");
const writers_1 = require("../writers");
const interfaces_2 = require("@oozcitak/dom/lib/dom/interfaces");
const util_2 = require("@oozcitak/dom/lib/util");
const algorithm_1 = require("@oozcitak/dom/lib/algorithm");
const dom_1 = require("./dom");
const infra_1 = require("@oozcitak/infra");
var interfaces_1 = require("../interfaces");
var util_1 = require("@oozcitak/util");
var writers_1 = require("../writers");
var interfaces_2 = require("@oozcitak/dom/lib/dom/interfaces");
var util_2 = require("@oozcitak/dom/lib/util");
var algorithm_1 = require("@oozcitak/dom/lib/algorithm");
var dom_1 = require("./dom");
var infra_1 = require("@oozcitak/infra");
/**

@@ -15,3 +42,3 @@ * Represents a wrapper that extends XML nodes to implement easy to use and

*/
class XMLBuilderImpl {
var XMLBuilderImpl = /** @class */ (function () {
/**

@@ -22,24 +49,30 @@ * Initializes a new instance of `XMLBuilderNodeImpl`.

*/
constructor(domNode) {
function XMLBuilderImpl(domNode) {
this._domNode = domNode;
}
Object.defineProperty(XMLBuilderImpl.prototype, "node", {
/** @inheritdoc */
get: function () { return this._domNode; },
enumerable: true,
configurable: true
});
/** @inheritdoc */
get node() { return this._domNode; }
/** @inheritdoc */
set(options) {
XMLBuilderImpl.prototype.set = function (options) {
this._options = util_1.applyDefaults(util_1.applyDefaults(this._options, options, true), // apply user settings
interfaces_1.DefaultBuilderOptions); // provide defaults
return this;
}
};
/** @inheritdoc */
ele(p1, p2, p3) {
let namespace;
let name;
let attributes;
let lastChild = null;
XMLBuilderImpl.prototype.ele = function (p1, p2, p3) {
var e_1, _a, _b, _c, _d, _e;
var _this = this;
var namespace;
var name;
var attributes;
var lastChild = null;
if (util_1.isString(p1) && /^\s*</.test(p1)) {
// parse XML string
const contents = "<TEMP_ROOT>" + p1 + "</TEMP_ROOT>";
const domParser = dom_1.createParser();
const doc = domParser.parseFromString(dom_1.sanitizeInput(contents, this._options.invalidCharReplacement), "text/xml");
var contents = "<TEMP_ROOT>" + p1 + "</TEMP_ROOT>";
var domParser = dom_1.createParser();
var doc = domParser.parseFromString(dom_1.sanitizeInput(contents, this._options.invalidCharReplacement), "text/xml");
/* istanbul ignore next */

@@ -50,7 +83,17 @@ if (doc.documentElement === null) {

dom_1.throwIfParserError(doc);
for (const child of doc.documentElement.childNodes) {
const newChild = doc.importNode(child, true);
lastChild = new XMLBuilderImpl(newChild);
this._domNode.appendChild(newChild);
try {
for (var _f = __values(doc.documentElement.childNodes), _g = _f.next(); !_g.done; _g = _f.next()) {
var child = _g.value;
var newChild = doc.importNode(child, true);
lastChild = new XMLBuilderImpl(newChild);
this._domNode.appendChild(newChild);
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_g && !_g.done && (_a = _f.return)) _a.call(_f);
}
finally { if (e_1) throw e_1.error; }
}
if (lastChild === null) {

@@ -63,3 +106,3 @@ throw new Error("Could not create any elements with: " + p1.toString() + ". " + this._debugInfo());

// parse JSON string
const obj = JSON.parse(p1);
var obj = JSON.parse(p1);
return this.ele(obj);

@@ -69,11 +112,11 @@ }

// ele(obj: ExpandObject)
[namespace, name, attributes] = [undefined, p1, undefined];
_b = __read([undefined, p1, undefined], 3), namespace = _b[0], name = _b[1], attributes = _b[2];
}
else if ((p1 === null || util_1.isString(p1)) && util_1.isString(p2)) {
// ele(namespace: string, name: string, attributes?: AttributesObject)
[namespace, name, attributes] = [p1, p2, p3];
_c = __read([p1, p2, p3], 3), namespace = _c[0], name = _c[1], attributes = _c[2];
}
else if (p1 !== null) {
// ele(name: string, attributes?: AttributesObject)
[namespace, name, attributes] = [undefined, p1, util_1.isObject(p2) ? p2 : undefined];
_d = __read([undefined, p1, util_1.isObject(p2) ? p2 : undefined], 3), namespace = _d[0], name = _d[1], attributes = _d[2];
}

@@ -91,58 +134,58 @@ else {

else if (util_1.isArray(name) || util_1.isSet(name)) {
util_1.forEachArray(name, item => lastChild = this.ele(item), this);
util_1.forEachArray(name, function (item) { return lastChild = _this.ele(item); }, this);
}
else if (util_1.isMap(name) || util_1.isObject(name)) {
// expand if object
util_1.forEachObject(name, (key, val) => {
util_1.forEachObject(name, function (key, val) {
if (util_1.isFunction(val)) {
// evaluate if function
val = val.apply(this);
val = val.apply(_this);
}
if (!this._options.ignoreConverters && key.indexOf(this._options.convert.att) === 0) {
if (!_this._options.ignoreConverters && key.indexOf(_this._options.convert.att) === 0) {
// assign attributes
if (key === this._options.convert.att) {
lastChild = this.att(val);
if (key === _this._options.convert.att) {
lastChild = _this.att(val);
}
else {
lastChild = this.att(key.substr(this._options.convert.att.length), val);
lastChild = _this.att(key.substr(_this._options.convert.att.length), val);
}
}
else if (!this._options.ignoreConverters && key.indexOf(this._options.convert.text) === 0) {
else if (!_this._options.ignoreConverters && key.indexOf(_this._options.convert.text) === 0) {
// text node
if (util_1.isMap(val) || util_1.isObject(val)) {
// if the key is #text expand child nodes under this node to support mixed content
lastChild = this.ele(val);
lastChild = _this.ele(val);
}
else {
lastChild = this.txt(val);
lastChild = _this.txt(val);
}
}
else if (!this._options.ignoreConverters && key.indexOf(this._options.convert.cdata) === 0) {
else if (!_this._options.ignoreConverters && key.indexOf(_this._options.convert.cdata) === 0) {
// cdata node
if (util_1.isArray(val) || util_1.isSet(val)) {
util_1.forEachArray(val, item => lastChild = this.dat(item), this);
util_1.forEachArray(val, function (item) { return lastChild = _this.dat(item); }, _this);
}
else {
lastChild = this.dat(val);
lastChild = _this.dat(val);
}
}
else if (!this._options.ignoreConverters && key.indexOf(this._options.convert.comment) === 0) {
else if (!_this._options.ignoreConverters && key.indexOf(_this._options.convert.comment) === 0) {
// comment node
if (util_1.isArray(val) || util_1.isSet(val)) {
util_1.forEachArray(val, item => lastChild = this.com(item), this);
util_1.forEachArray(val, function (item) { return lastChild = _this.com(item); }, _this);
}
else {
lastChild = this.com(val);
lastChild = _this.com(val);
}
}
else if (!this._options.ignoreConverters && key.indexOf(this._options.convert.ins) === 0) {
else if (!_this._options.ignoreConverters && key.indexOf(_this._options.convert.ins) === 0) {
// processing instruction
if (util_1.isString(val)) {
const insIndex = val.indexOf(' ');
const insTarget = (insIndex === -1 ? val : val.substr(0, insIndex));
const insValue = (insIndex === -1 ? '' : val.substr(insIndex + 1));
lastChild = this.ins(insTarget, insValue);
var insIndex = val.indexOf(' ');
var insTarget = (insIndex === -1 ? val : val.substr(0, insIndex));
var insValue = (insIndex === -1 ? '' : val.substr(insIndex + 1));
lastChild = _this.ins(insTarget, insValue);
}
else {
lastChild = this.ins(val);
lastChild = _this.ins(val);
}

@@ -152,23 +195,23 @@ }

// skip empty arrays
lastChild = this._dummy();
lastChild = _this._dummy();
}
else if ((util_1.isMap(val) || util_1.isObject(val)) && util_1.isEmpty(val)) {
// empty objects produce one node
lastChild = this.ele(key);
lastChild = _this.ele(key);
}
else if (!this._options.keepNullNodes && (val == null)) {
else if (!_this._options.keepNullNodes && (val == null)) {
// skip null and undefined nodes
lastChild = this._dummy();
lastChild = _this._dummy();
}
else if (util_1.isArray(val) || util_1.isSet(val)) {
// expand list by creating child nodes
util_1.forEachArray(val, item => {
const childNode = {};
util_1.forEachArray(val, function (item) {
var childNode = {};
childNode[key] = item;
lastChild = this.ele(childNode);
}, this);
lastChild = _this.ele(childNode);
}, _this);
}
else if (util_1.isMap(val) || util_1.isObject(val)) {
// create a parent node
lastChild = this.ele(key);
lastChild = _this.ele(key);
// expand child nodes under parent

@@ -179,3 +222,3 @@ lastChild.ele(val);

// leaf element node with a single text node
lastChild = this.ele(key);
lastChild = _this.ele(key);
lastChild.txt(val);

@@ -185,3 +228,3 @@ }

// leaf element node
lastChild = this.ele(key);
lastChild = _this.ele(key);
}

@@ -191,10 +234,10 @@ }, this);

else {
[namespace, name] = this._extractNamespace(dom_1.sanitizeInput(namespace, this._options.invalidCharReplacement), dom_1.sanitizeInput(name, this._options.invalidCharReplacement), true);
_e = __read(this._extractNamespace(dom_1.sanitizeInput(namespace, this._options.invalidCharReplacement), dom_1.sanitizeInput(name, this._options.invalidCharReplacement), true), 2), namespace = _e[0], name = _e[1];
// inherit namespace from parent
if (namespace === undefined) {
const [prefix] = algorithm_1.namespace_extractQName(name);
var _h = __read(algorithm_1.namespace_extractQName(name), 1), prefix = _h[0];
namespace = this.node.lookupNamespaceURI(prefix);
}
// create a child element node
const childNode = (namespace !== undefined && namespace !== null ?
var childNode = (namespace !== undefined && namespace !== null ?
this._doc.createElementNS(namespace, name) :

@@ -205,5 +248,5 @@ this._doc.createElement(name));

// update doctype node if the new node is the document element node
const oldDocType = this._doc.doctype;
var oldDocType = this._doc.doctype;
if (childNode === this._doc.documentElement && oldDocType !== null) {
const docType = this._doc.implementation.createDocumentType(this._doc.documentElement.tagName, oldDocType.publicId, oldDocType.systemId);
var docType = this._doc.implementation.createDocumentType(this._doc.documentElement.tagName, oldDocType.publicId, oldDocType.systemId);
this._doc.replaceChild(docType, oldDocType);

@@ -220,15 +263,17 @@ }

return lastChild;
}
};
/** @inheritdoc */
remove() {
const parent = this.up();
XMLBuilderImpl.prototype.remove = function () {
var parent = this.up();
parent.node.removeChild(this.node);
return parent;
}
};
/** @inheritdoc */
att(p1, p2, p3) {
XMLBuilderImpl.prototype.att = function (p1, p2, p3) {
var _a, _b, _c;
var _this = this;
if (util_1.isMap(p1) || util_1.isObject(p1)) {
// att(obj: AttributesObject)
// expand if object
util_1.forEachObject(p1, (attName, attValue) => this.att(attName, attValue), this);
util_1.forEachObject(p1, function (attName, attValue) { return _this.att(attName, attValue); }, this);
return this;

@@ -243,12 +288,12 @@ }

p3 = util_1.getValue(p3 + "");
let namespace;
let name;
let value;
var namespace;
var name;
var value;
if ((p1 === null || util_1.isString(p1)) && util_1.isString(p2) && (p3 === null || util_1.isString(p3))) {
// att(namespace: string, name: string, value: string)
[namespace, name, value] = [p1, p2, p3];
_a = __read([p1, p2, p3], 3), namespace = _a[0], name = _a[1], value = _a[2];
}
else if (util_1.isString(p1) && (p2 == null || util_1.isString(p2))) {
// ele(name: string, value: string)
[namespace, name, value] = [undefined, p1, p2];
_b = __read([undefined, p1, p2], 3), namespace = _b[0], name = _b[1], value = _b[2];
}

@@ -269,12 +314,12 @@ else {

}
let ele = this.node;
[namespace, name] = this._extractNamespace(namespace, name, false);
var ele = this.node;
_c = __read(this._extractNamespace(namespace, name, false), 2), namespace = _c[0], name = _c[1];
name = dom_1.sanitizeInput(name, this._options.invalidCharReplacement);
namespace = dom_1.sanitizeInput(namespace, this._options.invalidCharReplacement);
value = dom_1.sanitizeInput(value, this._options.invalidCharReplacement);
const [prefix, localName] = algorithm_1.namespace_extractQName(name);
const [elePrefix] = algorithm_1.namespace_extractQName(ele.prefix ? ele.prefix + ':' + ele.localName : ele.localName);
var _d = __read(algorithm_1.namespace_extractQName(name), 2), prefix = _d[0], localName = _d[1];
var _e = __read(algorithm_1.namespace_extractQName(ele.prefix ? ele.prefix + ':' + ele.localName : ele.localName), 1), elePrefix = _e[0];
// check if this is a namespace declaration attribute
// assign a new element namespace if it wasn't previously assigned
let eleNamespace = null;
var eleNamespace = null;
if (prefix === "xmlns") {

@@ -303,5 +348,6 @@ namespace = infra_1.namespace.XMLNS;

return this;
}
};
/** @inheritdoc */
removeAtt(p1, p2) {
XMLBuilderImpl.prototype.removeAtt = function (p1, p2) {
var _this = this;
if (!util_2.Guard.isElementNode(this.node)) {

@@ -315,4 +361,4 @@ throw new Error("An attribute can only be removed from an element node.");

}
let namespace;
let name;
var namespace;
var name;
if (p1 !== null && p2 === undefined) {

@@ -331,3 +377,5 @@ name = p1;

// removeAtt(namespace: string, names: string[])
util_1.forEachArray(name, attName => namespace === undefined ? this.removeAtt(attName) : this.removeAtt(namespace, attName), this);
util_1.forEachArray(name, function (attName) {
return namespace === undefined ? _this.removeAtt(attName) : _this.removeAtt(namespace, attName);
}, this);
}

@@ -346,43 +394,45 @@ else if (namespace !== undefined) {

return this;
}
};
/** @inheritdoc */
txt(content) {
const child = this._doc.createTextNode(dom_1.sanitizeInput(content, this._options.invalidCharReplacement));
XMLBuilderImpl.prototype.txt = function (content) {
var child = this._doc.createTextNode(dom_1.sanitizeInput(content, this._options.invalidCharReplacement));
this.node.appendChild(child);
return this;
}
};
/** @inheritdoc */
com(content) {
const child = this._doc.createComment(dom_1.sanitizeInput(content, this._options.invalidCharReplacement));
XMLBuilderImpl.prototype.com = function (content) {
var child = this._doc.createComment(dom_1.sanitizeInput(content, this._options.invalidCharReplacement));
this.node.appendChild(child);
return this;
}
};
/** @inheritdoc */
dat(content) {
const child = this._doc.createCDATASection(dom_1.sanitizeInput(content, this._options.invalidCharReplacement));
XMLBuilderImpl.prototype.dat = function (content) {
var child = this._doc.createCDATASection(dom_1.sanitizeInput(content, this._options.invalidCharReplacement));
this.node.appendChild(child);
return this;
}
};
/** @inheritdoc */
ins(target, content = '') {
XMLBuilderImpl.prototype.ins = function (target, content) {
var _this = this;
if (content === void 0) { content = ''; }
if (util_1.isArray(target) || util_1.isSet(target)) {
util_1.forEachArray(target, item => {
util_1.forEachArray(target, function (item) {
item += "";
const insIndex = item.indexOf(' ');
const insTarget = (insIndex === -1 ? item : item.substr(0, insIndex));
const insValue = (insIndex === -1 ? '' : item.substr(insIndex + 1));
this.ins(insTarget, insValue);
var insIndex = item.indexOf(' ');
var insTarget = (insIndex === -1 ? item : item.substr(0, insIndex));
var insValue = (insIndex === -1 ? '' : item.substr(insIndex + 1));
_this.ins(insTarget, insValue);
}, this);
}
else if (util_1.isMap(target) || util_1.isObject(target)) {
util_1.forEachObject(target, (insTarget, insValue) => this.ins(insTarget, insValue), this);
util_1.forEachObject(target, function (insTarget, insValue) { return _this.ins(insTarget, insValue); }, this);
}
else {
const child = this._doc.createProcessingInstruction(dom_1.sanitizeInput(target, this._options.invalidCharReplacement), dom_1.sanitizeInput(content, this._options.invalidCharReplacement));
var child = this._doc.createProcessingInstruction(dom_1.sanitizeInput(target, this._options.invalidCharReplacement), dom_1.sanitizeInput(content, this._options.invalidCharReplacement));
this.node.appendChild(child);
}
return this;
}
};
/** @inheritdoc */
dec(options) {
XMLBuilderImpl.prototype.dec = function (options) {
this._options.version = options.version || "1.0";

@@ -392,8 +442,8 @@ this._options.encoding = options.encoding;

return this;
}
};
/** @inheritdoc */
dtd(options) {
const name = dom_1.sanitizeInput((options && options.name) || (this._doc.documentElement ? this._doc.documentElement.tagName : "ROOT"), this._options.invalidCharReplacement);
const pubID = dom_1.sanitizeInput((options && options.pubID) || "", this._options.invalidCharReplacement);
const sysID = dom_1.sanitizeInput((options && options.sysID) || "", this._options.invalidCharReplacement);
XMLBuilderImpl.prototype.dtd = function (options) {
var name = dom_1.sanitizeInput((options && options.name) || (this._doc.documentElement ? this._doc.documentElement.tagName : "ROOT"), this._options.invalidCharReplacement);
var pubID = dom_1.sanitizeInput((options && options.pubID) || "", this._options.invalidCharReplacement);
var sysID = dom_1.sanitizeInput((options && options.sysID) || "", this._options.invalidCharReplacement);
// name must match document element

@@ -404,3 +454,3 @@ if (this._doc.documentElement !== null && name !== this._doc.documentElement.tagName) {

// create doctype node
const docType = this._doc.implementation.createDocumentType(name, pubID, sysID);
var docType = this._doc.implementation.createDocumentType(name, pubID, sysID);
if (this._doc.doctype !== null) {

@@ -415,39 +465,50 @@ // replace existing doctype

return this;
}
};
/** @inheritdoc */
import(node) {
const hostNode = this._domNode;
const hostDoc = this._doc;
const importedNode = node.node;
XMLBuilderImpl.prototype.import = function (node) {
var e_2, _a;
var hostNode = this._domNode;
var hostDoc = this._doc;
var importedNode = node.node;
if (util_2.Guard.isDocumentNode(importedNode)) {
// import document node
const elementNode = importedNode.documentElement;
var elementNode = importedNode.documentElement;
if (elementNode === null) {
throw new Error("Imported document has no document element node. " + this._debugInfo());
}
const clone = hostDoc.importNode(elementNode, true);
var clone = hostDoc.importNode(elementNode, true);
hostNode.appendChild(clone);
const [prefix] = algorithm_1.namespace_extractQName(clone.prefix ? clone.prefix + ':' + clone.localName : clone.localName);
const namespace = hostNode.lookupNamespaceURI(prefix);
var _b = __read(algorithm_1.namespace_extractQName(clone.prefix ? clone.prefix + ':' + clone.localName : clone.localName), 1), prefix = _b[0];
var namespace = hostNode.lookupNamespaceURI(prefix);
new XMLBuilderImpl(clone)._updateNamespace(namespace);
}
else if (util_2.Guard.isDocumentFragmentNode(importedNode)) {
// import child nodes
for (const childNode of importedNode.childNodes) {
const clone = hostDoc.importNode(childNode, true);
hostNode.appendChild(clone);
if (util_2.Guard.isElementNode(clone)) {
const [prefix] = algorithm_1.namespace_extractQName(clone.prefix ? clone.prefix + ':' + clone.localName : clone.localName);
const namespace = hostNode.lookupNamespaceURI(prefix);
new XMLBuilderImpl(clone)._updateNamespace(namespace);
try {
// import child nodes
for (var _c = __values(importedNode.childNodes), _d = _c.next(); !_d.done; _d = _c.next()) {
var childNode = _d.value;
var clone = hostDoc.importNode(childNode, true);
hostNode.appendChild(clone);
if (util_2.Guard.isElementNode(clone)) {
var _e = __read(algorithm_1.namespace_extractQName(clone.prefix ? clone.prefix + ':' + clone.localName : clone.localName), 1), prefix = _e[0];
var namespace = hostNode.lookupNamespaceURI(prefix);
new XMLBuilderImpl(clone)._updateNamespace(namespace);
}
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
}
finally { if (e_2) throw e_2.error; }
}
}
else {
// import node
const clone = hostDoc.importNode(importedNode, true);
var clone = hostDoc.importNode(importedNode, true);
hostNode.appendChild(clone);
if (util_2.Guard.isElementNode(clone)) {
const [prefix] = algorithm_1.namespace_extractQName(clone.prefix ? clone.prefix + ':' + clone.localName : clone.localName);
const namespace = hostNode.lookupNamespaceURI(prefix);
var _f = __read(algorithm_1.namespace_extractQName(clone.prefix ? clone.prefix + ':' + clone.localName : clone.localName), 1), prefix = _f[0];
var namespace = hostNode.lookupNamespaceURI(prefix);
new XMLBuilderImpl(clone)._updateNamespace(namespace);

@@ -457,7 +518,7 @@ }

return this;
}
};
/** @inheritdoc */
doc() {
XMLBuilderImpl.prototype.doc = function () {
if (this._doc._isFragment) {
let node = this.node;
var node = this.node;
while (node && node.nodeType !== interfaces_2.NodeType.DocumentFragment) {

@@ -475,6 +536,6 @@ node = node.parentNode;

}
}
};
/** @inheritdoc */
root() {
const ele = this._doc.documentElement;
XMLBuilderImpl.prototype.root = function () {
var ele = this._doc.documentElement;
if (!ele) {

@@ -484,6 +545,6 @@ throw new Error("Document root element is null. " + this._debugInfo());

return new XMLBuilderImpl(ele);
}
};
/** @inheritdoc */
up() {
const parent = this._domNode.parentNode;
XMLBuilderImpl.prototype.up = function () {
var parent = this._domNode.parentNode;
if (!parent) {

@@ -493,6 +554,6 @@ throw new Error("Parent node is null. " + this._debugInfo());

return new XMLBuilderImpl(parent);
}
};
/** @inheritdoc */
prev() {
const node = this._domNode.previousSibling;
XMLBuilderImpl.prototype.prev = function () {
var node = this._domNode.previousSibling;
if (!node) {

@@ -502,6 +563,6 @@ throw new Error("Previous sibling node is null. " + this._debugInfo());

return new XMLBuilderImpl(node);
}
};
/** @inheritdoc */
next() {
const node = this._domNode.nextSibling;
XMLBuilderImpl.prototype.next = function () {
var node = this._domNode.nextSibling;
if (!node) {

@@ -511,6 +572,6 @@ throw new Error("Next sibling node is null. " + this._debugInfo());

return new XMLBuilderImpl(node);
}
};
/** @inheritdoc */
first() {
const node = this._domNode.firstChild;
XMLBuilderImpl.prototype.first = function () {
var node = this._domNode.firstChild;
if (!node) {

@@ -520,6 +581,6 @@ throw new Error("First child node is null. " + this._debugInfo());

return new XMLBuilderImpl(node);
}
};
/** @inheritdoc */
last() {
const node = this._domNode.lastChild;
XMLBuilderImpl.prototype.last = function () {
var node = this._domNode.lastChild;
if (!node) {

@@ -529,6 +590,8 @@ throw new Error("Last child node is null. " + this._debugInfo());

return new XMLBuilderImpl(node);
}
};
/** @inheritdoc */
each(callback, self = false, recursive = false, thisArg) {
let result = this._getFirstDescendantNode(this._domNode, self, recursive);
XMLBuilderImpl.prototype.each = function (callback, self, recursive, thisArg) {
if (self === void 0) { self = false; }
if (recursive === void 0) { recursive = false; }
var result = this._getFirstDescendantNode(this._domNode, self, recursive);
while (result[0]) {

@@ -539,20 +602,30 @@ callback.call(thisArg, new XMLBuilderImpl(result[0]), result[1], result[2]);

return this;
}
};
/** @inheritdoc */
map(callback, self = false, recursive = false, thisArg) {
let result = [];
this.each((node, index, level) => result.push(callback.call(thisArg, node, index, level)), self, recursive);
XMLBuilderImpl.prototype.map = function (callback, self, recursive, thisArg) {
if (self === void 0) { self = false; }
if (recursive === void 0) { recursive = false; }
var result = [];
this.each(function (node, index, level) {
return result.push(callback.call(thisArg, node, index, level));
}, self, recursive);
return result;
}
};
/** @inheritdoc */
reduce(callback, initialValue, self = false, recursive = false, thisArg) {
let value = initialValue;
this.each((node, index, level) => value = callback.call(thisArg, value, node, index, level), self, recursive);
XMLBuilderImpl.prototype.reduce = function (callback, initialValue, self, recursive, thisArg) {
if (self === void 0) { self = false; }
if (recursive === void 0) { recursive = false; }
var value = initialValue;
this.each(function (node, index, level) {
return value = callback.call(thisArg, value, node, index, level);
}, self, recursive);
return value;
}
};
/** @inheritdoc */
find(predicate, self = false, recursive = false, thisArg) {
let result = this._getFirstDescendantNode(this._domNode, self, recursive);
XMLBuilderImpl.prototype.find = function (predicate, self, recursive, thisArg) {
if (self === void 0) { self = false; }
if (recursive === void 0) { recursive = false; }
var result = this._getFirstDescendantNode(this._domNode, self, recursive);
while (result[0]) {
const builder = new XMLBuilderImpl(result[0]);
var builder = new XMLBuilderImpl(result[0]);
if (predicate.call(thisArg, builder, result[1], result[2])) {

@@ -564,7 +637,9 @@ return builder;

return undefined;
}
};
/** @inheritdoc */
filter(predicate, self = false, recursive = false, thisArg) {
let result = [];
this.each((node, index, level) => {
XMLBuilderImpl.prototype.filter = function (predicate, self, recursive, thisArg) {
if (self === void 0) { self = false; }
if (recursive === void 0) { recursive = false; }
var result = [];
this.each(function (node, index, level) {
if (predicate.call(thisArg, node, index, level)) {

@@ -575,8 +650,10 @@ result.push(node);

return result;
}
};
/** @inheritdoc */
every(predicate, self = false, recursive = false, thisArg) {
let result = this._getFirstDescendantNode(this._domNode, self, recursive);
XMLBuilderImpl.prototype.every = function (predicate, self, recursive, thisArg) {
if (self === void 0) { self = false; }
if (recursive === void 0) { recursive = false; }
var result = this._getFirstDescendantNode(this._domNode, self, recursive);
while (result[0]) {
const builder = new XMLBuilderImpl(result[0]);
var builder = new XMLBuilderImpl(result[0]);
if (!predicate.call(thisArg, builder, result[1], result[2])) {

@@ -588,8 +665,10 @@ return false;

return true;
}
};
/** @inheritdoc */
some(predicate, self = false, recursive = false, thisArg) {
let result = this._getFirstDescendantNode(this._domNode, self, recursive);
XMLBuilderImpl.prototype.some = function (predicate, self, recursive, thisArg) {
if (self === void 0) { self = false; }
if (recursive === void 0) { recursive = false; }
var result = this._getFirstDescendantNode(this._domNode, self, recursive);
while (result[0]) {
const builder = new XMLBuilderImpl(result[0]);
var builder = new XMLBuilderImpl(result[0]);
if (predicate.call(thisArg, builder, result[1], result[2])) {

@@ -601,11 +680,13 @@ return true;

return false;
}
};
/** @inheritdoc */
toArray(self = false, recursive = false) {
let result = [];
this.each(node => result.push(node), self, recursive);
XMLBuilderImpl.prototype.toArray = function (self, recursive) {
if (self === void 0) { self = false; }
if (recursive === void 0) { recursive = false; }
var result = [];
this.each(function (node) { return result.push(node); }, self, recursive);
return result;
}
};
/** @inheritdoc */
toString(writerOptions) {
XMLBuilderImpl.prototype.toString = function (writerOptions) {
writerOptions = writerOptions || {};

@@ -616,5 +697,5 @@ if (writerOptions.format === undefined) {

return this._serialize(writerOptions);
}
};
/** @inheritdoc */
toObject(writerOptions) {
XMLBuilderImpl.prototype.toObject = function (writerOptions) {
writerOptions = writerOptions || {};

@@ -625,5 +706,5 @@ if (writerOptions.format === undefined) {

return this._serialize(writerOptions);
}
};
/** @inheritdoc */
end(writerOptions) {
XMLBuilderImpl.prototype.end = function (writerOptions) {
writerOptions = writerOptions || {};

@@ -634,3 +715,3 @@ if (writerOptions.format === undefined) {

return this.doc()._serialize(writerOptions);
}
};
/**

@@ -646,3 +727,3 @@ * Gets the next descendant of the given node of the tree rooted at `root`

*/
_getFirstDescendantNode(root, self, recursive) {
XMLBuilderImpl.prototype._getFirstDescendantNode = function (root, self, recursive) {
if (self)

@@ -654,3 +735,3 @@ return [this._domNode, 0, 0];

return [this._domNode.firstChild, 0, 1];
}
};
/**

@@ -668,3 +749,3 @@ * Gets the next descendant of the given node of the tree rooted at `root`

*/
_getNextDescendantNode(root, node, recursive, index, level) {
XMLBuilderImpl.prototype._getNextDescendantNode = function (root, node, recursive, index, level) {
if (recursive) {

@@ -680,3 +761,3 @@ // traverse child nodes

// traverse parent's next sibling
let parent = node.parentNode;
var parent = node.parentNode;
while (parent && parent !== root) {

@@ -696,3 +777,3 @@ if (parent.nextSibling)

return [null, -1, -1];
}
};
/**

@@ -703,17 +784,17 @@ * Converts the node into its string or object representation.

*/
_serialize(writerOptions) {
XMLBuilderImpl.prototype._serialize = function (writerOptions) {
if (writerOptions.format === "xml") {
const writer = new writers_1.XMLWriter(this._options);
var writer = new writers_1.XMLWriter(this._options);
return writer.serialize(this.node, writerOptions);
}
else if (writerOptions.format === "map") {
const writer = new writers_1.MapWriter(this._options);
var writer = new writers_1.MapWriter(this._options);
return writer.serialize(this.node, writerOptions);
}
else if (writerOptions.format === "object") {
const writer = new writers_1.ObjectWriter(this._options);
var writer = new writers_1.ObjectWriter(this._options);
return writer.serialize(this.node, writerOptions);
}
else if (writerOptions.format === "json") {
const writer = new writers_1.JSONWriter(this._options);
var writer = new writers_1.JSONWriter(this._options);
return writer.serialize(this.node, writerOptions);

@@ -724,3 +805,3 @@ }

}
}
};
/**

@@ -736,5 +817,5 @@ * Creates a dummy element node without adding it to the list of child nodes.

*/
_dummy() {
XMLBuilderImpl.prototype._dummy = function () {
return new XMLBuilderImpl(this._doc.createElement('dummy_node'));
}
};
/**

@@ -748,5 +829,5 @@ * Extracts a namespace and name from the given string.

*/
_extractNamespace(namespace, name, ele) {
XMLBuilderImpl.prototype._extractNamespace = function (namespace, name, ele) {
// extract from name
const atIndex = name.indexOf("@");
var atIndex = name.indexOf("@");
if (atIndex > 0) {

@@ -763,3 +844,3 @@ if (namespace === undefined)

// look-up namespace aliases
const alias = namespace.slice(1);
var alias = namespace.slice(1);
namespace = this._options.namespaceAlias[alias];

@@ -771,3 +852,3 @@ if (namespace === undefined) {

return [namespace, name];
}
};
/**

@@ -778,22 +859,33 @@ * Updates the element's namespace.

*/
_updateNamespace(ns) {
const ele = this._domNode;
XMLBuilderImpl.prototype._updateNamespace = function (ns) {
var e_3, _a, e_4, _b;
var ele = this._domNode;
if (util_2.Guard.isElementNode(ele) && ns !== null && ele.namespaceURI !== ns) {
const [elePrefix, eleLocalName] = algorithm_1.namespace_extractQName(ele.prefix ? ele.prefix + ':' + ele.localName : ele.localName);
var _c = __read(algorithm_1.namespace_extractQName(ele.prefix ? ele.prefix + ':' + ele.localName : ele.localName), 2), elePrefix = _c[0], eleLocalName = _c[1];
// re-create the element node if its namespace changed
// we can't simply change the namespaceURI since its read-only
const newEle = algorithm_1.create_element(this._doc, eleLocalName, ns, elePrefix);
for (const attr of ele.attributes) {
const attrQName = attr.prefix ? attr.prefix + ':' + attr.localName : attr.localName;
const [attrPrefix] = algorithm_1.namespace_extractQName(attrQName);
if (attrPrefix === null) {
newEle.setAttribute(attrQName, attr.value);
var newEle = algorithm_1.create_element(this._doc, eleLocalName, ns, elePrefix);
try {
for (var _d = __values(ele.attributes), _e = _d.next(); !_e.done; _e = _d.next()) {
var attr = _e.value;
var attrQName = attr.prefix ? attr.prefix + ':' + attr.localName : attr.localName;
var _f = __read(algorithm_1.namespace_extractQName(attrQName), 1), attrPrefix = _f[0];
if (attrPrefix === null) {
newEle.setAttribute(attrQName, attr.value);
}
else {
var newAttrNS = newEle.lookupNamespaceURI(attrPrefix);
newEle.setAttributeNS(newAttrNS, attrQName, attr.value);
}
}
else {
const newAttrNS = newEle.lookupNamespaceURI(attrPrefix);
newEle.setAttributeNS(newAttrNS, attrQName, attr.value);
}
catch (e_3_1) { e_3 = { error: e_3_1 }; }
finally {
try {
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
}
finally { if (e_3) throw e_3.error; }
}
// replace the new node in parent node
const parent = ele.parentNode;
var parent = ele.parentNode;
/* istanbul ignore next */

@@ -805,31 +897,45 @@ if (parent === null) {

this._domNode = newEle;
// check child nodes
for (const childNode of ele.childNodes) {
const newChildNode = childNode.cloneNode(true);
newEle.appendChild(newChildNode);
if (util_2.Guard.isElementNode(newChildNode)) {
const [newChildNodePrefix] = algorithm_1.namespace_extractQName(newChildNode.prefix ? newChildNode.prefix + ':' + newChildNode.localName : newChildNode.localName);
const newChildNodeNS = newEle.lookupNamespaceURI(newChildNodePrefix);
new XMLBuilderImpl(newChildNode)._updateNamespace(newChildNodeNS);
try {
// check child nodes
for (var _g = __values(ele.childNodes), _h = _g.next(); !_h.done; _h = _g.next()) {
var childNode = _h.value;
var newChildNode = childNode.cloneNode(true);
newEle.appendChild(newChildNode);
if (util_2.Guard.isElementNode(newChildNode)) {
var _j = __read(algorithm_1.namespace_extractQName(newChildNode.prefix ? newChildNode.prefix + ':' + newChildNode.localName : newChildNode.localName), 1), newChildNodePrefix = _j[0];
var newChildNodeNS = newEle.lookupNamespaceURI(newChildNodePrefix);
new XMLBuilderImpl(newChildNode)._updateNamespace(newChildNodeNS);
}
}
}
catch (e_4_1) { e_4 = { error: e_4_1 }; }
finally {
try {
if (_h && !_h.done && (_b = _g.return)) _b.call(_g);
}
finally { if (e_4) throw e_4.error; }
}
}
}
};
Object.defineProperty(XMLBuilderImpl.prototype, "_doc", {
/**
* Returns the document owning this node.
*/
get: function () {
var node = this.node;
if (util_2.Guard.isDocumentNode(node)) {
return node;
}
else {
var docNode = node.ownerDocument;
/* istanbul ignore next */
if (!docNode)
throw new Error("Owner document is null. " + this._debugInfo());
return docNode;
}
},
enumerable: true,
configurable: true
});
/**
* Returns the document owning this node.
*/
get _doc() {
const node = this.node;
if (util_2.Guard.isDocumentNode(node)) {
return node;
}
else {
const docNode = node.ownerDocument;
/* istanbul ignore next */
if (!docNode)
throw new Error("Owner document is null. " + this._debugInfo());
return docNode;
}
}
/**
* Returns debug information for this node.

@@ -839,7 +945,7 @@ *

*/
_debugInfo(name) {
const node = this.node;
const parentNode = node.parentNode;
XMLBuilderImpl.prototype._debugInfo = function (name) {
var node = this.node;
var parentNode = node.parentNode;
name = name || node.nodeName;
const parentName = parentNode ? parentNode.nodeName : '';
var parentName = parentNode ? parentNode.nodeName : '';
if (!parentName) {

@@ -851,20 +957,25 @@ return "node: <" + name + ">";

}
}
/**
* Gets or sets builder options.
*/
get _options() {
const doc = this._doc;
/* istanbul ignore next */
if (doc._xmlBuilderOptions === undefined) {
throw new Error("Builder options is not set.");
}
return doc._xmlBuilderOptions;
}
set _options(value) {
const doc = this._doc;
doc._xmlBuilderOptions = value;
}
}
};
Object.defineProperty(XMLBuilderImpl.prototype, "_options", {
/**
* Gets or sets builder options.
*/
get: function () {
var doc = this._doc;
/* istanbul ignore next */
if (doc._xmlBuilderOptions === undefined) {
throw new Error("Builder options is not set.");
}
return doc._xmlBuilderOptions;
},
set: function (value) {
var doc = this._doc;
doc._xmlBuilderOptions = value;
},
enumerable: true,
configurable: true
});
return XMLBuilderImpl;
}());
exports.XMLBuilderImpl = XMLBuilderImpl;
//# sourceMappingURL=XMLBuilderImpl.js.map

@@ -1,230 +0,1 @@

import { XMLBuilderCreateOptions, ExpandObject, XMLBuilder, XMLBuilderCB, XMLWriterOptions, JSONWriterOptions, ObjectWriterOptions, XMLSerializedAsObject, XMLSerializedAsObjectArray, MapWriterOptions, XMLSerializedAsMap, XMLSerializedAsMapArray, XMLBuilderCBCreateOptions } from './interfaces';
import { Node } from '@oozcitak/dom/lib/dom/interfaces';
/**
* Wraps a DOM node for use with XML builder with default options.
*
* @param node - DOM node
*
* @returns an XML builder
*/
export declare function builder(node: Node): XMLBuilder;
/**
* Wraps an array of DOM nodes for use with XML builder with default options.
*
* @param nodes - an array of DOM nodes
*
* @returns an array of XML builders
*/
export declare function builder(nodes: Node[]): XMLBuilder[];
/**
* Wraps a DOM node for use with XML builder with the given options.
*
* @param options - builder options
* @param node - DOM node
*
* @returns an XML builder
*/
export declare function builder(options: XMLBuilderCreateOptions, node: Node): XMLBuilder;
/**
* Wraps an array of DOM nodes for use with XML builder with the given options.
*
* @param options - builder options
* @param nodes - an array of DOM nodes
*
* @returns an array of XML builders
*/
export declare function builder(options: XMLBuilderCreateOptions, nodes: Node[]): XMLBuilder[];
/**
* Creates an XML document without any child nodes.
*
* @returns document node
*/
export declare function create(): XMLBuilder;
/**
* Creates an XML document without any child nodes with the given options.
*
* @param options - builder options
*
* @returns document node
*/
export declare function create(options: XMLBuilderCreateOptions): XMLBuilder;
/**
* Creates an XML document by parsing the given `contents`.
*
* @param contents - a string containing an XML document in either XML or JSON
* format or a JS object representing nodes to insert
*
* @returns document node
*/
export declare function create(contents: string | ExpandObject): XMLBuilder;
/**
* Creates an XML document.
*
* @param options - builder options
* @param contents - a string containing an XML document in either XML or JSON
* format or a JS object representing nodes to insert
*
* @returns document node
*/
export declare function create(options: XMLBuilderCreateOptions, contents: string | ExpandObject): XMLBuilder;
/**
* Creates a new document fragment without any child nodes.
*
* @returns document fragment node
*/
export declare function fragment(): XMLBuilder;
/**
* Creates a new document fragment with the given options.
*
* @param options - builder options
*
* @returns document fragment node
*/
export declare function fragment(options: XMLBuilderCreateOptions): XMLBuilder;
/**
* Creates a new document fragment by parsing the given `contents`.
*
* @param contents - a string containing an XML fragment in either XML or JSON
* format or a JS object representing nodes to insert
*
* @returns document fragment node
*/
export declare function fragment(contents: string | ExpandObject): XMLBuilder;
/**
* Creates a new document fragment.
*
* @param options - builder options
* @param contents - a string containing an XML fragment in either XML or JSON
* format or a JS object representing nodes to insert
*
* @returns document fragment node
*/
export declare function fragment(options: XMLBuilderCreateOptions, contents: string | ExpandObject): XMLBuilder;
/**
* Parses an XML document with the default options and converts it to an XML
* document string with the default writer options.
*
* @param contents - a string containing an XML document in either XML or JSON
* format or a JS object representing nodes to insert
*
* @returns document node
*/
export declare function convert(contents: string | ExpandObject): string;
/**
* Parses an XML document with the given options and converts it to an XML
* document string with the default writer options.
*
* @param builderOptions - builder options
* @param contents - a string containing an XML document in either XML or JSON
* format or a JS object representing nodes to insert
*
* @returns document node
*/
export declare function convert(builderOptions: XMLBuilderCreateOptions, contents: string | ExpandObject): string;
/**
* Parses an XML document with the default options and converts it an XML
* document string.
*
* @param contents - a string containing an XML document in either XML or JSON
* format or a JS object representing nodes to insert
* @param convertOptions - convert options
*
* @returns document node
*/
export declare function convert(contents: string | ExpandObject, convertOptions: XMLWriterOptions): string;
/**
* Parses an XML document with the default options and converts it a JSON string.
*
* @param contents - a string containing an XML document in either XML or JSON
* format or a JS object representing nodes to insert
* @param convertOptions - convert options
*
* @returns document node
*/
export declare function convert(contents: string | ExpandObject, convertOptions: JSONWriterOptions): string;
/**
* Parses an XML document with the default options and converts it to its object
* representation.
*
* @param contents - a string containing an XML document in either XML or JSON
* format or a JS object representing nodes to insert
* @param convertOptions - convert options
*
* @returns document node
*/
export declare function convert(contents: string | ExpandObject, convertOptions: ObjectWriterOptions): XMLSerializedAsObject | XMLSerializedAsObjectArray;
/**
* Parses an XML document with the default options and converts it to its object
* representation using ES6 maps.
*
* @param contents - a string containing an XML document in either XML or JSON
* format or a JS object representing nodes to insert
* @param convertOptions - convert options
*
* @returns document node
*/
export declare function convert(contents: string | ExpandObject, convertOptions: MapWriterOptions): XMLSerializedAsMap | XMLSerializedAsMapArray;
/**
* Parses an XML document with the given options and converts it to an XML
* document string.
*
* @param builderOptions - builder options
* @param contents - a string containing an XML document in either XML or JSON
* format or a JS object representing nodes to insert
* @param convertOptions - convert options
*
* @returns document node
*/
export declare function convert(builderOptions: XMLBuilderCreateOptions, contents: string | ExpandObject, convertOptions: XMLWriterOptions): string;
/**
* Parses an XML document with the given options and converts it to a JSON
* string.
*
* @param builderOptions - builder options
* @param contents - a string containing an XML document in either XML or JSON
* format or a JS object representing nodes to insert
* @param convertOptions - convert options
*
* @returns document node
*/
export declare function convert(builderOptions: XMLBuilderCreateOptions, contents: string | ExpandObject, convertOptions: JSONWriterOptions): string;
/**
* Parses an XML document with the given options and converts it to its object
* representation.
*
* @param builderOptions - builder options
* @param contents - a string containing an XML document in either XML or JSON
* format or a JS object representing nodes to insert
* @param convertOptions - convert options
*
* @returns document node
*/
export declare function convert(builderOptions: XMLBuilderCreateOptions, contents: string | ExpandObject, convertOptions: ObjectWriterOptions): XMLSerializedAsObject | XMLSerializedAsObjectArray;
/**
* Parses an XML document with the given options and converts it to its object
* representation using ES6 maps.
*
* @param builderOptions - builder options
* @param contents - a string containing an XML document in either XML or JSON
* format or a JS object representing nodes to insert
* @param convertOptions - convert options
*
* @returns document node
*/
export declare function convert(builderOptions: XMLBuilderCreateOptions, contents: string | ExpandObject, convertOptions: MapWriterOptions): XMLSerializedAsMap | XMLSerializedAsMapArray;
/**
* Creates an XML builder which serializes the document in chunks.
*
* @param options - callback builder options
*
* @returns callback builder
*/
export declare function createCB(options?: XMLBuilderCBCreateOptions): XMLBuilderCB;
/**
* Creates an XML builder which serializes the fragment in chunks.
*
* @param options - callback builder options
*
* @returns callback builder
*/
export declare function fragmentCB(options?: XMLBuilderCBCreateOptions): XMLBuilderCB;
export { builder, create, fragment, convert, createCB, fragmentCB } from "./builder";
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const interfaces_1 = require("./interfaces");
const util_1 = require("@oozcitak/util");
const util_2 = require("@oozcitak/dom/lib/util");
const builder_1 = require("./builder");
const dom_1 = require("./builder/dom");
const util_3 = require("util");
const builder_2 = require("./builder");
/** @inheritdoc */
function builder(p1, p2) {
const options = formatBuilderOptions(isXMLBuilderCreateOptions(p1) ? p1 : interfaces_1.DefaultBuilderOptions);
const nodes = util_2.Guard.isNode(p1) || util_3.isArray(p1) ? p1 : p2;
if (nodes === undefined) {
throw new Error("Invalid arguments.");
}
if (util_3.isArray(nodes)) {
const builders = [];
for (let i = 0; i < nodes.length; i++) {
const builder = new builder_1.XMLBuilderImpl(nodes[i]);
builder.set(options);
builders.push(builder);
}
return builders;
}
else {
const builder = new builder_1.XMLBuilderImpl(nodes);
builder.set(options);
return builder;
}
}
exports.builder = builder;
/** @inheritdoc */
function create(p1, p2) {
const options = formatBuilderOptions(p1 === undefined || isXMLBuilderCreateOptions(p1) ?
p1 : interfaces_1.DefaultBuilderOptions);
const contents = isXMLBuilderCreateOptions(p1) ? p2 : p1;
let builder;
if (contents === undefined) {
// empty document
const doc = dom_1.createDocument();
builder = new builder_1.XMLBuilderImpl(doc);
setOptions(doc, options);
}
else if (util_1.isObject(contents)) {
// JS object
const doc = dom_1.createDocument();
builder = new builder_1.XMLBuilderImpl(doc);
setOptions(doc, options);
builder.ele(contents);
}
else if (/^\s*</.test(contents)) {
// XML document
const domParser = dom_1.createParser();
const doc = domParser.parseFromString(dom_1.sanitizeInput(contents, options.invalidCharReplacement), "text/xml");
dom_1.throwIfParserError(doc);
builder = new builder_1.XMLBuilderImpl(doc);
setOptions(doc, options);
}
else {
// JSON
const doc = dom_1.createDocument();
builder = new builder_1.XMLBuilderImpl(doc);
setOptions(doc, options);
const obj = JSON.parse(contents);
builder.ele(obj);
}
return builder;
}
exports.create = create;
/** @inheritdoc */
function fragment(p1, p2) {
const options = formatBuilderOptions(p1 === undefined || isXMLBuilderCreateOptions(p1) ?
p1 : interfaces_1.DefaultBuilderOptions);
const contents = isXMLBuilderCreateOptions(p1) ? p2 : p1;
let builder;
if (contents === undefined) {
// empty fragment
const doc = dom_1.createDocument();
setOptions(doc, options, true);
builder = new builder_1.XMLBuilderImpl(doc.createDocumentFragment());
}
else if (util_1.isObject(contents)) {
// JS object
const doc = dom_1.createDocument();
setOptions(doc, options, true);
builder = new builder_1.XMLBuilderImpl(doc.createDocumentFragment());
builder.ele(contents);
}
else if (/^\s*</.test(contents)) {
// XML document
const domParser = dom_1.createParser();
const doc = domParser.parseFromString("<TEMP_ROOT>" +
dom_1.sanitizeInput(contents, options.invalidCharReplacement) + "</TEMP_ROOT>", "text/xml");
dom_1.throwIfParserError(doc);
setOptions(doc, options, true);
/* istanbul ignore next */
if (doc.documentElement === null) {
throw new Error("Document element is null.");
}
const frag = doc.createDocumentFragment();
for (const child of doc.documentElement.childNodes) {
const newChild = doc.importNode(child, true);
frag.appendChild(newChild);
}
builder = new builder_1.XMLBuilderImpl(frag);
}
else {
// JSON
const doc = dom_1.createDocument();
setOptions(doc, options, true);
builder = new builder_1.XMLBuilderImpl(doc.createDocumentFragment());
const obj = JSON.parse(contents);
builder.ele(obj);
}
return builder;
}
exports.fragment = fragment;
/** @inheritdoc */
function convert(p1, p2, p3) {
let builderOptions;
let contents;
let convertOptions;
if (isXMLBuilderCreateOptions(p1) && p2 !== undefined) {
builderOptions = p1;
contents = p2;
convertOptions = p3;
}
else {
builderOptions = interfaces_1.DefaultBuilderOptions;
contents = p1;
convertOptions = p2 || undefined;
}
return create(builderOptions, contents).end(convertOptions);
}
exports.convert = convert;
/**
* Creates an XML builder which serializes the document in chunks.
*
* @param options - callback builder options
*
* @returns callback builder
*/
function createCB(options) {
return new builder_2.XMLBuilderCBImpl(options);
}
exports.createCB = createCB;
/**
* Creates an XML builder which serializes the fragment in chunks.
*
* @param options - callback builder options
*
* @returns callback builder
*/
function fragmentCB(options) {
return new builder_2.XMLBuilderCBImpl(options, true);
}
exports.fragmentCB = fragmentCB;
function isXMLBuilderCreateOptions(obj) {
if (!util_1.isPlainObject(obj))
return false;
for (const key in obj) {
/* istanbul ignore else */
if (obj.hasOwnProperty(key)) {
if (!interfaces_1.XMLBuilderOptionKeys.has(key))
return false;
}
}
return true;
}
function formatBuilderOptions(createOptions = {}) {
const options = util_1.applyDefaults(createOptions, interfaces_1.DefaultBuilderOptions);
if (options.convert.att.length === 0 ||
options.convert.ins.length === 0 ||
options.convert.text.length === 0 ||
options.convert.cdata.length === 0 ||
options.convert.comment.length === 0) {
throw new Error("JS object converter strings cannot be zero length.");
}
return options;
}
function setOptions(doc, options, isFragment) {
const docWithSettings = doc;
docWithSettings._xmlBuilderOptions = options;
docWithSettings._isFragment = isFragment;
}
var builder_1 = require("./builder");
exports.builder = builder_1.builder;
exports.create = builder_1.create;
exports.fragment = builder_1.fragment;
exports.convert = builder_1.convert;
exports.createCB = builder_1.createCB;
exports.fragmentCB = builder_1.fragmentCB;
//# sourceMappingURL=index.js.map

@@ -6,3 +6,3 @@ "use strict";

*/
class BaseCBWriter {
var BaseCBWriter = /** @class */ (function () {
/**

@@ -13,3 +13,3 @@ * Initializes a new instance of `BaseCBWriter`.

*/
constructor(builderOptions) {
function BaseCBWriter(builderOptions) {
/**

@@ -22,4 +22,5 @@ * Gets the current depth of the XML tree.

}
}
return BaseCBWriter;
}());
exports.BaseCBWriter = BaseCBWriter;
//# sourceMappingURL=BaseCBWriter.js.map
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
const BaseCBWriter_1 = require("./BaseCBWriter");
var BaseCBWriter_1 = require("./BaseCBWriter");
/**
* Serializes XML nodes.
*/
class JSONCBWriter extends BaseCBWriter_1.BaseCBWriter {
var JSONCBWriter = /** @class */ (function (_super) {
__extends(JSONCBWriter, _super);
/**

@@ -13,17 +27,18 @@ * Initializes a new instance of `BaseCBWriter`.

*/
constructor(builderOptions) {
super(builderOptions);
this._hasChildren = [];
this._additionalLevel = 0;
function JSONCBWriter(builderOptions) {
var _this = _super.call(this, builderOptions) || this;
_this._hasChildren = [];
_this._additionalLevel = 0;
return _this;
}
/** @inheritdoc */
declaration(version, encoding, standalone) {
JSONCBWriter.prototype.declaration = function (version, encoding, standalone) {
return "";
}
};
/** @inheritdoc */
docType(name, publicId, systemId) {
JSONCBWriter.prototype.docType = function (name, publicId, systemId) {
return "";
}
};
/** @inheritdoc */
comment(data) {
JSONCBWriter.prototype.comment = function (data) {
// { "!": "hello" }

@@ -33,5 +48,5 @@ return this._comma() + this._beginLine() + "{" + this._sep() +

this._val(data) + this._sep() + "}";
}
};
/** @inheritdoc */
text(data) {
JSONCBWriter.prototype.text = function (data) {
// { "#": "hello" }

@@ -41,5 +56,5 @@ return this._comma() + this._beginLine() + "{" + this._sep() +

this._val(data) + this._sep() + "}";
}
};
/** @inheritdoc */
instruction(target, data) {
JSONCBWriter.prototype.instruction = function (target, data) {
// { "?": "target hello" }

@@ -49,5 +64,5 @@ return this._comma() + this._beginLine() + "{" + this._sep() +

this._val(data ? target + " " + data : target) + this._sep() + "}";
}
};
/** @inheritdoc */
cdata(data) {
JSONCBWriter.prototype.cdata = function (data) {
// { "$": "hello" }

@@ -57,5 +72,5 @@ return this._comma() + this._beginLine() + "{" + this._sep() +

this._val(data) + this._sep() + "}";
}
};
/** @inheritdoc */
attribute(name, value) {
JSONCBWriter.prototype.attribute = function (name, value) {
// { "@name": "val" }

@@ -65,7 +80,7 @@ return this._comma() + this._beginLine(1) + "{" + this._sep() +

this._val(value) + this._sep() + "}";
}
};
/** @inheritdoc */
openTagBegin(name) {
JSONCBWriter.prototype.openTagBegin = function (name) {
// { "node": { "#": [
let str = this._comma() + this._beginLine() + "{" + this._sep() + this._key(name) + this._sep() + "{";
var str = this._comma() + this._beginLine() + "{" + this._sep() + this._key(name) + this._sep() + "{";
this._additionalLevel++;

@@ -76,7 +91,7 @@ this.hasData = true;

return str;
}
};
/** @inheritdoc */
openTagEnd(name, selfClosing, voidElement) {
JSONCBWriter.prototype.openTagEnd = function (name, selfClosing, voidElement) {
if (selfClosing) {
let str = this._sep() + "]";
var str = this._sep() + "]";
this._additionalLevel--;

@@ -89,15 +104,15 @@ str += this._beginLine() + "}" + this._sep() + "}";

}
}
};
/** @inheritdoc */
closeTag(name) {
JSONCBWriter.prototype.closeTag = function (name) {
// ] } }
let str = this._beginLine() + "]";
var str = this._beginLine() + "]";
this._additionalLevel--;
str += this._beginLine() + "}" + this._sep() + "}";
return str;
}
};
/** @inheritdoc */
beginElement(name) { }
JSONCBWriter.prototype.beginElement = function (name) { };
/** @inheritdoc */
endElement(name) { this._hasChildren.pop(); }
JSONCBWriter.prototype.endElement = function (name) { this._hasChildren.pop(); };
/**

@@ -107,3 +122,4 @@ * Produces characters to be prepended to a line of string in pretty-print

*/
_beginLine(additionalOffset = 0) {
JSONCBWriter.prototype._beginLine = function (additionalOffset) {
if (additionalOffset === void 0) { additionalOffset = 0; }
if (this._writerOptions.prettyPrint) {

@@ -116,3 +132,3 @@ return (this.hasData ? this._writerOptions.newline : "") +

}
}
};
/**

@@ -123,3 +139,3 @@ * Produces an indentation string.

*/
_indent(level) {
JSONCBWriter.prototype._indent = function (level) {
if (level + this._additionalLevel <= 0) {

@@ -131,8 +147,8 @@ return "";

}
}
};
/**
* Produces a comma before a child node if it has previous siblings.
*/
_comma() {
const str = (this._hasChildren[this._hasChildren.length - 1] ? "," : "");
JSONCBWriter.prototype._comma = function () {
var str = (this._hasChildren[this._hasChildren.length - 1] ? "," : "");
if (this._hasChildren.length > 0) {

@@ -142,23 +158,24 @@ this._hasChildren[this._hasChildren.length - 1] = true;

return str;
}
};
/**
* Produces a separator string.
*/
_sep() {
JSONCBWriter.prototype._sep = function () {
return (this._writerOptions.prettyPrint ? " " : "");
}
};
/**
* Produces a JSON key string delimited with double quotes.
*/
_key(key) {
JSONCBWriter.prototype._key = function (key) {
return "\"" + key + "\":";
}
};
/**
* Produces a JSON value string delimited with double quotes.
*/
_val(val) {
JSONCBWriter.prototype._val = function (val) {
return "\"" + val + "\"";
}
}
};
return JSONCBWriter;
}(BaseCBWriter_1.BaseCBWriter));
exports.JSONCBWriter = JSONCBWriter;
//# sourceMappingURL=JSONCBWriter.js.map
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
Object.defineProperty(exports, "__esModule", { value: true });
const ObjectWriter_1 = require("./ObjectWriter");
const util_1 = require("@oozcitak/util");
const BaseWriter_1 = require("./BaseWriter");
var ObjectWriter_1 = require("./ObjectWriter");
var util_1 = require("@oozcitak/util");
var BaseWriter_1 = require("./BaseWriter");
/**
* Serializes XML nodes into a JSON string.
*/
class JSONWriter extends BaseWriter_1.BaseWriter {
var JSONWriter = /** @class */ (function (_super) {
__extends(JSONWriter, _super);
function JSONWriter() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**

@@ -16,5 +44,5 @@ * Produces an XML serialization of the given node.

*/
serialize(node, writerOptions) {
JSONWriter.prototype.serialize = function (node, writerOptions) {
// provide default options
const options = util_1.applyDefaults(writerOptions, {
var options = util_1.applyDefaults(writerOptions, {
wellFormed: false,

@@ -29,3 +57,3 @@ noDoubleEncoding: false,

// convert to object
const objectWriterOptions = util_1.applyDefaults(options, {
var objectWriterOptions = util_1.applyDefaults(options, {
format: "object",

@@ -35,7 +63,7 @@ wellFormed: false,

});
const objectWriter = new ObjectWriter_1.ObjectWriter(this._builderOptions);
const val = objectWriter.serialize(node, objectWriterOptions);
var objectWriter = new ObjectWriter_1.ObjectWriter(this._builderOptions);
var val = objectWriter.serialize(node, objectWriterOptions);
// recursively convert object into JSON string
return this._beginLine(options, 0) + this._convertObject(val, options);
}
};
/**

@@ -48,18 +76,31 @@ * Produces an XML serialization of the given object.

*/
_convertObject(obj, options, level = 0) {
let markup = '';
const isLeaf = this._isLeafNode(obj);
JSONWriter.prototype._convertObject = function (obj, options, level) {
var e_1, _a;
var _this = this;
if (level === void 0) { level = 0; }
var markup = '';
var isLeaf = this._isLeafNode(obj);
if (util_1.isArray(obj)) {
markup += '[';
const len = obj.length;
let i = 0;
for (const val of obj) {
markup += this._endLine(options, level + 1) +
this._beginLine(options, level + 1) +
this._convertObject(val, options, level + 1);
if (i < len - 1) {
markup += ',';
var len = obj.length;
var i = 0;
try {
for (var obj_1 = __values(obj), obj_1_1 = obj_1.next(); !obj_1_1.done; obj_1_1 = obj_1.next()) {
var val = obj_1_1.value;
markup += this._endLine(options, level + 1) +
this._beginLine(options, level + 1) +
this._convertObject(val, options, level + 1);
if (i < len - 1) {
markup += ',';
}
i++;
}
i++;
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (obj_1_1 && !obj_1_1.done && (_a = obj_1.return)) _a.call(obj_1);
}
finally { if (e_1) throw e_1.error; }
}
markup += this._endLine(options, level) + this._beginLine(options, level);

@@ -70,5 +111,5 @@ markup += ']';

markup += '{';
const len = util_1.objectLength(obj);
let i = 0;
util_1.forEachObject(obj, (key, val) => {
var len_1 = util_1.objectLength(obj);
var i_1 = 0;
util_1.forEachObject(obj, function (key, val) {
if (isLeaf && options.prettyPrint) {

@@ -78,3 +119,3 @@ markup += ' ';

else {
markup += this._endLine(options, level + 1) + this._beginLine(options, level + 1);
markup += _this._endLine(options, level + 1) + _this._beginLine(options, level + 1);
}

@@ -85,7 +126,7 @@ markup += '"' + key + '":';

}
markup += this._convertObject(val, options, level + 1);
if (i < len - 1) {
markup += _this._convertObject(val, options, level + 1);
if (i_1 < len_1 - 1) {
markup += ',';
}
i++;
i_1++;
}, this);

@@ -104,3 +145,3 @@ if (isLeaf && options.prettyPrint) {

return markup;
}
};
/**

@@ -113,3 +154,3 @@ * Produces characters to be prepended to a line of string in pretty-print

*/
_beginLine(options, level) {
JSONWriter.prototype._beginLine = function (options, level) {
if (!options.prettyPrint) {

@@ -119,3 +160,3 @@ return '';

else {
const indentLevel = options.offset + level + 1;
var indentLevel = options.offset + level + 1;
if (indentLevel > 0) {

@@ -126,3 +167,3 @@ return new Array(indentLevel).join(options.indent);

return '';
}
};
/**

@@ -135,3 +176,3 @@ * Produces characters to be appended to a line of string in pretty-print

*/
_endLine(options, level) {
JSONWriter.prototype._endLine = function (options, level) {
if (!options.prettyPrint) {

@@ -143,3 +184,3 @@ return '';

}
}
};
/**

@@ -150,5 +191,5 @@ * Determines if an object is a leaf node.

*/
_isLeafNode(obj) {
JSONWriter.prototype._isLeafNode = function (obj) {
return this._descendantCount(obj) <= 1;
}
};
/**

@@ -160,8 +201,10 @@ * Counts the number of descendants of the given object.

*/
_descendantCount(obj, count = 0) {
JSONWriter.prototype._descendantCount = function (obj, count) {
var _this = this;
if (count === void 0) { count = 0; }
if (util_1.isArray(obj)) {
util_1.forEachArray(obj, val => count += this._descendantCount(val, count), this);
util_1.forEachArray(obj, function (val) { return count += _this._descendantCount(val, count); }, this);
}
else if (util_1.isObject(obj)) {
util_1.forEachObject(obj, (key, val) => count += this._descendantCount(val, count), this);
util_1.forEachObject(obj, function (key, val) { return count += _this._descendantCount(val, count); }, this);
}

@@ -172,5 +215,6 @@ else {

return count;
}
}
};
return JSONWriter;
}(BaseWriter_1.BaseWriter));
exports.JSONWriter = JSONWriter;
//# sourceMappingURL=JSONWriter.js.map
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
const util_1 = require("@oozcitak/util");
const ObjectWriter_1 = require("./ObjectWriter");
const BaseWriter_1 = require("./BaseWriter");
var util_1 = require("@oozcitak/util");
var ObjectWriter_1 = require("./ObjectWriter");
var BaseWriter_1 = require("./BaseWriter");
/**
* Serializes XML nodes into ES6 maps and arrays.
*/
class MapWriter extends BaseWriter_1.BaseWriter {
var MapWriter = /** @class */ (function (_super) {
__extends(MapWriter, _super);
function MapWriter() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**

@@ -16,4 +33,4 @@ * Produces an XML serialization of the given node.

*/
serialize(node, writerOptions) {
const options = util_1.applyDefaults(writerOptions, {
MapWriter.prototype.serialize = function (node, writerOptions) {
var options = util_1.applyDefaults(writerOptions, {
format: "map",

@@ -25,3 +42,3 @@ wellFormed: false,

// convert to object
const objectWriterOptions = util_1.applyDefaults(options, {
var objectWriterOptions = util_1.applyDefaults(options, {
format: "object",

@@ -31,7 +48,7 @@ wellFormed: false,

});
const objectWriter = new ObjectWriter_1.ObjectWriter(this._builderOptions);
const val = objectWriter.serialize(node, objectWriterOptions);
var objectWriter = new ObjectWriter_1.ObjectWriter(this._builderOptions);
var val = objectWriter.serialize(node, objectWriterOptions);
// recursively convert object into Map
return this._convertObject(val);
}
};
/**

@@ -42,5 +59,5 @@ * Recursively converts a JS object into an ES5 map.

*/
_convertObject(obj) {
MapWriter.prototype._convertObject = function (obj) {
if (util_1.isArray(obj)) {
for (let i = 0; i < obj.length; i++) {
for (var i = 0; i < obj.length; i++) {
obj[i] = this._convertObject(obj[i]);

@@ -51,4 +68,4 @@ }

else if (util_1.isObject(obj)) {
const map = new Map();
for (const key in obj) {
var map = new Map();
for (var key in obj) {
map.set(key, this._convertObject(obj[key]));

@@ -61,5 +78,6 @@ }

}
}
}
};
return MapWriter;
}(BaseWriter_1.BaseWriter));
exports.MapWriter = MapWriter;
//# sourceMappingURL=MapWriter.js.map
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
Object.defineProperty(exports, "__esModule", { value: true });
const util_1 = require("@oozcitak/util");
const interfaces_1 = require("@oozcitak/dom/lib/dom/interfaces");
const BaseWriter_1 = require("./BaseWriter");
var util_1 = require("@oozcitak/util");
var interfaces_1 = require("@oozcitak/dom/lib/dom/interfaces");
var BaseWriter_1 = require("./BaseWriter");
/**
* Serializes XML nodes into objects and arrays.
*/
class ObjectWriter extends BaseWriter_1.BaseWriter {
var ObjectWriter = /** @class */ (function (_super) {
__extends(ObjectWriter, _super);
function ObjectWriter() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**

@@ -16,4 +44,4 @@ * Produces an XML serialization of the given node.

*/
serialize(node, writerOptions) {
const options = util_1.applyDefaults(writerOptions, {
ObjectWriter.prototype.serialize = function (node, writerOptions) {
var options = util_1.applyDefaults(writerOptions, {
format: "object",

@@ -68,16 +96,17 @@ wellFormed: false,

return this._process(this._currentList, options);
}
_process(items, options) {
};
ObjectWriter.prototype._process = function (items, options) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
if (items.length === 0)
return {};
// determine if there are non-unique element names
const namesSeen = {};
let hasNonUniqueNames = false;
let textCount = 0;
let commentCount = 0;
let instructionCount = 0;
let cdataCount = 0;
for (let i = 0; i < items.length; i++) {
const item = items[i];
const key = Object.keys(item)[0];
var namesSeen = {};
var hasNonUniqueNames = false;
var textCount = 0;
var commentCount = 0;
var instructionCount = 0;
var cdataCount = 0;
for (var i = 0; i < items.length; i++) {
var item = items[i];
var key = Object.keys(item)[0];
switch (key) {

@@ -108,7 +137,7 @@ case "@":

}
const defAttrKey = this._getAttrKey();
const defTextKey = this._getNodeKey(interfaces_1.NodeType.Text);
const defCommentKey = this._getNodeKey(interfaces_1.NodeType.Comment);
const defInstructionKey = this._getNodeKey(interfaces_1.NodeType.ProcessingInstruction);
const defCdataKey = this._getNodeKey(interfaces_1.NodeType.CData);
var defAttrKey = this._getAttrKey();
var defTextKey = this._getNodeKey(interfaces_1.NodeType.Text);
var defCommentKey = this._getNodeKey(interfaces_1.NodeType.Comment);
var defInstructionKey = this._getNodeKey(interfaces_1.NodeType.ProcessingInstruction);
var defCdataKey = this._getNodeKey(interfaces_1.NodeType.CData);
if (textCount === 1 && items.length === 1 && util_1.isString(items[0]["#"])) {

@@ -121,45 +150,45 @@ // special case of an element node with a single text node

// return an array with mixed content notation
const result = [];
const obj = { [defTextKey]: result };
for (let i = 0; i < items.length; i++) {
const item = items[i];
const key = Object.keys(item)[0];
var result = [];
var obj = (_a = {}, _a[defTextKey] = result, _a);
for (var i = 0; i < items.length; i++) {
var item = items[i];
var key = Object.keys(item)[0];
switch (key) {
case "@":
const attrs = item["@"];
const attrKeys = Object.keys(attrs);
var attrs = item["@"];
var attrKeys = Object.keys(attrs);
if (attrKeys.length === 1) {
result.push({ [defAttrKey + attrKeys[0]]: attrs[attrKeys[0]] });
result.push((_b = {}, _b[defAttrKey + attrKeys[0]] = attrs[attrKeys[0]], _b));
}
else {
result.push({ [defAttrKey]: item["@"] });
result.push((_c = {}, _c[defAttrKey] = item["@"], _c));
}
break;
case "#":
result.push({ [defTextKey]: item["#"] });
result.push((_d = {}, _d[defTextKey] = item["#"], _d));
break;
case "!":
result.push({ [defCommentKey]: item["!"] });
result.push((_e = {}, _e[defCommentKey] = item["!"], _e));
break;
case "?":
result.push({ [defInstructionKey]: item["?"] });
result.push((_f = {}, _f[defInstructionKey] = item["?"], _f));
break;
case "$":
result.push({ [defCdataKey]: item["$"] });
result.push((_g = {}, _g[defCdataKey] = item["$"], _g));
break;
default:
// element node
const ele = item;
var ele = item;
if (ele[key].length !== 0 && util_1.isArray(ele[key][0])) {
// group of element nodes
const eleGroup = [];
const listOfLists = ele[key];
for (let i = 0; i < listOfLists.length; i++) {
eleGroup.push(this._process(listOfLists[i], options));
var eleGroup = [];
var listOfLists = ele[key];
for (var i_1 = 0; i_1 < listOfLists.length; i_1++) {
eleGroup.push(this._process(listOfLists[i_1], options));
}
result.push({ [key]: eleGroup });
result.push((_h = {}, _h[key] = eleGroup, _h));
}
else {
// single element node
result.push({ [key]: this._process(ele[key], options) });
result.push((_j = {}, _j[key] = this._process(ele[key], options), _j));
}

@@ -174,16 +203,16 @@ break;

// return an object while prefixing data node keys
let textId = 1;
let commentId = 1;
let instructionId = 1;
let cdataId = 1;
const obj = {};
for (let i = 0; i < items.length; i++) {
const item = items[i];
const key = Object.keys(item)[0];
var textId = 1;
var commentId = 1;
var instructionId = 1;
var cdataId = 1;
var obj = {};
for (var i = 0; i < items.length; i++) {
var item = items[i];
var key = Object.keys(item)[0];
switch (key) {
case "@":
const attrs = item["@"];
const attrKeys = Object.keys(attrs);
var attrs = item["@"];
var attrKeys = Object.keys(attrs);
if (!options.group || attrKeys.length === 1) {
for (const attrName in attrs) {
for (var attrName in attrs) {
obj[defAttrKey + attrName] = attrs[attrName];

@@ -210,9 +239,9 @@ }

// element node
const ele = item;
var ele = item;
if (ele[key].length !== 0 && util_1.isArray(ele[key][0])) {
// group of element nodes
const eleGroup = [];
const listOfLists = ele[key];
for (let i = 0; i < listOfLists.length; i++) {
eleGroup.push(this._process(listOfLists[i], options));
var eleGroup = [];
var listOfLists = ele[key];
for (var i_2 = 0; i_2 < listOfLists.length; i_2++) {
eleGroup.push(this._process(listOfLists[i_2], options));
}

@@ -230,27 +259,39 @@ obj[key] = eleGroup;

}
}
_processSpecItem(item, obj, group, defKey, count, id) {
};
ObjectWriter.prototype._processSpecItem = function (item, obj, group, defKey, count, id) {
var e_1, _a;
if (!group && util_1.isArray(item) && count + item.length > 2) {
for (const subItem of item) {
const key = defKey + (id++).toString();
obj[key] = subItem;
try {
for (var item_1 = __values(item), item_1_1 = item_1.next(); !item_1_1.done; item_1_1 = item_1.next()) {
var subItem = item_1_1.value;
var key = defKey + (id++).toString();
obj[key] = subItem;
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (item_1_1 && !item_1_1.done && (_a = item_1.return)) _a.call(item_1);
}
finally { if (e_1) throw e_1.error; }
}
}
else {
const key = count > 1 ? defKey + (id++).toString() : defKey;
var key = count > 1 ? defKey + (id++).toString() : defKey;
obj[key] = item;
}
return id;
}
};
/** @inheritdoc */
beginElement(name) {
const childItems = [];
ObjectWriter.prototype.beginElement = function (name) {
var _a, _b;
var childItems = [];
if (this._currentList.length === 0) {
this._currentList.push({ [name]: childItems });
this._currentList.push((_a = {}, _a[name] = childItems, _a));
}
else {
const lastItem = this._currentList[this._currentList.length - 1];
var lastItem = this._currentList[this._currentList.length - 1];
if (this._isElementNode(lastItem, name)) {
if (lastItem[name].length !== 0 && util_1.isArray(lastItem[name][0])) {
const listOfLists = lastItem[name];
var listOfLists = lastItem[name];
listOfLists.push(childItems);

@@ -263,3 +304,3 @@ }

else {
this._currentList.push({ [name]: childItems });
this._currentList.push((_b = {}, _b[name] = childItems, _b));
}

@@ -275,14 +316,15 @@ }

this._currentList = childItems;
}
};
/** @inheritdoc */
endElement() {
ObjectWriter.prototype.endElement = function () {
this._currentList = this._listRegister[--this._currentIndex];
}
};
/** @inheritdoc */
attribute(name, value) {
ObjectWriter.prototype.attribute = function (name, value) {
var _a, _b;
if (this._currentList.length === 0) {
this._currentList.push({ "@": { [name]: value } });
this._currentList.push({ "@": (_a = {}, _a[name] = value, _a) });
}
else {
const lastItem = this._currentList[this._currentList.length - 1];
var lastItem = this._currentList[this._currentList.length - 1];
/* istanbul ignore else */

@@ -293,8 +335,8 @@ if (this._isAttrNode(lastItem)) {

else {
this._currentList.push({ "@": { [name]: value } });
this._currentList.push({ "@": (_b = {}, _b[name] = value, _b) });
}
}
}
};
/** @inheritdoc */
comment(data) {
ObjectWriter.prototype.comment = function (data) {
if (this._currentList.length === 0) {

@@ -304,3 +346,3 @@ this._currentList.push({ "!": data });

else {
const lastItem = this._currentList[this._currentList.length - 1];
var lastItem = this._currentList[this._currentList.length - 1];
if (this._isCommentNode(lastItem)) {

@@ -318,5 +360,5 @@ if (util_1.isArray(lastItem["!"])) {

}
}
};
/** @inheritdoc */
text(data) {
ObjectWriter.prototype.text = function (data) {
if (this._currentList.length === 0) {

@@ -326,3 +368,3 @@ this._currentList.push({ "#": data });

else {
const lastItem = this._currentList[this._currentList.length - 1];
var lastItem = this._currentList[this._currentList.length - 1];
if (this._isTextNode(lastItem)) {

@@ -340,6 +382,6 @@ if (util_1.isArray(lastItem["#"])) {

}
}
};
/** @inheritdoc */
instruction(target, data) {
const value = (data === "" ? target : target + " " + data);
ObjectWriter.prototype.instruction = function (target, data) {
var value = (data === "" ? target : target + " " + data);
if (this._currentList.length === 0) {

@@ -349,3 +391,3 @@ this._currentList.push({ "?": value });

else {
const lastItem = this._currentList[this._currentList.length - 1];
var lastItem = this._currentList[this._currentList.length - 1];
if (this._isInstructionNode(lastItem)) {

@@ -363,5 +405,5 @@ if (util_1.isArray(lastItem["?"])) {

}
}
};
/** @inheritdoc */
cdata(data) {
ObjectWriter.prototype.cdata = function (data) {
if (this._currentList.length === 0) {

@@ -371,3 +413,3 @@ this._currentList.push({ "$": data });

else {
const lastItem = this._currentList[this._currentList.length - 1];
var lastItem = this._currentList[this._currentList.length - 1];
if (this._isCDATANode(lastItem)) {

@@ -385,27 +427,27 @@ if (util_1.isArray(lastItem["$"])) {

}
}
_isAttrNode(x) {
};
ObjectWriter.prototype._isAttrNode = function (x) {
return "@" in x;
}
_isTextNode(x) {
};
ObjectWriter.prototype._isTextNode = function (x) {
return "#" in x;
}
_isCommentNode(x) {
};
ObjectWriter.prototype._isCommentNode = function (x) {
return "!" in x;
}
_isInstructionNode(x) {
};
ObjectWriter.prototype._isInstructionNode = function (x) {
return "?" in x;
}
_isCDATANode(x) {
};
ObjectWriter.prototype._isCDATANode = function (x) {
return "$" in x;
}
_isElementNode(x, name) {
};
ObjectWriter.prototype._isElementNode = function (x, name) {
return name in x;
}
};
/**
* Returns an object key for an attribute or namespace declaration.
*/
_getAttrKey() {
ObjectWriter.prototype._getAttrKey = function () {
return this._builderOptions.convert.att;
}
};
/**

@@ -416,3 +458,3 @@ * Returns an object key for the given node type.

*/
_getNodeKey(nodeType) {
ObjectWriter.prototype._getNodeKey = function (nodeType) {
switch (nodeType) {

@@ -431,5 +473,6 @@ case interfaces_1.NodeType.Comment:

}
}
}
};
return ObjectWriter;
}(BaseWriter_1.BaseWriter));
exports.ObjectWriter = ObjectWriter;
//# sourceMappingURL=ObjectWriter.js.map
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
const BaseCBWriter_1 = require("./BaseCBWriter");
var BaseCBWriter_1 = require("./BaseCBWriter");
/**
* Serializes XML nodes.
*/
class XMLCBWriter extends BaseCBWriter_1.BaseCBWriter {
var XMLCBWriter = /** @class */ (function (_super) {
__extends(XMLCBWriter, _super);
/**

@@ -13,9 +27,10 @@ * Initializes a new instance of `BaseCBWriter`.

*/
constructor(builderOptions) {
super(builderOptions);
this._lineLength = 0;
function XMLCBWriter(builderOptions) {
var _this = _super.call(this, builderOptions) || this;
_this._lineLength = 0;
return _this;
}
/** @inheritdoc */
declaration(version, encoding, standalone) {
let markup = this._beginLine() + "<?xml";
XMLCBWriter.prototype.declaration = function (version, encoding, standalone) {
var markup = this._beginLine() + "<?xml";
markup += " version=\"" + version + "\"";

@@ -30,6 +45,6 @@ if (encoding !== undefined) {

return markup;
}
};
/** @inheritdoc */
docType(name, publicId, systemId) {
let markup = this._beginLine();
XMLCBWriter.prototype.docType = function (name, publicId, systemId) {
var markup = this._beginLine();
if (publicId && systemId) {

@@ -48,13 +63,13 @@ markup += "<!DOCTYPE " + name + " PUBLIC \"" + publicId + "\" \"" + systemId + "\">";

return markup;
}
};
/** @inheritdoc */
comment(data) {
XMLCBWriter.prototype.comment = function (data) {
return this._beginLine() + "<!--" + data + "-->";
}
};
/** @inheritdoc */
text(data) {
XMLCBWriter.prototype.text = function (data) {
return this._beginLine() + data;
}
};
/** @inheritdoc */
instruction(target, data) {
XMLCBWriter.prototype.instruction = function (target, data) {
if (data) {

@@ -66,14 +81,14 @@ return this._beginLine() + "<?" + target + " " + data + "?>";

}
}
};
/** @inheritdoc */
cdata(data) {
XMLCBWriter.prototype.cdata = function (data) {
return this._beginLine() + "<![CDATA[" + data + "]]>";
}
};
/** @inheritdoc */
openTagBegin(name) {
XMLCBWriter.prototype.openTagBegin = function (name) {
this._lineLength += 1 + name.length;
return this._beginLine() + "<" + name;
}
};
/** @inheritdoc */
openTagEnd(name, selfClosing, voidElement) {
XMLCBWriter.prototype.openTagEnd = function (name, selfClosing, voidElement) {
if (voidElement) {

@@ -96,10 +111,10 @@ return " />";

}
}
};
/** @inheritdoc */
closeTag(name) {
XMLCBWriter.prototype.closeTag = function (name) {
return this._beginLine() + "</" + name + ">";
}
};
/** @inheritdoc */
attribute(name, value) {
let str = name + "=\"" + value + "\"";
XMLCBWriter.prototype.attribute = function (name, value) {
var str = name + "=\"" + value + "\"";
if (this._writerOptions.prettyPrint && this._writerOptions.width > 0 &&

@@ -115,7 +130,7 @@ this._lineLength + 1 + str.length > this._writerOptions.width) {

}
}
};
/** @inheritdoc */
beginElement(name) { }
XMLCBWriter.prototype.beginElement = function (name) { };
/** @inheritdoc */
endElement(name) { }
XMLCBWriter.prototype.endElement = function (name) { };
/**

@@ -125,5 +140,5 @@ * Produces characters to be prepended to a line of string in pretty-print

*/
_beginLine() {
XMLCBWriter.prototype._beginLine = function () {
if (this._writerOptions.prettyPrint) {
const str = (this.hasData ? this._writerOptions.newline : "") +
var str = (this.hasData ? this._writerOptions.newline : "") +
this._indent(this._writerOptions.offset + this.level);

@@ -136,3 +151,3 @@ this._lineLength = str.length;

}
}
};
/**

@@ -143,3 +158,3 @@ * Produces an indentation string.

*/
_indent(level) {
XMLCBWriter.prototype._indent = function (level) {
if (level <= 0) {

@@ -151,5 +166,6 @@ return "";

}
}
}
};
return XMLCBWriter;
}(BaseCBWriter_1.BaseCBWriter));
exports.XMLCBWriter = XMLCBWriter;
//# sourceMappingURL=XMLCBWriter.js.map
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
const util_1 = require("@oozcitak/util");
const interfaces_1 = require("@oozcitak/dom/lib/dom/interfaces");
const BaseWriter_1 = require("./BaseWriter");
const util_2 = require("@oozcitak/dom/lib/util");
var util_1 = require("@oozcitak/util");
var interfaces_1 = require("@oozcitak/dom/lib/dom/interfaces");
var BaseWriter_1 = require("./BaseWriter");
var util_2 = require("@oozcitak/dom/lib/util");
/**
* Serializes XML nodes into strings.
*/
class XMLWriter extends BaseWriter_1.BaseWriter {
constructor() {
super(...arguments);
this._indentation = {};
this._lengthToLastNewline = 0;
var XMLWriter = /** @class */ (function (_super) {
__extends(XMLWriter, _super);
function XMLWriter() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this._indentation = {};
_this._lengthToLastNewline = 0;
return _this;
}

@@ -22,3 +37,3 @@ /**

*/
serialize(node, writerOptions) {
XMLWriter.prototype.serialize = function (node, writerOptions) {
// provide default options

@@ -60,5 +75,5 @@ this._options = util_1.applyDefaults(writerOptions, {

return this._refs.markup;
}
};
/** @inheritdoc */
docType(name, publicId, systemId) {
XMLWriter.prototype.docType = function (name, publicId, systemId) {
this._beginLine();

@@ -78,10 +93,10 @@ if (publicId && systemId) {

this._endLine();
}
};
/** @inheritdoc */
openTagBegin(name) {
XMLWriter.prototype.openTagBegin = function (name) {
this._beginLine();
this._refs.markup += "<" + name;
}
};
/** @inheritdoc */
openTagEnd(name, selfClosing, voidElement) {
XMLWriter.prototype.openTagEnd = function (name, selfClosing, voidElement) {
// do not indent text only elements or elements with empty text nodes

@@ -91,7 +106,7 @@ this._refs.suppressPretty = false;

if (this._options.prettyPrint && !selfClosing && !voidElement) {
let textOnlyNode = true;
let emptyNode = true;
let childNode = this.currentNode.firstChild;
let cdataCount = 0;
let textCount = 0;
var textOnlyNode = true;
var emptyNode = true;
var childNode = this.currentNode.firstChild;
var cdataCount = 0;
var textCount = 0;
while (childNode) {

@@ -125,5 +140,5 @@ if (util_2.Guard.isExclusiveTextNode(childNode)) {

this._endLine();
}
};
/** @inheritdoc */
closeTag(name) {
XMLWriter.prototype.closeTag = function (name) {
if (!this._refs.emptyNode) {

@@ -136,6 +151,6 @@ this._beginLine();

this._endLine();
}
};
/** @inheritdoc */
attribute(name, value) {
const str = name + "=\"" + value + "\"";
XMLWriter.prototype.attribute = function (name, value) {
var str = name + "=\"" + value + "\"";
if (this._options.prettyPrint && this._options.width > 0 &&

@@ -150,5 +165,5 @@ this._refs.markup.length - this._lengthToLastNewline + 1 + str.length > this._options.width) {

}
}
};
/** @inheritdoc */
text(data) {
XMLWriter.prototype.text = function (data) {
if (data !== '') {

@@ -159,5 +174,5 @@ this._beginLine();

}
}
};
/** @inheritdoc */
cdata(data) {
XMLWriter.prototype.cdata = function (data) {
if (data !== '') {

@@ -168,15 +183,15 @@ this._beginLine();

}
}
};
/** @inheritdoc */
comment(data) {
XMLWriter.prototype.comment = function (data) {
this._beginLine();
this._refs.markup += "<!--" + data + "-->";
this._endLine();
}
};
/** @inheritdoc */
instruction(target, data) {
XMLWriter.prototype.instruction = function (target, data) {
this._beginLine();
this._refs.markup += "<?" + (data === "" ? target : target + " " + data) + "?>";
this._endLine();
}
};
/**

@@ -186,7 +201,7 @@ * Produces characters to be prepended to a line of string in pretty-print

*/
_beginLine() {
XMLWriter.prototype._beginLine = function () {
if (this._options.prettyPrint && !this._refs.suppressPretty) {
this._refs.markup += this._indent(this._options.offset + this.level);
}
}
};
/**

@@ -196,3 +211,3 @@ * Produces characters to be appended to a line of string in pretty-print

*/
_endLine() {
XMLWriter.prototype._endLine = function () {
if (this._options.prettyPrint && !this._refs.suppressPretty) {

@@ -202,3 +217,3 @@ this._refs.markup += this._options.newline;

}
}
};
/**

@@ -209,3 +224,3 @@ * Produces an indentation string.

*/
_indent(level) {
XMLWriter.prototype._indent = function (level) {
if (level <= 0) {

@@ -218,9 +233,10 @@ return "";

else {
const str = this._options.indent.repeat(level);
var str = this._options.indent.repeat(level);
this._indentation[level] = str;
return str;
}
}
}
};
return XMLWriter;
}(BaseWriter_1.BaseWriter));
exports.XMLWriter = XMLWriter;
//# sourceMappingURL=XMLWriter.js.map
{
"name": "xmlbuilder2",
"version": "2.1.5",
"version": "2.1.6",
"keywords": [

@@ -21,4 +21,5 @@ "xml",

"main": "./lib/index",
"browser": "./lib/xmlbuilder2.min.js",
"engines": {
"node": ">=8.0"
"node": ">=10.0"
},

@@ -30,7 +31,9 @@ "files": [

"dependencies": {
"@oozcitak/util": "8.3.4",
"@oozcitak/dom": "1.15.6",
"@oozcitak/infra": "1.0.5"
"@oozcitak/util": "8.3.8",
"@oozcitak/dom": "1.15.8",
"@oozcitak/infra": "1.0.8"
},
"devDependencies": {
"@babel/preset-env": "*",
"@babel/runtime-corejs3": "7.10.3",
"@types/benchmark": "*",

@@ -41,13 +44,26 @@ "@types/dedent": "*",

"@types/node": "*",
"babel-loader": "*",
"benchmark": "*",
"chalk": "*",
"core-js": "3.6.5",
"dedent": "*",
"glob": "*",
"es6-proxy-polyfill": "*",
"harmony-reflect": "*",
"jest": "*",
"libxmljs": "*",
"ts-jest": "*",
"ts-loader": "*",
"ts-node": "*",
"typescript": "*",
"webpack": "*",
"webpack-cli": "*",
"xmlbuilder": "*",
"xpath": "*"
"xpath": "*",
"selenium-webdriver": "*",
"chromedriver": "*",
"geckodriver": "*",
"iedriver": "*",
"@types/selenium-webdriver": "*",
"@types/chromedriver": "*"
},

@@ -59,2 +75,5 @@ "jest": {

"testRegex": "/test/.*\\.test\\.tsx?$",
"testPathIgnorePatterns": [
"/test/browser/.*"
],
"testEnvironment": "node",

@@ -66,3 +85,3 @@ "collectCoverageFrom": [

"scripts": {
"pretest": "rm -rf ./lib && tsc --version && tsc",
"pretest": "rm -rf ./lib && tsc --version && tsc && webpack",
"test": "jest --coverage",

@@ -69,0 +88,0 @@ "perf": "npm run pretest && ts-node ./perf/perf.ts",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc