Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
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 1.3.0 to 1.4.0

lib/interfaces.d.ts

18

CHANGELOG.md

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

## [1.3.0] - 2020-02-18
- Added namespace aliases.
## [1.2.1] - 2020-02-18

@@ -13,7 +18,7 @@

Added namespace aliases.
- Added namespace aliases.
## [1.1.2] - 2020-02-17
- Prevented child element namespaces to be inherited from their parent elements (issue #1).
- Prevented child element namespaces to be inherited from their parent elements (See [#1](https://github.com/oozcitak/xmlbuilder2/issues/1)).
- Fixed JS object parser to allow namespaces for both element nodes and attributes with the `{ "prefix:name@ns": {} }` notation.

@@ -23,12 +28,13 @@

Fixed `width` option to work in pretty-printing mode to wrap attributes.
- Fixed `width` option to work in pretty-printing mode to wrap attributes.
## [1.1.0] - 2020-02-12
A CDATA node will not be indented in pretty-printing mode if it is the single child of its parent element.
- A CDATA node will not be indented in pretty-printing mode if it is the single child of its parent element.
## 1.0.0 - 2020-02-12
Initial release
- Initial release
[1.3.0]: https://github.com/oozcitak/xmlbuilder2/compare/v1.2.1...v1.3.0
[1.2.1]: https://github.com/oozcitak/xmlbuilder2/compare/v1.2.0...v1.2.1

@@ -38,2 +44,2 @@ [1.2.0]: https://github.com/oozcitak/xmlbuilder2/compare/v1.1.2...v1.2.0

[1.1.1]: https://github.com/oozcitak/xmlbuilder2/compare/v1.1.0...v1.1.1
[1.1.0]: https://github.com/oozcitak/xmlbuilder2/compare/v1.0.0...v1.1.0
[1.1.0]: https://github.com/oozcitak/xmlbuilder2/compare/v1.0.0...v1.1.0

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

import { XMLBuilderOptions, XMLBuilder, AttributesObject, ExpandObject, WriterOptions, XMLSerializedValue, DTDOptions, PIObject } from "./interfaces";
import { XMLBuilderOptions, XMLBuilder, AttributesObject, ExpandObject, WriterOptions, XMLSerializedValue, DTDOptions, PIObject } from "../interfaces";
import { Document, Node } from "@oozcitak/dom/lib/dom/interfaces";

@@ -3,0 +3,0 @@ /**

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const interfaces_1 = require("./interfaces");
const interfaces_1 = require("../interfaces");
const util_1 = require("@oozcitak/util");

@@ -336,6 +336,11 @@ const writers_1 = require("../writers");

dtd(options) {
const name = ((options && options.name) || (this._doc.documentElement ? this._doc.documentElement.tagName : "ROOT")) + "";
const pubID = ((options && options.pubID) || "") + "";
const sysID = ((options && options.sysID) || "") + "";
// name must match document element
if (this._doc.documentElement !== null && name !== this._doc.documentElement.tagName) {
throw new Error("DocType name does not match document element name.");
}
// create doctype node
const docType = this._doc.implementation.createDocumentType(this._doc.documentElement !== null ? this._doc.documentElement.tagName : 'ROOT', pubID, sysID);
const docType = this._doc.implementation.createDocumentType(name, pubID, sysID);
if (this._doc.doctype !== null) {

@@ -342,0 +347,0 @@ // replace existing doctype

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

import { XMLBuilderCreateOptions, ExpandObject, XMLBuilder, WriterOptions, XMLSerializedValue } from './builder/interfaces';
import { XMLBuilderCreateOptions, ExpandObject, XMLBuilder, WriterOptions, XMLSerializedValue, XMLBuilderStream, StreamWriterOptions } from './interfaces';
import { Node } from '@oozcitak/dom/lib/dom/interfaces';

@@ -147,1 +147,17 @@ /**

export declare function convert(builderOptions: XMLBuilderCreateOptions, contents: string | ExpandObject, convertOptions: WriterOptions): XMLSerializedValue;
/**
* Creates an XML builder document stream.
*
* @param options - stream writer options
*
* @returns XML builder stream
*/
export declare function documentStream(options: StreamWriterOptions): XMLBuilderStream;
/**
* Creates an XML builder fragment stream.
*
* @param options - stream writer options
*
* @returns XML builder stream
*/
export declare function fragmentStream(options: StreamWriterOptions): XMLBuilderStream;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const interfaces_1 = require("./builder/interfaces");
const interfaces_1 = require("./interfaces");
const util_1 = require("@oozcitak/util");

@@ -9,5 +9,6 @@ const util_2 = require("@oozcitak/dom/lib/util");

const util_3 = require("util");
const stream_1 = require("./stream");
/** @inheritdoc */
function builder(p1, p2) {
const options = formatOptions(isXMLBuilderCreateOptions(p1) ? p1 : interfaces_1.DefaultBuilderOptions);
const options = formatBuilderOptions(isXMLBuilderCreateOptions(p1) ? p1 : interfaces_1.DefaultBuilderOptions);
const nodes = util_2.Guard.isNode(p1) || util_3.isArray(p1) ? p1 : p2;

@@ -35,3 +36,3 @@ if (nodes === undefined) {

function create(p1, p2) {
const options = formatOptions(p1 === undefined || isXMLBuilderCreateOptions(p1) ?
const options = formatBuilderOptions(p1 === undefined || isXMLBuilderCreateOptions(p1) ?
p1 : interfaces_1.DefaultBuilderOptions);

@@ -74,3 +75,3 @@ const contents = isXMLBuilderCreateOptions(p1) ? p2 : p1;

function fragment(p1, p2) {
const options = formatOptions(p1 === undefined || isXMLBuilderCreateOptions(p1) ?
const options = formatBuilderOptions(p1 === undefined || isXMLBuilderCreateOptions(p1) ?
p1 : interfaces_1.DefaultBuilderOptions);

@@ -138,2 +139,24 @@ const contents = isXMLBuilderCreateOptions(p1) ? p2 : p1;

exports.convert = convert;
/**
* Creates an XML builder document stream.
*
* @param options - stream writer options
*
* @returns XML builder stream
*/
function documentStream(options) {
return new stream_1.XMLBuilderStreamImpl(options);
}
exports.documentStream = documentStream;
/**
* Creates an XML builder fragment stream.
*
* @param options - stream writer options
*
* @returns XML builder stream
*/
function fragmentStream(options) {
return new stream_1.XMLBuilderStreamImpl(options, true);
}
exports.fragmentStream = fragmentStream;
function isXMLBuilderCreateOptions(obj) {

@@ -151,3 +174,3 @@ if (!util_1.isPlainObject(obj))

}
function formatOptions(createOptions = {}) {
function formatBuilderOptions(createOptions = {}) {
const options = util_1.applyDefaults(createOptions, interfaces_1.DefaultBuilderOptions);

@@ -154,0 +177,0 @@ if (options.convert.att.length === 0 ||

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

import { JSONWriterOptions, XMLBuilderOptions } from "../builder/interfaces";
import { JSONWriterOptions, XMLBuilderOptions } from "../interfaces";
import { Node } from "@oozcitak/dom/lib/dom/interfaces";

@@ -3,0 +3,0 @@ /**

@@ -30,3 +30,4 @@ "use strict";

newline: '\n',
offset: 0
offset: 0,
group: true
});

@@ -33,0 +34,0 @@ // convert to object

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

import { XMLSerializedValue, MapWriterOptions, XMLBuilderOptions } from "../builder/interfaces";
import { XMLSerializedValue, MapWriterOptions, XMLBuilderOptions } from "../interfaces";
import { Node } from "@oozcitak/dom/lib/dom/interfaces";

@@ -3,0 +3,0 @@ /**

@@ -26,3 +26,4 @@ "use strict";

format: "map",
wellFormed: false
wellFormed: false,
group: true
});

@@ -29,0 +30,0 @@ // convert to object

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

import { XMLSerializedValue, ObjectWriterOptions, XMLBuilderOptions } from "../builder/interfaces";
import { XMLSerializedValue, ObjectWriterOptions, XMLBuilderOptions } from "../interfaces";
import { Node } from "@oozcitak/dom/lib/dom/interfaces";

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

private _process;
private _processSpecItem;
private _addAttr;

@@ -24,0 +25,0 @@ private _addText;

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

const interfaces_1 = require("@oozcitak/dom/lib/dom/interfaces");
const PreSerializer_1 = require("./base/PreSerializer");
const PreSerializer_1 = require("./PreSerializer");
/**

@@ -28,3 +28,4 @@ * Serializes XML nodes into objects and arrays.

format: "object",
wellFormed: false
wellFormed: false,
group: true
});

@@ -106,5 +107,5 @@ let currentList = [];

*/
return this._process(currentList);
return this._process(currentList, options);
}
_process(items) {
_process(items, options) {
if (items.length === 0)

@@ -147,2 +148,7 @@ return {};

}
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);
if (textCount === 1 && items.length === 1 && util_1.isString(items[0]["#"])) {

@@ -152,7 +158,7 @@ // special case of an element node with a single text node

}
else if (hasNonUniqueNames) {
else if (options.group && hasNonUniqueNames) {
// list contains element nodes with non-unique names
// return an array with mixed content notation
const result = [];
const obj = { "#": result };
const obj = { [defTextKey]: result };
for (let i = 0; i < items.length; i++) {

@@ -166,23 +172,19 @@ const item = items[i];

if (attrKeys.length === 1) {
result.push({ [this._getAttrKey() + attrKeys[0]]: attrs[attrKeys[0]] });
result.push({ [defAttrKey + attrKeys[0]]: attrs[attrKeys[0]] });
}
else {
result.push({ [this._getAttrKey()]: item["@"] });
result.push({ [defAttrKey]: item["@"] });
}
break;
case "#":
const textKey = this._getNodeKey(interfaces_1.NodeType.Text);
result.push({ [textKey]: item["#"] });
result.push({ [defTextKey]: item["#"] });
break;
case "!":
const commentKey = this._getNodeKey(interfaces_1.NodeType.Comment);
result.push({ [commentKey]: item["!"] });
result.push({ [defCommentKey]: item["!"] });
break;
case "?":
const instructionKey = this._getNodeKey(interfaces_1.NodeType.ProcessingInstruction);
result.push({ [instructionKey]: item["?"] });
result.push({ [defInstructionKey]: item["?"] });
break;
case "$":
const cdataKey = this._getNodeKey(interfaces_1.NodeType.CData);
result.push({ [cdataKey]: item["$"] });
result.push({ [defCdataKey]: item["$"] });
break;

@@ -197,3 +199,3 @@ default:

for (let i = 0; i < listOfLists.length; i++) {
eleGroup.push(this._process(listOfLists[i]));
eleGroup.push(this._process(listOfLists[i], options));
}

@@ -204,3 +206,3 @@ result.push({ [key]: eleGroup });

// single element node
result.push({ [key]: this._process(ele[key]) });
result.push({ [key]: this._process(ele[key], options) });
}

@@ -227,24 +229,22 @@ break;

const attrKeys = Object.keys(attrs);
if (attrKeys.length === 1) {
obj[this._getAttrKey() + attrKeys[0]] = attrs[attrKeys[0]];
if (!options.group || attrKeys.length === 1) {
for (const attrName in attrs) {
obj[defAttrKey + attrName] = attrs[attrName];
}
}
else {
obj[this._getAttrKey()] = item["@"];
obj[defAttrKey] = attrs;
}
break;
case "#":
const textKey = textCount > 1 ? this._getNodeKey(interfaces_1.NodeType.Text) + (textId++).toString() : this._getNodeKey(interfaces_1.NodeType.Text);
obj[textKey] = item["#"];
textId = this._processSpecItem(item["#"], obj, options.group, defTextKey, textCount, textId);
break;
case "!":
const commentKey = commentCount > 1 ? this._getNodeKey(interfaces_1.NodeType.Comment) + (commentId++).toString() : this._getNodeKey(interfaces_1.NodeType.Comment);
obj[commentKey] = item["!"];
commentId = this._processSpecItem(item["!"], obj, options.group, defCommentKey, commentCount, commentId);
break;
case "?":
const instructionKey = instructionCount > 1 ? this._getNodeKey(interfaces_1.NodeType.ProcessingInstruction) + (instructionId++).toString() : this._getNodeKey(interfaces_1.NodeType.ProcessingInstruction);
obj[instructionKey] = item["?"];
instructionId = this._processSpecItem(item["?"], obj, options.group, defInstructionKey, instructionCount, instructionId);
break;
case "$":
const cdataKey = cdataCount > 1 ? this._getNodeKey(interfaces_1.NodeType.CData) + (cdataId++).toString() : this._getNodeKey(interfaces_1.NodeType.CData);
obj[cdataKey] = item["$"];
cdataId = this._processSpecItem(item["$"], obj, options.group, defCdataKey, cdataCount, cdataId);
break;

@@ -259,3 +259,3 @@ default:

for (let i = 0; i < listOfLists.length; i++) {
eleGroup.push(this._process(listOfLists[i]));
eleGroup.push(this._process(listOfLists[i], options));
}

@@ -266,3 +266,3 @@ obj[key] = eleGroup;

// single element node
obj[key] = this._process(ele[key]);
obj[key] = this._process(ele[key], options);
}

@@ -275,2 +275,15 @@ break;

}
_processSpecItem(item, obj, group, defKey, count, id) {
if (!group && util_1.isArray(item) && count + item.length > 2) {
for (const subItem of item) {
const key = defKey + (id++).toString();
obj[key] = subItem;
}
}
else {
const key = count > 1 ? defKey + (id++).toString() : defKey;
obj[key] = item;
}
return id;
}
_addAttr(items, name, value) {

@@ -277,0 +290,0 @@ if (items.length === 0) {

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

import { StringWriterOptions, XMLBuilderOptions } from "../builder/interfaces";
import { StringWriterOptions, XMLBuilderOptions } from "../interfaces";
import { Node } from "@oozcitak/dom/lib/dom/interfaces";

@@ -3,0 +3,0 @@ /**

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

const interfaces_1 = require("@oozcitak/dom/lib/dom/interfaces");
const PreSerializer_1 = require("./base/PreSerializer");
const PreSerializer_1 = require("./PreSerializer");
const util_2 = require("@oozcitak/dom/lib/util");

@@ -8,0 +8,0 @@ /**

{
"name": "xmlbuilder2",
"version": "1.3.0",
"version": "1.4.0",
"keywords": [

@@ -28,3 +28,3 @@ "xml",

"dependencies": {
"@oozcitak/util": "8.0.0",
"@oozcitak/util": "8.3.1",
"@oozcitak/dom": "1.15.2",

@@ -66,2 +66,3 @@ "@oozcitak/infra": "1.0.5"

"perf": "npm run pretest && ts-node ./perf/perf.ts",
"stream-perf": "npm run pretest && ts-node ./perf/stream-perf.ts",
"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",

@@ -68,0 +69,0 @@ "prepare": "npm run test",

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