Socket
Socket
Sign inDemoInstall

xmlbuilder

Package Overview
Dependencies
Maintainers
1
Versions
98
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xmlbuilder - npm Package Compare versions

Comparing version 1.0.2 to 1.1.0

lib/XMLAttribute.js

7

lib/index.js
// Generated by CoffeeScript 1.6.1
(function() {
var XMLBuilder;
var XMLBuilder, _;
_ = require('underscore');
XMLBuilder = require('./XMLBuilder');
module.exports.create = function(name, xmldec, doctype, options) {
return new XMLBuilder(name, xmldec, doctype, options).root();
options = _.extend({}, xmldec, doctype, options);
return new XMLBuilder(name, options).root();
};
}).call(this);
// Generated by CoffeeScript 1.6.1
(function() {
var XMLBuilder, XMLFragment, XMLStringifier, _;
var XMLBuilder, XMLDeclaration, XMLDocType, XMLElement, XMLStringifier, _;
_ = require('underscore');
XMLFragment = require('./XMLFragment');
XMLStringifier = require('./XMLStringifier');
XMLBuilder = (function() {
XMLDeclaration = require('./XMLDeclaration');
function XMLBuilder(name, xmldec, doctype, options) {
var child, decatts, docatts, root;
XMLDocType = require('./XMLDocType');
XMLElement = require('./XMLElement');
module.exports = XMLBuilder = (function() {
function XMLBuilder(name, options) {
var root;
if (name == null) {
throw new Error("Root element needs a name");
}
this.children = [];
this.rootObject = null;
options = _.extend({
'version': '1.0'
}, xmldec, doctype, options);
if (options == null) {
options = {};
}
this.stringify = new XMLStringifier(options);
name = this.stringify.eleName(name);
if (!(options != null ? options.headless : void 0)) {
decatts = {};
if (options.version != null) {
decatts.version = this.stringify.xmlVersion(options.version);
}
if (options.encoding != null) {
decatts.encoding = this.stringify.xmlEncoding(options.encoding);
}
if (options.standalone != null) {
decatts.standalone = this.stringify.xmlStandalone(options.standalone);
}
child = new XMLFragment(this, '?xml', decatts);
this.children.push(child);
docatts = {};
if (!options.headless) {
this.xmldec = new XMLDeclaration(this, options);
if (options.ext != null) {
docatts.ext = this.stringify.xmlExternalSubset(options.ext);
this.doctype = new XMLDocType(this, options);
}
if (!_.isEmpty(docatts)) {
docatts.name = name;
child = new XMLFragment(this, '!DOCTYPE', docatts);
this.children.push(child);
}
}
root = new XMLFragment(this, name, {});
root = new XMLElement(this, 'doc');
root = root.element(name);
root.isRoot = true;
root.documentObject = this;
this.children.push(root);
this.rootObject = root;

@@ -64,10 +48,11 @@ }

XMLBuilder.prototype.toString = function(options) {
var child, r, _i, _len, _ref;
var r;
r = '';
_ref = this.children;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
child = _ref[_i];
r += child.toString(options);
if (this.xmldec != null) {
r += this.xmldec.toString(options);
}
return r;
if (this.doctype != null) {
r += this.doctype.toString(options);
}
return r += this.rootObject.toString(options);
};

@@ -79,4 +64,2 @@

module.exports = XMLBuilder;
}).call(this);

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

// Generated by CoffeeScript 1.6.1
// Generated by CoffeeScript 1.6.3
(function() {

@@ -9,3 +9,2 @@ var XMLFragment, _,

XMLFragment = (function() {
function XMLFragment(parent, name, attributes, text) {

@@ -24,106 +23,105 @@ this.isRoot = false;

XMLFragment.prototype.element = function(name, attributes, text) {
var atts, child, key, val, _ref, _ref1;
if (name == null) {
throw new Error("Missing element name");
var child;
child = this.makeElement(this, name, attributes, text);
if (_.isArray(child)) {
Array.prototype.push.apply(this.children, child);
return _.last(child);
} else {
this.children.push(child);
return child;
}
name = this.stringify.eleName(name);
if (attributes == null) {
attributes = {};
}
if (_.isString(attributes) && _.isObject(text)) {
_ref = [text, attributes], attributes = _ref[0], text = _ref[1];
} else if (_.isString(attributes)) {
_ref1 = [{}, attributes], attributes = _ref1[0], text = _ref1[1];
}
atts = {};
for (key in attributes) {
if (!__hasProp.call(attributes, key)) continue;
val = attributes[key];
key = this.stringify.attName(key);
val = this.stringify.attValue(val);
if ((key != null) && (val != null)) {
atts[key] = val;
}
}
child = new XMLFragment(this, name, atts);
if (text != null) {
text = this.stringify.eleText(text);
child.raw(text);
}
this.children.push(child);
return child;
};
XMLFragment.prototype.insertBefore = function(name, attributes, text) {
var atts, child, i, key, val, _ref, _ref1;
var child, i;
if (this.isRoot) {
throw new Error("Cannot insert elements at root level");
}
if (name == null) {
throw new Error("Missing element name");
child = this.makeElement(this.parent, name, attributes, text);
i = this.parent.children.indexOf(this);
if (_.isArray(child)) {
child.unshift(i, 0);
Array.prototype.splice.apply(this.parent.children, child);
return _.last(child);
} else {
this.parent.children.splice(i, 0, child);
return child;
}
name = this.stringify.eleName(name);
if (attributes == null) {
attributes = {};
}
if (_.isString(attributes) && _.isObject(text)) {
_ref = [text, attributes], attributes = _ref[0], text = _ref[1];
} else if (_.isString(attributes)) {
_ref1 = [{}, attributes], attributes = _ref1[0], text = _ref1[1];
}
atts = {};
for (key in attributes) {
if (!__hasProp.call(attributes, key)) continue;
val = attributes[key];
key = this.stringify.attName(key);
val = this.stringify.attValue(val);
if ((key != null) && (val != null)) {
atts[key] = val;
}
}
child = new XMLFragment(this.parent, name, atts);
if (text != null) {
text = this.stringify.eleText(text);
child.raw(text);
}
i = this.parent.children.indexOf(this);
this.parent.children.splice(i, 0, child);
return child;
};
XMLFragment.prototype.insertAfter = function(name, attributes, text) {
var atts, child, i, key, val, _ref, _ref1;
var child, i;
if (this.isRoot) {
throw new Error("Cannot insert elements at root level");
}
child = this.makeElement(this.parent, name, attributes, text);
i = this.parent.children.indexOf(this);
if (_.isArray(child)) {
child.unshift(i + 1, 0);
Array.prototype.splice.apply(this.parent.children, child);
return _.last(child);
} else {
this.parent.children.splice(i + 1, 0, child);
return child;
}
};
XMLFragment.prototype.makeElement = function(parent, name, attributes, text) {
var atts, child, item, items, key, res, val, _ref;
if (name == null) {
throw new Error("Missing element name");
}
name = this.stringify.eleName(name);
if (attributes == null) {
attributes = {};
}
if (_.isString(attributes) && _.isObject(text)) {
_ref = [text, attributes], attributes = _ref[0], text = _ref[1];
} else if (_.isString(attributes)) {
_ref1 = [{}, attributes], attributes = _ref1[0], text = _ref1[1];
}
atts = {};
for (key in attributes) {
if (!__hasProp.call(attributes, key)) continue;
val = attributes[key];
key = this.stringify.attName(key);
val = this.stringify.attValue(val);
if ((key != null) && (val != null)) {
atts[key] = val;
if (_.isObject(name)) {
items = [];
for (key in name) {
if (!__hasProp.call(name, key)) continue;
val = name[key];
if (_.isFunction(val)) {
val = val.apply();
items.push(this.makeElement(parent, key, val));
} else if (_.isArray(val)) {
res = (function() {
var _i, _len, _results;
_results = [];
for (_i = 0, _len = val.length; _i < _len; _i++) {
item = val[_i];
_results.push(this.makeElement(parent, key, item));
}
return _results;
}).call(this);
Array.prototype.push.apply(items, res);
} else if (_.isObject(val)) {
child = this.makeElement(parent, key);
child.element(val);
items.push(child);
} else {
items.push(this.makeElement(parent, key, val));
}
}
return items;
} else {
name = this.stringify.eleName(name);
if (attributes == null) {
attributes = {};
}
if (_.isObject(text) || !_.isObject(attributes)) {
_ref = [text, attributes], attributes = _ref[0], text = _ref[1];
}
atts = {};
for (key in attributes) {
if (!__hasProp.call(attributes, key)) continue;
val = attributes[key];
key = this.stringify.attName(key);
val = this.stringify.attValue(val);
if ((key != null) && (val != null)) {
atts[key] = val;
}
}
child = new XMLFragment(parent, name, atts);
if (text != null) {
text = this.stringify.eleText(text);
child.raw(text);
}
return child;
}
child = new XMLFragment(this.parent, name, atts);
if (text != null) {
text = this.stringify.eleText(text);
child.raw(text);
}
i = this.parent.children.indexOf(this);
this.parent.children.splice(i + 1, 0, child);
return child;
};

@@ -187,3 +185,3 @@

if (this.isRoot) {
throw new Error("This node has no parent. Use doc() if you need to get the document object.");
throw new Error("The root node has no parent. Use doc() if you need to get the document object.");
}

@@ -261,3 +259,2 @@ return this.parent;

XMLFragment.prototype.attribute = function(name, value) {
var _ref;
if (name == null) {

@@ -271,3 +268,3 @@ throw new Error("Missing attribute name");

value = this.stringify.attValue(value);
if ((_ref = this.attributes) == null) {
if (this.attributes == null) {
this.attributes = {};

@@ -289,17 +286,8 @@ }

XMLFragment.prototype.instruction = function(target, value) {
var pi;
if (target == null) {
throw new Error("Missing instruction target");
}
if (value == null) {
value = '';
}
target = this.stringify.insTarget(target);
value = this.stringify.insValue(value);
pi = target;
if (value) {
pi += ' ';
}
pi += value;
this.instructions.push(pi);
this.instructions.push(target + (value ? ' ' + value : ''));
return this;

@@ -310,5 +298,5 @@ };

var attName, attValue, child, indent, instruction, newline, pretty, r, space, _i, _j, _len, _len1, _ref, _ref1, _ref2;
pretty = (options != null) && options.pretty || false;
indent = (options != null) && options.indent || ' ';
newline = (options != null) && options.newline || '\n';
pretty = (options != null ? options.pretty : void 0) || false;
indent = (options != null ? options.indent : void 0) || ' ';
newline = (options != null ? options.newline : void 0) || '\n';
level || (level = 0);

@@ -315,0 +303,0 @@ space = new Array(level + 1).join(indent);

@@ -7,3 +7,3 @@ // Generated by CoffeeScript 1.6.1

XMLStringifier = (function() {
module.exports = XMLStringifier = (function() {

@@ -40,4 +40,3 @@ function XMLStringifier(options) {

}
val = this.assertLegalChar(val);
return '<![CDATA[' + val + ']]>';
return this.assertLegalChar(val);
};

@@ -50,4 +49,3 @@

}
val = this.assertLegalChar(this.escape(val));
return '<!-- ' + val + ' -->';
return this.assertLegalChar(this.escape(val));
};

@@ -108,2 +106,14 @@

XMLStringifier.prototype.convertAttKey = '@';
XMLStringifier.prototype.convertTextKey = '#text';
XMLStringifier.prototype.convertCDataKey = '#cdata';
XMLStringifier.prototype.convertCommentKey = '#comment';
XMLStringifier.prototype.convertRawKey = '#raw';
XMLStringifier.prototype.convertListKey = '#list';
XMLStringifier.prototype.assertLegalChar = function(str) {

@@ -131,4 +141,2 @@ var chars, chr;

module.exports = XMLStringifier;
}).call(this);
{
"name": "xmlbuilder",
"version": "1.0.2",
"version": "1.1.0",
"keywords": [ "xml", "xmlbuilder" ],

@@ -5,0 +5,0 @@ "homepage": "http://github.com/oozcitak/xmlbuilder-js",

@@ -6,3 +6,5 @@ # xmlbuilder-js

[![NPM version](https://badge.fury.io/js/xmlbuilder.png)](http://badge.fury.io/js/xmlbuilder)
[![Build Status](https://secure.travis-ci.org/oozcitak/xmlbuilder-js.png)](http://travis-ci.org/oozcitak/xmlbuilder-js)
[![Dependency Status](https://david-dm.org/oozcitak/xmlbuilder-js.png)](https://david-dm.org/oozcitak/xmlbuilder-js)

@@ -9,0 +11,0 @@ ### Installation:

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