xmlbuilder2
Advanced tools
Comparing version 0.0.12 to 0.0.14
@@ -164,2 +164,3 @@ "use strict"; | ||
// check for a namespace declaration attribute | ||
let attNamespace; | ||
const qName = dom_1.extractQName(key); | ||
@@ -171,3 +172,3 @@ util_1.forEachObject(val, (attName, attValue) => { | ||
(attQName[0] === "xmlns" && attQName[1] === qName[0])) { | ||
namespace = attValue; | ||
attNamespace = attValue; | ||
} | ||
@@ -177,3 +178,3 @@ } | ||
// create a parent node | ||
lastChild = this._node(namespace, key); | ||
lastChild = this._node(attNamespace, key); | ||
// expand child nodes under parent | ||
@@ -180,0 +181,0 @@ lastChild.ele(val); |
@@ -42,3 +42,3 @@ import { XMLBuilderCreateOptions, ExpandObject, XMLBuilder, WriterOptions, XMLSerializedValue } from './builder/interfaces'; | ||
*/ | ||
export declare function document(): XMLBuilder; | ||
export declare function create(): XMLBuilder; | ||
/** | ||
@@ -51,3 +51,3 @@ * Creates an XML document without any child nodes with the given options. | ||
*/ | ||
export declare function document(options: XMLBuilderCreateOptions): XMLBuilder; | ||
export declare function create(options: XMLBuilderCreateOptions): XMLBuilder; | ||
/** | ||
@@ -61,3 +61,3 @@ * Creates an XML document by parsing the given `contents`. | ||
*/ | ||
export declare function document(contents: string | ExpandObject): XMLBuilder; | ||
export declare function create(contents: string | ExpandObject): XMLBuilder; | ||
/** | ||
@@ -72,3 +72,3 @@ * Creates an XML document. | ||
*/ | ||
export declare function document(options: XMLBuilderCreateOptions, contents: string | ExpandObject): XMLBuilder; | ||
export declare function create(options: XMLBuilderCreateOptions, contents: string | ExpandObject): XMLBuilder; | ||
/** | ||
@@ -75,0 +75,0 @@ * Creates a new document fragment without any child nodes. |
@@ -32,3 +32,3 @@ "use strict"; | ||
/** @inheritdoc */ | ||
function document(p1, p2) { | ||
function create(p1, p2) { | ||
const options = formatOptions(p1 === undefined || isXMLBuilderCreateOptions(p1) ? | ||
@@ -69,3 +69,3 @@ p1 : interfaces_1.DefaultBuilderOptions); | ||
} | ||
exports.document = document; | ||
exports.create = create; | ||
/** @inheritdoc */ | ||
@@ -133,3 +133,3 @@ function fragment(p1, p2) { | ||
} | ||
return document(builderOptions, contents).end(convertOptions); | ||
return create(builderOptions, contents).end(convertOptions); | ||
} | ||
@@ -136,0 +136,0 @@ exports.convert = convert; |
@@ -238,16 +238,7 @@ "use strict"; | ||
*/ | ||
if (node._children !== undefined) { | ||
for (const childNode of node._children) { | ||
this.level++; | ||
this._serializeNode(childNode, requireWellFormed); | ||
this.level--; | ||
} | ||
for (const childNode of node._children) { | ||
this.level++; | ||
this._serializeNode(childNode, requireWellFormed); | ||
this.level--; | ||
} | ||
else { | ||
node.childNodes.forEach(childNode => { | ||
this.level++; | ||
this._serializeNode(childNode, requireWellFormed); | ||
this.level--; | ||
}, this); | ||
} | ||
/** | ||
@@ -297,12 +288,5 @@ * 20. Append the following to markup, in the order listed: | ||
*/ | ||
if (node._children !== undefined) { | ||
for (const childNode of node._children) { | ||
this._serializeNode(childNode, requireWellFormed); | ||
} | ||
for (const childNode of node._children) { | ||
this._serializeNode(childNode, requireWellFormed); | ||
} | ||
else { | ||
node.childNodes.forEach(childNode => { | ||
this._serializeNode(childNode, requireWellFormed); | ||
}, this); | ||
} | ||
} | ||
@@ -388,12 +372,5 @@ /** | ||
*/ | ||
if (node._children !== undefined) { | ||
for (const childNode of node._children) { | ||
this._serializeNode(childNode, requireWellFormed); | ||
} | ||
for (const childNode of node._children) { | ||
this._serializeNode(childNode, requireWellFormed); | ||
} | ||
else { | ||
node.childNodes.forEach(childNode => { | ||
this._serializeNode(childNode, requireWellFormed); | ||
}, this); | ||
} | ||
} | ||
@@ -536,4 +513,3 @@ /** | ||
*/ | ||
for (let i = 0; i < node.attributes.length; i++) { | ||
const attr = node.attributes[i]; | ||
for (const attr of node.attributes) { | ||
// Optimize common case | ||
@@ -562,2 +538,3 @@ if (!requireWellFormed) { | ||
*/ | ||
/* istanbul ignore else */ | ||
if (requireWellFormed && localNameSet) | ||
@@ -564,0 +541,0 @@ localNameSet[attr.localName] = true; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const interfaces_1 = require("@oozcitak/dom/lib/dom/interfaces"); | ||
const LocalNameSet_1 = require("./LocalNameSet"); | ||
@@ -93,29 +94,30 @@ const NamespacePrefixMap_1 = require("./NamespacePrefixMap"); | ||
this.currentNode = node; | ||
if (dom_1.isElementNode(node)) { | ||
this._serializeElement(node, namespace, prefixMap, prefixIndex, requireWellFormed); | ||
switch (node.nodeType) { | ||
case interfaces_1.NodeType.Element: | ||
this._serializeElement(node, namespace, prefixMap, prefixIndex, requireWellFormed); | ||
break; | ||
case interfaces_1.NodeType.Document: | ||
this._serializeDocument(node, namespace, prefixMap, prefixIndex, requireWellFormed); | ||
break; | ||
case interfaces_1.NodeType.Comment: | ||
this._serializeComment(node, requireWellFormed); | ||
break; | ||
case interfaces_1.NodeType.Text: | ||
this._serializeText(node, requireWellFormed); | ||
break; | ||
case interfaces_1.NodeType.DocumentFragment: | ||
this._serializeDocumentFragment(node, namespace, prefixMap, prefixIndex, requireWellFormed); | ||
break; | ||
case interfaces_1.NodeType.DocumentType: | ||
this._serializeDocumentType(node, requireWellFormed); | ||
break; | ||
case interfaces_1.NodeType.ProcessingInstruction: | ||
this._serializeProcessingInstruction(node, requireWellFormed); | ||
break; | ||
case interfaces_1.NodeType.CData: | ||
this._serializeCData(node, requireWellFormed); | ||
break; | ||
default: | ||
throw new Error(`Unknown node type: ${node.nodeType}`); | ||
} | ||
else if (dom_1.isDocumentNode(node)) { | ||
this._serializeDocument(node, namespace, prefixMap, prefixIndex, requireWellFormed); | ||
} | ||
else if (dom_1.isCommentNode(node)) { | ||
this._serializeComment(node, requireWellFormed); | ||
} | ||
else if (dom_1.isTextNode(node)) { | ||
this._serializeText(node, requireWellFormed); | ||
} | ||
else if (dom_1.isDocumentFragmentNode(node)) { | ||
this._serializeDocumentFragment(node, namespace, prefixMap, prefixIndex, requireWellFormed); | ||
} | ||
else if (dom_1.isDocumentTypeNode(node)) { | ||
this._serializeDocumentType(node, requireWellFormed); | ||
} | ||
else if (dom_1.isProcessingInstructionNode(node)) { | ||
this._serializeProcessingInstruction(node, requireWellFormed); | ||
} | ||
else if (dom_1.isCDATASectionNode(node)) { | ||
this._serializeCData(node, requireWellFormed); | ||
} | ||
else { | ||
throw new Error(`Unknown node type: ${node.nodeType}`); | ||
} | ||
} | ||
@@ -765,6 +767,3 @@ /** | ||
*/ | ||
for (let i = 0; i < node.attributes.length; i++) { | ||
const attr = node.attributes.item(i); | ||
if (!attr) | ||
continue; | ||
for (const attr of node.attributes) { | ||
// Optimize common case | ||
@@ -771,0 +770,0 @@ if (!requireWellFormed && attr.namespaceURI === null) { |
{ | ||
"name": "xmlbuilder2", | ||
"version": "0.0.12", | ||
"version": "0.0.14", | ||
"keywords": [ | ||
@@ -28,5 +28,5 @@ "xml", | ||
"dependencies": { | ||
"@oozcitak/util": "7.0.0", | ||
"@oozcitak/dom": "1.13.0", | ||
"@oozcitak/infra": "1.0.4" | ||
"@oozcitak/util": "8.0.0", | ||
"@oozcitak/dom": "1.15.1", | ||
"@oozcitak/infra": "1.0.5" | ||
}, | ||
@@ -33,0 +33,0 @@ "devDependencies": { |
@@ -36,5 +36,5 @@ # xmlbuilder2 | ||
``` js | ||
const { document } = require('xmlbuilder2'); | ||
const { create } = require('xmlbuilder2'); | ||
const root = document({ version: '1.0' }) | ||
const root = create({ version: '1.0' }) | ||
.ele('root', { att: 'val' }) | ||
@@ -57,3 +57,3 @@ .ele('foo') | ||
``` js | ||
const { document } = require('xmlbuilder2'); | ||
const { create } = require('xmlbuilder2'); | ||
@@ -70,3 +70,3 @@ const obj = { | ||
const doc = document(obj); | ||
const doc = create(obj); | ||
const xml = doc.end({ prettyPrint: true }); | ||
@@ -79,6 +79,6 @@ console.log(xml); | ||
```js | ||
const { document } = require('xmlbuilder2'); | ||
const { create } = require('xmlbuilder2'); | ||
const xmlStr = '<root att="val"><foo><bar>foobar</bar></foo></root>'; | ||
const doc = document(xmlStr); | ||
const doc = create(xmlStr); | ||
@@ -114,5 +114,5 @@ // append a 'baz' element to the root node of the document | ||
``` js | ||
const { document } = require('xmlbuilder2'); | ||
const { create } = require('xmlbuilder2'); | ||
const root = document().ele('squares'); | ||
const root = create().ele('squares'); | ||
root.com('f(x) = x^2'); | ||
@@ -119,0 +119,0 @@ for(let i = 1; i <= 5; i++) |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
313072
45
5748
+ Added@oozcitak/dom@1.15.1(transitive)
+ Added@oozcitak/infra@1.0.5(transitive)
+ Added@oozcitak/util@8.0.0(transitive)
- Removed@oozcitak/dom@1.13.0(transitive)
- Removed@oozcitak/infra@1.0.4(transitive)
- Removed@oozcitak/util@7.0.0(transitive)
Updated@oozcitak/dom@1.15.1
Updated@oozcitak/infra@1.0.5
Updated@oozcitak/util@8.0.0