🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

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

to
1.2.0

27

lib/builder/interfaces.d.ts

@@ -43,2 +43,10 @@ import { Node, Document } from "@oozcitak/dom/lib/dom/interfaces";

convert?: Partial<ConvertOptions>;
/**
* Defines an object with namespace aliases. These aliases can be used instead
* of actual namespaces by appending them to element and attribute names after
* '@@'.
*/
namespaceAlias?: {
[key: string]: string;
};
}

@@ -78,4 +86,23 @@ /**

convert: ConvertOptions;
/**
* Defines an object with namespace aliases. These aliases can be used instead
* of actual namespaces by appending them to element and attribute names after
* '@@'.
*/
namespaceAlias: {
[key: string]: string;
};
/**
* Defines default namespaces to apply to all elements and attributes.
*/
defaultNamespace: {
"ele": undefined | null | string;
"att": undefined | null | string;
};
}
/**
* Contains keys of `XMLBuilderOptions`.
*/
export declare const XMLBuilderOptionKeys: Set<string>;
/**
* Defines the identifier strings of the DocType node.

@@ -82,0 +109,0 @@ */

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Contains keys of `XMLBuilderOptions`.
*/
exports.XMLBuilderOptionKeys = new Set([
"version", "encoding", "standalone", "keepNullNodes", "keepNullAttributes",
"ignoreConverters", "convert", "namespaceAlias", "defaultNamespace"
]);
/**
* Defines default values for builder options.

@@ -17,4 +24,16 @@ */

comment: "!"
},
namespaceAlias: {
html: "http://www.w3.org/1999/xhtml",
xml: "http://www.w3.org/XML/1998/namespace",
xmlns: "http://www.w3.org/2000/xmlns/",
mathml: "http://www.w3.org/1998/Math/MathML",
svg: "http://www.w3.org/2000/svg",
xlink: "http://www.w3.org/1999/xlink"
},
defaultNamespace: {
ele: undefined,
att: undefined
}
};
//# sourceMappingURL=interfaces.js.map

15

lib/builder/XMLBuilderImpl.d.ts

@@ -132,6 +132,19 @@ import { XMLBuilderOptions, XMLBuilder, AttributesObject, ExpandObject, WriterOptions, XMLSerializedValue, DTDOptions, PIObject } from "./interfaces";

* @param str - a string containing both a name and namespace separated by an
* '@' character.
* '@' character
*/
private _extractNamespace;
/**
* Converts a namespace alias to a namespace.
*
* @param str - a string containing a namespace alias
*/
private _applyNamespaceAlias;
/**
* Looks-up a default namespace.
*
* @param namespace - namespace
* @param ele - `true` if this is an element namespace; otherwise `false`
*/
private _lookupDefaultNamespace;
/**
* Returns the document owning this node.

@@ -138,0 +151,0 @@ */

@@ -218,2 +218,3 @@ "use strict";

[namespace, name, value] = [p1, p2, p3];
namespace = this._applyNamespaceAlias(namespace);
}

@@ -228,2 +229,3 @@ else if (p1 !== undefined && p2 !== undefined) {

}
namespace = this._lookupDefaultNamespace(namespace, false);
if (this._options.keepNullAttributes && (value === null)) {

@@ -238,3 +240,3 @@ // keep null attributes

const ele = this.node;
if (namespace !== null && namespace !== undefined) {
if (namespace !== undefined) {
ele.setAttributeNS(namespace + "", name + "", value + "");

@@ -254,17 +256,26 @@ }

}
if (util_1.isArray(p1) || util_1.isSet(p1)) {
let namespace;
let name;
if (p2 === undefined) {
name = p1;
}
else if (util_1.isString(p1)) {
namespace = p1;
name = p2;
}
else {
throw new Error("Attribute namespace must be a string. " + this._debugInfo());
}
if (util_1.isArray(name) || util_1.isSet(name)) {
// removeAtt(names: string[])
util_1.forEachArray(p1, attName => this.removeAtt(attName), this);
}
else if (util_1.isArray(p2) || util_1.isSet(p2)) {
// removeAtt(namespace: string, names: string[])
util_1.forEachArray(p2, attName => this.removeAtt(p1 + "", attName), this);
util_1.forEachArray(name, attName => namespace === undefined ? this.removeAtt(attName) : this.removeAtt(namespace, attName), this);
}
else if (p1 !== undefined && p2 !== undefined) {
else if (namespace !== undefined) {
// removeAtt(namespace: string, name: string)
this.node.removeAttributeNS(p1 + "", p2 + "");
this.node.removeAttributeNS(this._applyNamespaceAlias(namespace), name + "");
}
else {
// removeAtt(name: string)
this.node.removeAttribute(p1 + "");
this.node.removeAttribute(name + "");
}

@@ -603,5 +614,6 @@ return this;

_node(namespace, name, attributes) {
namespace = this._lookupDefaultNamespace(namespace, true);
name += "";
const child = (namespace !== null && namespace !== undefined ?
this._doc.createElementNS(namespace + "", name) :
const child = (namespace !== undefined ?
this._doc.createElementNS(namespace, name) :
this._doc.createElement(name));

@@ -639,3 +651,3 @@ this.node.appendChild(child);

* @param str - a string containing both a name and namespace separated by an
* '@' character.
* '@' character
*/

@@ -648,6 +660,42 @@ _extractNamespace(str) {

else {
return [str.slice(atIndex + 1), str.slice(0, atIndex)];
return [this._applyNamespaceAlias(str.slice(atIndex + 1)), str.slice(0, atIndex)];
}
}
/**
* Converts a namespace alias to a namespace.
*
* @param str - a string containing a namespace alias
*/
_applyNamespaceAlias(str) {
if (str[0] === '@') {
const alias = str.slice(1);
const namespace = this._options.namespaceAlias[alias];
if (namespace === undefined) {
throw new Error(`Namespace alias "${alias}" not defined.`);
}
return namespace;
}
else {
return str;
}
}
/**
* Looks-up a default namespace.
*
* @param namespace - namespace
* @param ele - `true` if this is an element namespace; otherwise `false`
*/
_lookupDefaultNamespace(namespace, ele) {
if (namespace === undefined) {
const defaultNS = (ele ? this._options.defaultNamespace.ele : this._options.defaultNamespace.att);
if (defaultNS !== undefined) {
namespace = defaultNS;
if (namespace !== null && namespace !== undefined) {
namespace = this._applyNamespaceAlias(namespace);
}
}
}
return namespace;
}
/**
* Returns the document owning this node.

@@ -654,0 +702,0 @@ */

4

lib/index.js

@@ -138,8 +138,6 @@ "use strict";

return false;
const keys = new Set(["version", "encoding", "standalone", "keepNullNodes",
"keepNullAttributes", "ignoreConverters", "convert"]);
for (const key in obj) {
/* istanbul ignore else */
if (obj.hasOwnProperty(key)) {
if (!keys.has(key))
if (!interfaces_1.XMLBuilderOptionKeys.has(key))
return false;

@@ -146,0 +144,0 @@ }

{
"name": "xmlbuilder2",
"version": "1.1.2",
"version": "1.2.0",
"keywords": [

@@ -66,5 +66,5 @@ "xml",

"prof-serialize": "npm run pretest && rm -f isolate-*-v8.log && node --prof ./perf/prof-serialize.js && find . -name isolate-*-v8.log -exec mv {} isolate-v8.log ; && node --prof-process isolate-v8.log > isolate-serialize.log && rm isolate-v8.log",
"prepublish": "npm run test",
"prepare": "npm run test",
"postpublish": "git push --all && git push --tags"
}
}

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