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.1.2 to 2.0.0

lib/XMLDTDAttList.js

12

lib/XMLAttribute.js

@@ -14,2 +14,5 @@ // Generated by CoffeeScript 1.6.1

}
if (_.isFunction(value)) {
value = value.apply();
}
this.name = this.stringify.attName(name);

@@ -20,10 +23,3 @@ this.value = this.stringify.attValue(value);

XMLAttribute.prototype.toString = function(options, level) {
var indent, newline, pretty, r, space;
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);
space = new Array(level).join(indent);
r = ' ' + this.name + '="' + this.value + '"';
return r;
return ' ' + this.name + '="' + this.value + '"';
};

@@ -30,0 +26,0 @@

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

function XMLBuilder(name, options) {
var root;
var root, temp;
if (name == null) {

@@ -27,13 +27,13 @@ throw new Error("Root element needs a name");

this.stringify = new XMLStringifier(options);
temp = new XMLElement(this, 'doc');
root = temp.element(name);
root.isRoot = true;
root.documentObject = this;
this.rootObject = root;
if (!options.headless) {
this.xmldec = new XMLDeclaration(this, options);
if (options.ext != null) {
this.doctype = new XMLDocType(this, options);
root.declaration(options);
if ((options.pubID != null) || (options.sysID != null)) {
root.doctype(options.pubID, options.sysID);
}
}
root = new XMLElement(this, 'doc');
root = root.element(name);
root.isRoot = true;
root.documentObject = this;
this.rootObject = root;
}

@@ -50,3 +50,6 @@

XMLBuilder.prototype.toString = function(options) {
var r;
var indent, newline, pretty, r;
pretty = (options != null ? options.pretty : void 0) || false;
indent = (options != null ? options.indent : void 0) || ' ';
newline = (options != null ? options.newline : void 0) || '\n';
r = '';

@@ -59,3 +62,7 @@ if (this.xmldec != null) {

}
return r += this.rootObject.toString(options);
r += this.rootObject.toString(options);
if (pretty && r.slice(-newline.length) === newline) {
r = r.slice(0, -newline.length);
}
return r;
};

@@ -62,0 +69,0 @@

@@ -15,16 +15,20 @@ // Generated by CoffeeScript 1.6.1

function XMLDeclaration(parent, options) {
function XMLDeclaration(parent, version, encoding, standalone) {
var _ref;
XMLDeclaration.__super__.constructor.call(this, parent);
options = _.extend({
'version': '1.0'
}, options);
if (options.version != null) {
this.version = this.stringify.xmlVersion(options.version);
if (_.isObject(version)) {
_ref = version, version = _ref.version, encoding = _ref.encoding, standalone = _ref.standalone;
}
if (options.encoding != null) {
this.encoding = this.stringify.xmlEncoding(options.encoding);
if (!version) {
version = '1.0';
}
if (options.standalone != null) {
this.standalone = this.stringify.xmlStandalone(options.standalone);
if (version != null) {
this.version = this.stringify.xmlVersion(version);
}
if (encoding != null) {
this.encoding = this.stringify.xmlEncoding(encoding);
}
if (standalone != null) {
this.standalone = this.stringify.xmlStandalone(standalone);
}
}

@@ -31,0 +35,0 @@

// Generated by CoffeeScript 1.6.1
(function() {
var XMLDocType, XMLNode, _,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
var XMLDocType, _;
_ = require('underscore');
XMLNode = require('./XMLNode');
module.exports = XMLDocType = (function() {
module.exports = XMLDocType = (function(_super) {
__extends(XMLDocType, _super);
function XMLDocType(parent, options) {
XMLDocType.__super__.constructor.call(this, parent);
if (options.ext != null) {
this.ext = this.stringify.xmlExternalSubset(options.ext);
function XMLDocType(parent, pubID, sysID) {
var _ref, _ref1;
this.documentObject = parent;
this.stringify = this.documentObject.stringify;
this.children = [];
if (_.isObject(pubID)) {
_ref = pubID, pubID = _ref.pubID, sysID = _ref.sysID;
}
if (sysID == null) {
_ref1 = [pubID, sysID], sysID = _ref1[0], pubID = _ref1[1];
}
if (pubID != null) {
this.pubID = this.stringify.dtdPubID(pubID);
}
if (sysID != null) {
this.sysID = this.stringify.dtdSysID(sysID);
}
}
XMLDocType.prototype.element = function(name, value) {
var XMLDTDElement, child;
XMLDTDElement = require('./XMLDTDElement');
child = new XMLDTDElement(this, name, value);
this.children.push(child);
return this;
};
XMLDocType.prototype.attList = function(elementName, attributeName, attributeType, defaultValueType, defaultValue) {
var XMLDTDAttList, child;
XMLDTDAttList = require('./XMLDTDAttList');
child = new XMLDTDAttList(this, elementName, attributeName, attributeType, defaultValueType, defaultValue);
this.children.push(child);
return this;
};
XMLDocType.prototype.entity = function(name, value) {
var XMLDTDEntity, child;
XMLDTDEntity = require('./XMLDTDEntity');
child = new XMLDTDEntity(this, false, name, value);
this.children.push(child);
return this;
};
XMLDocType.prototype.pEntity = function(name, value) {
var XMLDTDEntity, child;
XMLDTDEntity = require('./XMLDTDEntity');
child = new XMLDTDEntity(this, true, name, value);
this.children.push(child);
return this;
};
XMLDocType.prototype.notation = function(name, value) {
var XMLDTDNotation, child;
XMLDTDNotation = require('./XMLDTDNotation');
child = new XMLDTDNotation(this, name, value);
this.children.push(child);
return this;
};
XMLDocType.prototype.cdata = function(value) {
var XMLCData, child;
XMLCData = require('./XMLCData');
child = new XMLCData(this, value);
this.children.push(child);
return this;
};
XMLDocType.prototype.comment = function(value) {
var XMLComment, child;
XMLComment = require('./XMLComment');
child = new XMLComment(this, value);
this.children.push(child);
return this;
};
XMLDocType.prototype.instruction = function(target, value) {
var XMLProcessingInstruction, child;
XMLProcessingInstruction = require('./XMLProcessingInstruction');
child = new XMLProcessingInstruction(this, target, value);
this.children.push(child);
return this;
};
XMLDocType.prototype.root = function() {
return this.documentObject.root();
};
XMLDocType.prototype.document = function() {
return this.documentObject;
};
XMLDocType.prototype.toString = function(options, level) {
var indent, newline, pretty, r, space;
var child, indent, newline, pretty, r, space, _i, _len, _ref;
pretty = (options != null ? options.pretty : void 0) || false;

@@ -33,7 +111,20 @@ indent = (options != null ? options.indent : void 0) || ' ';

}
r += '<!DOCTYPE';
r += ' ' + this.parent.root().name;
if (this.ext != null) {
r += ' ' + this.ext;
r += '<!DOCTYPE ' + this.root().name;
if (this.pubID && this.sysID) {
r += ' PUBLIC "' + this.pubID + '" "' + this.sysID + '"';
} else if (this.sysID) {
r += ' SYSTEM "' + this.sysID + '"';
}
if (this.children.length > 0) {
r += ' [';
if (pretty) {
r += newline;
}
_ref = this.children;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
child = _ref[_i];
r += child.toString(options, level + 1);
}
r += ']';
}
r += '>';

@@ -46,6 +137,46 @@ if (pretty) {

XMLDocType.prototype.ele = function(name, value) {
return this.element(name, value);
};
XMLDocType.prototype.att = function(elementName, attributeName, attributeType, defaultValueType, defaultValue) {
return this.attList(elementName, attributeName, attributeType, defaultValueType, defaultValue);
};
XMLDocType.prototype.ent = function(name, value) {
return this.entity(name, value);
};
XMLDocType.prototype.pent = function(name, value) {
return this.pEntity(name, value);
};
XMLDocType.prototype.not = function(name, value) {
return this.notation(name, value);
};
XMLDocType.prototype.dat = function(value) {
return this.cdata(value);
};
XMLDocType.prototype.com = function(value) {
return this.comment(value);
};
XMLDocType.prototype.ins = function(target, value) {
return this.instruction(target, value);
};
XMLDocType.prototype.up = function() {
return this.root();
};
XMLDocType.prototype.doc = function() {
return this.document();
};
return XMLDocType;
})(XMLNode);
})();
}).call(this);

@@ -26,5 +26,2 @@ // Generated by CoffeeScript 1.6.1

this.name = this.stringify.eleName(name);
if (attributes == null) {
attributes = {};
}
this.children = [];

@@ -43,4 +40,18 @@ this.instructions = [];

XMLElement.prototype.clone = function(deep) {
var clonedSelf;
clonedSelf = new XMLElement(this.parent, this.name, this.attributes, this.value);
var att, attName, clonedSelf, pi, _i, _len, _ref, _ref1;
clonedSelf = _.clone(this);
clonedSelf.attributes = {};
_ref = this.attributes;
for (attName in _ref) {
if (!__hasProp.call(_ref, attName)) continue;
att = _ref[attName];
clonedSelf.attributes[attName] = _.clone(att);
}
clonedSelf.instructions = [];
_ref1 = this.instructions;
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
pi = _ref1[_i];
clonedSelf.instructions.push(_.clone(pi));
}
clonedSelf.children = [];
if (deep) {

@@ -47,0 +58,0 @@ this.children.forEach(function(child) {

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

XMLNode.prototype.element = function(name, attributes, text) {
var attKey, attVal, item, key, lastChild, piKey, piVal, val, _i, _len, _ref;
var item, key, lastChild, val, _i, _len, _ref;
lastChild = null;

@@ -31,4 +31,3 @@ if (attributes == null) {

} else if (_.isFunction(name)) {
name = name.apply();
lastChild = this.element(name);
lastChild = this.element(name.apply());
} else if (_.isObject(name)) {

@@ -38,33 +37,13 @@ for (key in name) {

val = name[key];
if (!(val != null)) {
continue;
}
if (_.isFunction(val)) {
name[key] = val.apply();
val = val.apply();
}
}
for (key in name) {
if (!__hasProp.call(name, key)) continue;
val = name[key];
if (val == null) {
delete name[key];
}
}
for (attKey in name) {
if (!__hasProp.call(name, attKey)) continue;
attVal = name[attKey];
if (this.stringify.convertAttKey && attKey.indexOf(this.stringify.convertAttKey) === 0) {
this.attribute(attKey.substr(this.stringify.convertAttKey.length), attVal);
delete name[attKey];
}
}
for (piKey in name) {
if (!__hasProp.call(name, piKey)) continue;
piVal = name[piKey];
if (this.stringify.convertPIKey && piKey.indexOf(this.stringify.convertPIKey) === 0) {
this.instruction(piKey.substr(this.stringify.convertPIKey.length), piVal);
delete name[piKey];
}
}
for (key in name) {
if (!__hasProp.call(name, key)) continue;
val = name[key];
if (_.isObject(val)) {
if (this.stringify.convertAttKey && key.indexOf(this.stringify.convertAttKey) === 0) {
lastChild = this.attribute(key.substr(this.stringify.convertAttKey.length), val);
} else if (this.stringify.convertPIKey && key.indexOf(this.stringify.convertPIKey) === 0) {
lastChild = this.instruction(key.substr(this.stringify.convertPIKey.length), val);
} else if (_.isObject(val)) {
if (this.stringify.convertListKey && key.indexOf(this.stringify.convertListKey) === 0 && _.isArray(val)) {

@@ -94,2 +73,5 @@ lastChild = this.element(val);

}
if (lastChild == null) {
throw new Error("Could not create any elements with: " + name);
}
return lastChild;

@@ -175,2 +157,20 @@ };

XMLNode.prototype.declaration = function(version, encoding, standalone) {
var XMLDeclaration, doc, xmldec;
doc = this.document();
XMLDeclaration = require('./XMLDeclaration');
xmldec = new XMLDeclaration(doc, version, encoding, standalone);
doc.xmldec = xmldec;
return doc.root();
};
XMLNode.prototype.doctype = function(pubID, sysID) {
var XMLDocType, doc, doctype;
doc = this.document();
XMLDocType = require('./XMLDocType');
doctype = new XMLDocType(doc, pubID, sysID);
doc.doctype = doctype;
return doctype;
};
XMLNode.prototype.up = function() {

@@ -264,2 +264,10 @@ if (this.isRoot) {

XMLNode.prototype.dec = function(version, encoding, standalone) {
return this.declaration(version, encoding, standalone);
};
XMLNode.prototype.dtd = function(pubID, sysID) {
return this.doctype(pubID, sysID);
};
XMLNode.prototype.e = function(name, attributes, text) {

@@ -266,0 +274,0 @@ return this.element(name, attributes, text);

@@ -14,4 +14,9 @@ // Generated by CoffeeScript 1.6.1

}
if (_.isFunction(value)) {
value = value.apply();
}
this.target = this.stringify.insTarget(target);
this.value = this.stringify.insValue(value);
if (value) {
this.value = this.stringify.insValue(value);
}
}

@@ -25,3 +30,3 @@

level || (level = 0);
space = new Array(level).join(indent);
space = new Array(level + 1).join(indent);
r = '';

@@ -28,0 +33,0 @@ if (pretty) {

@@ -99,6 +99,34 @@ // Generated by CoffeeScript 1.6.1

XMLStringifier.prototype.xmlExternalSubset = function(val) {
XMLStringifier.prototype.dtdPubID = function(val) {
return '' + val || '';
};
XMLStringifier.prototype.dtdSysID = function(val) {
return '' + val || '';
};
XMLStringifier.prototype.dtdElementValue = function(val) {
return '' + val || '';
};
XMLStringifier.prototype.dtdAttType = function(val) {
return '' + val || '';
};
XMLStringifier.prototype.dtdAttDefault = function(val) {
if (val != null) {
return '' + val || '';
} else {
return val;
}
};
XMLStringifier.prototype.dtdEntityValue = function(val) {
return '' + val || '';
};
XMLStringifier.prototype.dtdNData = function(val) {
return '' + val || '';
};
XMLStringifier.prototype.convertAttKey = '@';

@@ -105,0 +133,0 @@

{
"name": "xmlbuilder",
"version": "1.1.2",
"version": "2.0.0",
"keywords": [ "xml", "xmlbuilder" ],

@@ -30,3 +30,4 @@ "homepage": "http://github.com/oozcitak/xmlbuilder-js",

"coffee-script": ">=1.1.x",
"vows": ">=0.7.x"
"vows": ">=0.7.x",
"memwatch": ">=0.2.x"
},

@@ -33,0 +34,0 @@ "scripts": {

@@ -83,5 +83,1 @@ # xmlbuilder-js

See the [wiki](https://github.com/oozcitak/xmlbuilder-js/wiki) for details.
### License:
`xmlbuilder-js` is [MIT Licensed](http://opensource.org/licenses/mit-license.php).
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc