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 0.0.14 to 1.1.0

83

lib/builder/dom.d.ts

@@ -1,2 +0,2 @@

import { Document, DocumentType, Element, Text, CDATASection, Comment, ProcessingInstruction, DocumentFragment, Node } from "@oozcitak/dom/lib/dom/interfaces";
import { Document } from "@oozcitak/dom/lib/dom/interfaces";
import { DOMParser } from "@oozcitak/dom";

@@ -15,82 +15,1 @@ /**

export declare function createParser(): DOMParser;
/**
* Determines if the given object is a `Node`.
*
* @param x - the object to check
*/
export declare function isNode(x: any): x is Node;
/**
* Determines if the given object is a `Document`.
*
* @param x - the object to check
*/
export declare function isDocumentNode(x: any): x is Document;
/**
* Determines if the given object is a `DocumentType`.
*
* @param x - the object to check
*/
export declare function isDocumentTypeNode(x: any): x is DocumentType;
/**
* Determines if the given object is a `DocumentFragment`.
*
* @param x - the object to check
*/
export declare function isDocumentFragmentNode(x: any): x is DocumentFragment;
/**
* Determines if the given object is a `Element`.
*
* @param x - the object to check
*/
export declare function isElementNode(x: any): x is Element;
/**
* Determines if the given object is a `Text`.
*
* @param x - the object to check
*/
export declare function isTextNode(x: any): x is Text;
/**
* Determines if the given object is a `CDATASection`.
*
* @param x - the object to check
*/
export declare function isCDATASectionNode(x: any): x is CDATASection;
/**
* Determines if the given object is a `Comment`.
*
* @param x - the object to check
*/
export declare function isCommentNode(x: any): x is Comment;
/**
* Determines if the given object is a `ProcessingInstruction`.
*
* @param x - the object to check
*/
export declare function isProcessingInstructionNode(x: any): x is ProcessingInstruction;
/**
* Extracts a prefix and localName from the given qualified name.
*
* @param qualifiedName - qualified name
*
* @returns an tuple with `prefix` and `localName`.
*/
export declare function extractQName(qualifiedName: string): [string | null, string];
/**
* Determines if the given string is valid for a `"Name"` construct.
*
* @param name - name string to test
*/
export declare function isName(name: string): boolean;
/**
* Determines if the given string contains legal characters.
*
* @param chars - sequence of characters to test
*/
export declare function isLegalChar(chars: string): boolean;
/**
* Determines if the given string contains legal characters for a public
* identifier.
*
* @param chars - sequence of characters to test
*/
export declare function isPubidChar(chars: string): boolean;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const interfaces_1 = require("@oozcitak/dom/lib/dom/interfaces");
const dom_1 = require("@oozcitak/dom");

@@ -15,4 +14,11 @@ const dom_2 = require("@oozcitak/dom/lib/dom");

root.namespaceURI === "http://www.mozilla.org/newlayout/xml/parsererror.xml") {
const msg = root.firstChild ? root.firstChild.getAttribute("message") : null;
throw new Error(msg || "Error parsing XML string.");
const msgElement = root.firstElementChild;
/* istanbul ignore next */
if (msgElement === null)
throw new Error("Error parsing XML string.");
const msg = msgElement.getAttribute("message");
/* istanbul ignore next */
if (msg === null)
throw new Error("Error parsing XML string.");
throw new Error(msg);
}

@@ -41,201 +47,2 @@ }

exports.createParser = createParser;
/**
* Determines if the given object is a `Node`.
*
* @param x - the object to check
*/
function isNode(x) {
return (!!x && x.nodeType !== undefined);
}
exports.isNode = isNode;
/**
* Determines if the given object is a `Document`.
*
* @param x - the object to check
*/
function isDocumentNode(x) {
return (!!x && x.nodeType === interfaces_1.NodeType.Document);
}
exports.isDocumentNode = isDocumentNode;
/**
* Determines if the given object is a `DocumentType`.
*
* @param x - the object to check
*/
function isDocumentTypeNode(x) {
return (!!x && x.nodeType === interfaces_1.NodeType.DocumentType);
}
exports.isDocumentTypeNode = isDocumentTypeNode;
/**
* Determines if the given object is a `DocumentFragment`.
*
* @param x - the object to check
*/
function isDocumentFragmentNode(x) {
return (!!x && x.nodeType === interfaces_1.NodeType.DocumentFragment);
}
exports.isDocumentFragmentNode = isDocumentFragmentNode;
/**
* Determines if the given object is a `Element`.
*
* @param x - the object to check
*/
function isElementNode(x) {
return (!!x && x.nodeType === interfaces_1.NodeType.Element);
}
exports.isElementNode = isElementNode;
/**
* Determines if the given object is a `Text`.
*
* @param x - the object to check
*/
function isTextNode(x) {
return (!!x && x.nodeType === interfaces_1.NodeType.Text);
}
exports.isTextNode = isTextNode;
/**
* Determines if the given object is a `CDATASection`.
*
* @param x - the object to check
*/
function isCDATASectionNode(x) {
return (!!x && x.nodeType === interfaces_1.NodeType.CData);
}
exports.isCDATASectionNode = isCDATASectionNode;
/**
* Determines if the given object is a `Comment`.
*
* @param x - the object to check
*/
function isCommentNode(x) {
return (!!x && x.nodeType === interfaces_1.NodeType.Comment);
}
exports.isCommentNode = isCommentNode;
/**
* Determines if the given object is a `ProcessingInstruction`.
*
* @param x - the object to check
*/
function isProcessingInstructionNode(x) {
return (!!x && x.nodeType === interfaces_1.NodeType.ProcessingInstruction);
}
exports.isProcessingInstructionNode = isProcessingInstructionNode;
/**
* Extracts a prefix and localName from the given qualified name.
*
* @param qualifiedName - qualified name
*
* @returns an tuple with `prefix` and `localName`.
*/
function extractQName(qualifiedName) {
const parts = qualifiedName.split(':');
const prefix = (parts.length === 2 ? parts[0] : null);
const localName = (parts.length === 2 ? parts[1] : qualifiedName);
return [prefix, localName];
}
exports.extractQName = extractQName;
/**
* Determines if the given string is valid for a `"Name"` construct.
*
* @param name - name string to test
*/
function isName(name) {
for (let i = 0; i < name.length; i++) {
let n = name.charCodeAt(i);
// NameStartChar
if ((n >= 97 && n <= 122) || // [a-z]
(n >= 65 && n <= 90) || // [A-Z]
n === 58 || n === 95 || // ':' or '_'
(n >= 0xC0 && n <= 0xD6) ||
(n >= 0xD8 && n <= 0xF6) ||
(n >= 0xF8 && n <= 0x2FF) ||
(n >= 0x370 && n <= 0x37D) ||
(n >= 0x37F && n <= 0x1FFF) ||
(n >= 0x200C && n <= 0x200D) ||
(n >= 0x2070 && n <= 0x218F) ||
(n >= 0x2C00 && n <= 0x2FEF) ||
(n >= 0x3001 && n <= 0xD7FF) ||
(n >= 0xF900 && n <= 0xFDCF) ||
(n >= 0xFDF0 && n <= 0xFFFD)) {
continue;
}
else if (i !== 0 &&
(n === 45 || n === 46 || // '-' or '.'
(n >= 48 && n <= 57) || // [0-9]
(n === 0xB7) ||
(n >= 0x0300 && n <= 0x036F) ||
(n >= 0x203F && n <= 0x2040))) {
continue;
}
if (n >= 0xD800 && n <= 0xDBFF && i < name.length - 1) {
const n2 = name.charCodeAt(i + 1);
if (n2 >= 0xDC00 && n2 <= 0xDFFF) {
n = (n - 0xD800) * 0x400 + n2 - 0xDC00 + 0x10000;
i++;
if (n >= 0x10000 && n <= 0xEFFFF) {
continue;
}
}
}
return false;
}
return true;
}
exports.isName = isName;
/**
* Determines if the given string contains legal characters.
*
* @param chars - sequence of characters to test
*/
function isLegalChar(chars) {
for (let i = 0; i < chars.length; i++) {
let n = chars.charCodeAt(i);
// #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
if (n === 0x9 || n === 0xA || n === 0xD ||
(n >= 0x20 && n <= 0xD7FF) ||
(n >= 0xE000 && n <= 0xFFFD)) {
continue;
}
if (n >= 0xD800 && n <= 0xDBFF && i < chars.length - 1) {
const n2 = chars.charCodeAt(i + 1);
if (n2 >= 0xDC00 && n2 <= 0xDFFF) {
n = (n - 0xD800) * 0x400 + n2 - 0xDC00 + 0x10000;
i++;
if (n >= 0x10000 && n <= 0x10FFFF) {
continue;
}
}
}
return false;
}
return true;
}
exports.isLegalChar = isLegalChar;
/**
* Determines if the given string contains legal characters for a public
* identifier.
*
* @param chars - sequence of characters to test
*/
function isPubidChar(chars) {
for (let i = 0; i < chars.length; i++) {
// PubId chars are all in the ASCII range, no need to check surrogates
const n = chars.charCodeAt(i);
// #x20 | #xD | #xA | [a-zA-Z0-9] | [-'()+,./:=?;!*#@$_%]
if ((n >= 97 && n <= 122) || // [a-z]
(n >= 65 && n <= 90) || // [A-Z]
(n >= 39 && n <= 59) || // ['()*+,-./] | [0-9] | [:;]
n === 0x20 || n === 0xD || n === 0xA || // #x20 | #xD | #xA
(n >= 35 && n <= 37) || // [#$%]
n === 33 || // !
n === 61 || n === 63 || n === 64 || n === 95) { // [=?@_]
continue;
}
else {
return false;
}
}
return true;
}
exports.isPubidChar = isPubidChar;
//# sourceMappingURL=dom.js.map

2

lib/builder/interfaces.d.ts

@@ -361,3 +361,3 @@ import { Node, Document } from "@oozcitak/dom/lib/dom/interfaces";

[key: string]: any;
} | Map<string, any> | any[] | ((...args: any) => any);
} | Map<string, any> | any[] | Set<any> | ((...args: any) => any);
/**

@@ -364,0 +364,0 @@ * Represents the type of a variable that is a JS object defining

@@ -8,2 +8,4 @@ "use strict";

const dom_1 = require("./dom");
const algorithm_1 = require("@oozcitak/dom/lib/algorithm");
const util_2 = require("@oozcitak/dom/lib/util");
/**

@@ -166,6 +168,6 @@ * Represents a wrapper that extends XML nodes to implement easy to use and

let attNamespace;
const qName = dom_1.extractQName(key);
const qName = algorithm_1.namespace_extractQName(key);
util_1.forEachObject(val, (attName, attValue) => {
if (attName[0] === this._options.convert.att) {
const attQName = dom_1.extractQName(attName.slice(1));
const attQName = algorithm_1.namespace_extractQName(attName.slice(1));
if ((attQName[0] === null && attQName[1] === "xmlns") ||

@@ -258,3 +260,3 @@ (attQName[0] === "xmlns" && attQName[1] === qName[0])) {

if (namespace === undefined) {
const attQName = dom_1.extractQName(name);
const attQName = algorithm_1.namespace_extractQName(name);
if (attQName[0] === "xmlns") {

@@ -369,3 +371,3 @@ namespace = infra_1.namespace.XMLNS;

const importedNode = node.node;
if (dom_1.isDocumentNode(importedNode)) {
if (util_2.Guard.isDocumentNode(importedNode)) {
// import document node

@@ -379,3 +381,3 @@ const elementNode = importedNode.documentElement;

}
else if (dom_1.isDocumentFragmentNode(importedNode)) {
else if (util_2.Guard.isDocumentFragmentNode(importedNode)) {
// import child nodes

@@ -638,3 +640,3 @@ for (const childNode of importedNode.childNodes) {

if (namespace === null || namespace === undefined) {
const qName = dom_1.extractQName(name);
const qName = algorithm_1.namespace_extractQName(name);
const parent = this.node.parentNode;

@@ -652,3 +654,3 @@ if (parent) {

else {
const attQName = dom_1.extractQName(attName);
const attQName = algorithm_1.namespace_extractQName(attName);
if (attQName[0] === "xmlns" && attQName[1] === qName[0]) {

@@ -697,3 +699,3 @@ namespace = attValue;

const node = this.node;
if (dom_1.isDocumentNode(node)) {
if (util_2.Guard.isDocumentNode(node)) {
return node;

@@ -700,0 +702,0 @@ }

@@ -5,13 +5,14 @@ "use strict";

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_2 = require("util");
const util_3 = require("util");
/** @inheritdoc */
function builder(p1, p2) {
const options = formatOptions(isXMLBuilderCreateOptions(p1) ? p1 : interfaces_1.DefaultBuilderOptions);
const nodes = dom_1.isNode(p1) || util_2.isArray(p1) ? p1 : p2;
const nodes = util_2.Guard.isNode(p1) || util_3.isArray(p1) ? p1 : p2;
if (nodes === undefined) {
throw new Error("Invalid arguments.");
}
if (util_2.isArray(nodes)) {
if (util_3.isArray(nodes)) {
const builders = [];

@@ -18,0 +19,0 @@ for (let i = 0; i < nodes.length; i++) {

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

const DOMException_1 = require("@oozcitak/dom/lib/dom/DOMException");
const dom_1 = require("../../builder/dom");
const algorithm_1 = require("@oozcitak/dom/lib/algorithm");
/**

@@ -130,3 +130,3 @@ * Pre-serializes XML nodes. This class is not namespace aware.

if (requireWellFormed && (node.localName.indexOf(":") !== -1 ||
!dom_1.isName(node.localName))) {
!algorithm_1.xml_isName(node.localName))) {
throw new Error("Node local name contains invalid characters (well-formed required).");

@@ -307,3 +307,3 @@ }

*/
if (requireWellFormed && (!dom_1.isLegalChar(node.data) ||
if (requireWellFormed && (!algorithm_1.xml_isLegalChar(node.data) ||
node.data.indexOf("--") !== -1 || node.data.endsWith("-"))) {

@@ -333,3 +333,3 @@ throw new Error("Comment data contains invalid characters (well-formed required).");

*/
if (requireWellFormed && !dom_1.isLegalChar(node.data)) {
if (requireWellFormed && !algorithm_1.xml_isLegalChar(node.data)) {
throw new Error("Text data contains invalid characters (well-formed required).");

@@ -391,3 +391,3 @@ }

*/
if (requireWellFormed && !dom_1.isPubidChar(node.publicId)) {
if (requireWellFormed && !algorithm_1.xml_isPubidChar(node.publicId)) {
throw new Error("DocType public identifier does not match PubidChar construct (well-formed required).");

@@ -403,3 +403,3 @@ }

if (requireWellFormed &&
(!dom_1.isLegalChar(node.systemId) ||
(!algorithm_1.xml_isLegalChar(node.systemId) ||
(node.systemId.indexOf('"') !== -1 && node.systemId.indexOf("'") !== -1))) {

@@ -463,3 +463,3 @@ throw new Error("DocType system identifier contains invalid characters (well-formed required).");

*/
if (requireWellFormed && (!dom_1.isLegalChar(node.data) ||
if (requireWellFormed && (!algorithm_1.xml_isLegalChar(node.data) ||
node.data.indexOf("?>") !== -1)) {

@@ -559,3 +559,3 @@ throw new Error("Processing instruction data contains invalid characters (well-formed required).");

if (requireWellFormed && (attr.localName.indexOf(":") !== -1 ||
!dom_1.isName(attr.localName))) {
!algorithm_1.xml_isName(attr.localName))) {
throw new Error("Attribute local name contains invalid characters (well-formed required).");

@@ -594,3 +594,3 @@ }

*/
if (requireWellFormed && value !== null && !dom_1.isLegalChar(value)) {
if (requireWellFormed && value !== null && !algorithm_1.xml_isLegalChar(value)) {
throw new Error("Invalid characters in attribute value.");

@@ -597,0 +597,0 @@ }

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

const infra_1 = require("@oozcitak/infra");
const dom_1 = require("../../builder/dom");
const algorithm_1 = require("@oozcitak/dom/lib/algorithm");
/**

@@ -143,3 +143,3 @@ * Pre-serializes XML nodes. This class is namespace aware.

if (requireWellFormed && (node.localName.indexOf(":") !== -1 ||
!dom_1.isName(node.localName))) {
!algorithm_1.xml_isName(node.localName))) {
throw new Error("Node local name contains invalid characters (well-formed required).");

@@ -555,3 +555,3 @@ }

*/
if (requireWellFormed && (!dom_1.isLegalChar(node.data) ||
if (requireWellFormed && (!algorithm_1.xml_isLegalChar(node.data) ||
node.data.indexOf("--") !== -1 || node.data.endsWith("-"))) {

@@ -581,3 +581,3 @@ throw new Error("Comment data contains invalid characters (well-formed required).");

*/
if (requireWellFormed && !dom_1.isLegalChar(node.data)) {
if (requireWellFormed && !algorithm_1.xml_isLegalChar(node.data)) {
throw new Error("Text data contains invalid characters (well-formed required).");

@@ -642,3 +642,3 @@ }

*/
if (requireWellFormed && !dom_1.isPubidChar(node.publicId)) {
if (requireWellFormed && !algorithm_1.xml_isPubidChar(node.publicId)) {
throw new Error("DocType public identifier does not match PubidChar construct (well-formed required).");

@@ -654,3 +654,3 @@ }

if (requireWellFormed &&
(!dom_1.isLegalChar(node.systemId) ||
(!algorithm_1.xml_isLegalChar(node.systemId) ||
(node.systemId.indexOf('"') !== -1 && node.systemId.indexOf("'") !== -1))) {

@@ -714,3 +714,3 @@ throw new Error("DocType system identifier contains invalid characters (well-formed required).");

*/
if (requireWellFormed && (!dom_1.isLegalChar(node.data) ||
if (requireWellFormed && (!algorithm_1.xml_isLegalChar(node.data) ||
node.data.indexOf("?>") !== -1)) {

@@ -934,3 +934,3 @@ throw new Error("Processing instruction data contains invalid characters (well-formed required).");

if (requireWellFormed && (attr.localName.indexOf(":") !== -1 ||
!dom_1.isName(attr.localName) ||
!algorithm_1.xml_isName(attr.localName) ||
(attr.localName === "xmlns" && attributeNamespace === null))) {

@@ -973,6 +973,3 @@ throw new Error("Attribute local name contains invalid characters (well-formed required).");

*/
for (let i = 0; i < node.attributes.length; i++) {
const attr = node.attributes.item(i);
if (!attr)
continue;
for (const attr of node.attributes) {
/**

@@ -1103,3 +1100,3 @@ * _Note:_ The following conditional steps find namespace prefixes. Only

*/
if (requireWellFormed && value !== null && !dom_1.isLegalChar(value)) {
if (requireWellFormed && value !== null && !algorithm_1.xml_isLegalChar(value)) {
throw new Error("Invalid characters in attribute value.");

@@ -1106,0 +1103,0 @@ }

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

}
else if (util_1.isMap(obj) || util_1.isObject(obj)) {
else if (util_1.isObject(obj)) {
markup += '{';

@@ -71,0 +71,0 @@ const len = util_1.objectLength(obj);

@@ -5,5 +5,5 @@ "use strict";

const interfaces_1 = require("@oozcitak/dom/lib/dom/interfaces");
const dom_1 = require("../builder/dom");
const PreSerializerNS_1 = require("./base/PreSerializerNS");
const PreSerializerNoNS_1 = require("./base/PreSerializerNoNS");
const util_2 = require("@oozcitak/dom/lib/util");
/**

@@ -116,4 +116,6 @@ * Serializes XML nodes into strings.

let childNode = this._pre.currentNode.firstChild;
let cdataCount = 0;
let textCount = 0;
while (childNode) {
if (!dom_1.isTextNode(childNode)) {
if (!util_2.Guard.isTextNode(childNode)) {
textOnlyNode = false;

@@ -126,5 +128,11 @@ emptyNode = false;

}
if (util_2.Guard.isCDATASectionNode(childNode)) {
cdataCount++;
}
else if (util_2.Guard.isExclusiveTextNode(childNode)) {
textCount++;
}
childNode = childNode.nextSibling;
}
this._refs.suppressPretty = textOnlyNode;
this._refs.suppressPretty = textOnlyNode && ((cdataCount <= 1 && textCount === 0) || cdataCount === 0);
this._refs.emptyNode = emptyNode;

@@ -163,5 +171,7 @@ }

_text(data) {
this._beginLine();
this._refs.markup += data;
this._endLine();
if (data !== '') {
this._beginLine();
this._refs.markup += data;
this._endLine();
}
}

@@ -172,5 +182,7 @@ /**

_cdata(data) {
this._beginLine();
this._refs.markup += "<![CDATA[" + data + "]]>";
this._endLine();
if (data !== '') {
this._beginLine();
this._refs.markup += "<![CDATA[" + data + "]]>";
this._endLine();
}
}

@@ -177,0 +189,0 @@ /**

{
"name": "xmlbuilder2",
"version": "0.0.14",
"version": "1.1.0",
"keywords": [

@@ -29,3 +29,3 @@ "xml",

"@oozcitak/util": "8.0.0",
"@oozcitak/dom": "1.15.1",
"@oozcitak/dom": "1.15.2",
"@oozcitak/infra": "1.0.5"

@@ -32,0 +32,0 @@ },

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