Initial commit

This commit is contained in:
Luis Fernando Molina committed 2018-02-07 21:05:26 +01:00
commit ec49fedc45
1288 files changed
+226749

No files matched your search

+7
View File
@@ -0,0 +1,7 @@
.gitignore
.travis.yml
.git/
src/
test/
node_modules/
+15
View File
@@ -0,0 +1,15 @@
clean:
@rm -fr lib/
release: clean
@test `which coffee` || { echo 'You need to have CoffeeScript installed.'; exit 1; }
@coffee -c -o lib src/*.coffee
test: release
@coffee test/test.coffee
publish: release
@test `which npm` || { echo 'You need to have npm installed.'; exit 1; }
npm publish
@rm -fr lib/
+73
View File
@@ -0,0 +1,73 @@
# xmlbuilder-js
An XMLBuilder for [node.js](http://nodejs.org/) similar to
[java-xmlbuilder](http://code.google.com/p/java-xmlbuilder/).
[![Build Status](https://secure.travis-ci.org/oozcitak/xmlbuilder-js.png)](http://travis-ci.org/oozcitak/xmlbuilder-js)
### Installation:
``` sh
npm install xmlbuilder
```
### Important:
I had to break compatibility while adding multiple instances in 0.1.3.
As a result, version from v0.1.3 are **not** compatible with previous versions.
### Usage:
``` js
var builder = require('xmlbuilder');
var xml = builder.create('root')
.ele('xmlbuilder', {'for': 'node-js'})
.ele('repo', {'type': 'git'}, 'git://github.com/oozcitak/xmlbuilder-js.git')
.end({ pretty: true});
console.log(xml);
```
will result in:
``` xml
<?xml version="1.0"?>
<root>
<xmlbuilder for="node-js">
<repo type="git">git://github.com/oozcitak/xmlbuilder-js.git</repo>
</xmlbuilder>
</root>
```
If you need to do some processing:
``` js
var root = builder.create('squares');
root.com('f(x) = x^2');
for(var i = 1; i <= 5; i++)
{
var item = root.ele('data');
item.att('x', i);
item.att('y', i * i);
}
```
This will result in:
``` xml
<?xml version="1.0"?>
<squares>
<!-- f(x) = x^2 -->
<data x="1" y="1"/>
<data x="2" y="4"/>
<data x="3" y="9"/>
<data x="4" y="16"/>
<data x="5" y="25"/>
</squares>
```
See the [Usage](https://github.com/oozcitak/xmlbuilder-js/wiki/Usage) page in the wiki for more detailed instructions.
### License:
`xmlbuilder-js` is [MIT Licensed](http://opensource.org/licenses/mit-license.php).
+136
View File
@@ -0,0 +1,136 @@
// Generated by CoffeeScript 1.3.3
(function() {
var XMLBuilder, XMLFragment,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
XMLFragment = require('./XMLFragment');
XMLBuilder = (function() {
function XMLBuilder(name, xmldec, doctype, options) {
this.assertLegalChar = __bind(this.assertLegalChar, this);
var att, child, _ref;
this.children = [];
this.rootObject = null;
if (this.is(name, 'Object')) {
_ref = [name, xmldec], xmldec = _ref[0], doctype = _ref[1];
name = null;
}
if (name != null) {
name = '' + name || '';
if (xmldec == null) {
xmldec = {
'version': '1.0'
};
}
}
this.allowSurrogateChars = options != null ? options.allowSurrogateChars : void 0;
if ((xmldec != null) && !(xmldec.version != null)) {
throw new Error("Version number is required");
}
if (xmldec != null) {
xmldec.version = '' + xmldec.version || '';
if (!xmldec.version.match(/1\.[0-9]+/)) {
throw new Error("Invalid version number: " + xmldec.version);
}
att = {
version: xmldec.version
};
if (xmldec.encoding != null) {
xmldec.encoding = '' + xmldec.encoding || '';
if (!xmldec.encoding.match(/[A-Za-z](?:[A-Za-z0-9._-]|-)*/)) {
throw new Error("Invalid encoding: " + xmldec.encoding);
}
att.encoding = xmldec.encoding;
}
if (xmldec.standalone != null) {
att.standalone = xmldec.standalone ? "yes" : "no";
}
child = new XMLFragment(this, '?xml', att);
this.children.push(child);
}
if (doctype != null) {
att = {};
if (name != null) {
att.name = name;
}
if (doctype.ext != null) {
doctype.ext = '' + doctype.ext || '';
att.ext = doctype.ext;
}
child = new XMLFragment(this, '!DOCTYPE', att);
this.children.push(child);
}
if (name != null) {
this.begin(name);
}
}
XMLBuilder.prototype.begin = function(name, xmldec, doctype) {
var doc, root;
if (!(name != null)) {
throw new Error("Root element needs a name");
}
if (this.rootObject) {
this.children = [];
this.rootObject = null;
}
if (xmldec != null) {
doc = new XMLBuilder(name, xmldec, doctype);
return doc.root();
}
name = '' + name || '';
root = new XMLFragment(this, name, {});
root.isRoot = true;
root.documentObject = this;
this.children.push(root);
this.rootObject = root;
return root;
};
XMLBuilder.prototype.root = function() {
return this.rootObject;
};
XMLBuilder.prototype.end = function(options) {
return toString(options);
};
XMLBuilder.prototype.toString = function(options) {
var child, r, _i, _len, _ref;
r = '';
_ref = this.children;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
child = _ref[_i];
r += child.toString(options);
}
return r;
};
XMLBuilder.prototype.is = function(obj, type) {
var clas;
clas = Object.prototype.toString.call(obj).slice(8, -1);
return (obj != null) && clas === type;
};
XMLBuilder.prototype.assertLegalChar = function(str) {
var chars, chr;
if (this.allowSurrogateChars) {
chars = /[\u0000-\u0008\u000B-\u000C\u000E-\u001F\uFFFE-\uFFFF]/;
} else {
chars = /[\u0000-\u0008\u000B-\u000C\u000E-\u001F\uD800-\uDFFF\uFFFE-\uFFFF]/;
}
chr = str.match(chars);
if (chr) {
throw new Error("Invalid character (" + chr + ") in string: " + str + " at index " + chr.index);
}
};
return XMLBuilder;
})();
module.exports = XMLBuilder;
}).call(this);
+415
View File
@@ -0,0 +1,415 @@
// Generated by CoffeeScript 1.3.3
(function() {
var XMLFragment,
__hasProp = {}.hasOwnProperty;
XMLFragment = (function() {
function XMLFragment(parent, name, attributes, text) {
this.isRoot = false;
this.documentObject = null;
this.parent = parent;
this.name = name;
this.attributes = attributes;
this.value = text;
this.children = [];
this.assertLegalChar = parent.assertLegalChar;
}
XMLFragment.prototype.element = function(name, attributes, text) {
var child, key, val, _ref, _ref1;
if (!(name != null)) {
throw new Error("Missing element name");
}
name = '' + name || '';
this.assertLegalChar(name);
if (attributes == null) {
attributes = {};
}
if (this.is(attributes, 'String') && this.is(text, 'Object')) {
_ref = [text, attributes], attributes = _ref[0], text = _ref[1];
} else if (this.is(attributes, 'String')) {
_ref1 = [{}, attributes], attributes = _ref1[0], text = _ref1[1];
}
for (key in attributes) {
if (!__hasProp.call(attributes, key)) continue;
val = attributes[key];
val = '' + val || '';
attributes[key] = this.escape(val);
}
child = new XMLFragment(this, name, attributes);
if (text != null) {
text = '' + text || '';
text = this.escape(text);
this.assertLegalChar(text);
child.raw(text);
}
this.children.push(child);
return child;
};
XMLFragment.prototype.insertBefore = function(name, attributes, text) {
var child, i, key, val, _ref, _ref1;
if (this.isRoot) {
throw new Error("Cannot insert elements at root level");
}
if (!(name != null)) {
throw new Error("Missing element name");
}
name = '' + name || '';
this.assertLegalChar(name);
if (attributes == null) {
attributes = {};
}
if (this.is(attributes, 'String') && this.is(text, 'Object')) {
_ref = [text, attributes], attributes = _ref[0], text = _ref[1];
} else if (this.is(attributes, 'String')) {
_ref1 = [{}, attributes], attributes = _ref1[0], text = _ref1[1];
}
for (key in attributes) {
if (!__hasProp.call(attributes, key)) continue;
val = attributes[key];
val = '' + val || '';
attributes[key] = this.escape(val);
}
child = new XMLFragment(this.parent, name, attributes);
if (text != null) {
text = '' + text || '';
text = this.escape(text);
this.assertLegalChar(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 child, i, key, val, _ref, _ref1;
if (this.isRoot) {
throw new Error("Cannot insert elements at root level");
}
if (!(name != null)) {
throw new Error("Missing element name");
}
name = '' + name || '';
this.assertLegalChar(name);
if (attributes == null) {
attributes = {};
}
if (this.is(attributes, 'String') && this.is(text, 'Object')) {
_ref = [text, attributes], attributes = _ref[0], text = _ref[1];
} else if (this.is(attributes, 'String')) {
_ref1 = [{}, attributes], attributes = _ref1[0], text = _ref1[1];
}
for (key in attributes) {
if (!__hasProp.call(attributes, key)) continue;
val = attributes[key];
val = '' + val || '';
attributes[key] = this.escape(val);
}
child = new XMLFragment(this.parent, name, attributes);
if (text != null) {
text = '' + text || '';
text = this.escape(text);
this.assertLegalChar(text);
child.raw(text);
}
i = this.parent.children.indexOf(this);
this.parent.children.splice(i + 1, 0, child);
return child;
};
XMLFragment.prototype.remove = function() {
var i, _ref;
if (this.isRoot) {
throw new Error("Cannot remove the root element");
}
i = this.parent.children.indexOf(this);
[].splice.apply(this.parent.children, [i, i - i + 1].concat(_ref = [])), _ref;
return this.parent;
};
XMLFragment.prototype.text = function(value) {
var child;
if (!(value != null)) {
throw new Error("Missing element text");
}
value = '' + value || '';
value = this.escape(value);
this.assertLegalChar(value);
child = new XMLFragment(this, '', {}, value);
this.children.push(child);
return this;
};
XMLFragment.prototype.cdata = function(value) {
var child;
if (!(value != null)) {
throw new Error("Missing CDATA text");
}
value = '' + value || '';
this.assertLegalChar(value);
if (value.match(/]]>/)) {
throw new Error("Invalid CDATA text: " + value);
}
child = new XMLFragment(this, '', {}, '<![CDATA[' + value + ']]>');
this.children.push(child);
return this;
};
XMLFragment.prototype.comment = function(value) {
var child;
if (!(value != null)) {
throw new Error("Missing comment text");
}
value = '' + value || '';
value = this.escape(value);
this.assertLegalChar(value);
if (value.match(/--/)) {
throw new Error("Comment text cannot contain double-hypen: " + value);
}
child = new XMLFragment(this, '', {}, '<!-- ' + value + ' -->');
this.children.push(child);
return this;
};
XMLFragment.prototype.raw = function(value) {
var child;
if (!(value != null)) {
throw new Error("Missing raw text");
}
value = '' + value || '';
child = new XMLFragment(this, '', {}, value);
this.children.push(child);
return this;
};
XMLFragment.prototype.up = function() {
if (this.isRoot) {
throw new Error("This node has no parent. Use doc() if you need to get the document object.");
}
return this.parent;
};
XMLFragment.prototype.root = function() {
var child;
if (this.isRoot) {
return this;
}
child = this.parent;
while (!child.isRoot) {
child = child.parent;
}
return child;
};
XMLFragment.prototype.document = function() {
return this.root().documentObject;
};
XMLFragment.prototype.end = function(options) {
return this.document().toString(options);
};
XMLFragment.prototype.prev = function() {
var i;
if (this.isRoot) {
throw new Error("Root node has no siblings");
}
i = this.parent.children.indexOf(this);
if (i < 1) {
throw new Error("Already at the first node");
}
return this.parent.children[i - 1];
};
XMLFragment.prototype.next = function() {
var i;
if (this.isRoot) {
throw new Error("Root node has no siblings");
}
i = this.parent.children.indexOf(this);
if (i === -1 || i === this.parent.children.length - 1) {
throw new Error("Already at the last node");
}
return this.parent.children[i + 1];
};
XMLFragment.prototype.clone = function(deep) {
var clonedSelf;
clonedSelf = new XMLFragment(this.parent, this.name, this.attributes, this.value);
if (deep) {
this.children.forEach(function(child) {
var clonedChild;
clonedChild = child.clone(deep);
clonedChild.parent = clonedSelf;
return clonedSelf.children.push(clonedChild);
});
}
return clonedSelf;
};
XMLFragment.prototype.importXMLBuilder = function(xmlbuilder) {
var clonedRoot;
clonedRoot = xmlbuilder.root().clone(true);
clonedRoot.parent = this;
this.children.push(clonedRoot);
clonedRoot.isRoot = false;
return this;
};
XMLFragment.prototype.attribute = function(name, value) {
var _ref;
if (!(name != null)) {
throw new Error("Missing attribute name");
}
if (!(value != null)) {
throw new Error("Missing attribute value");
}
name = '' + name || '';
value = '' + value || '';
if ((_ref = this.attributes) == null) {
this.attributes = {};
}
this.attributes[name] = this.escape(value);
return this;
};
XMLFragment.prototype.removeAttribute = function(name) {
if (!(name != null)) {
throw new Error("Missing attribute name");
}
name = '' + name || '';
delete this.attributes[name];
return this;
};
XMLFragment.prototype.toString = function(options, level) {
var attName, attValue, child, indent, newline, pretty, r, space, _i, _len, _ref, _ref1;
pretty = (options != null) && options.pretty || false;
indent = (options != null) && options.indent || ' ';
newline = (options != null) && options.newline || '\n';
level || (level = 0);
space = new Array(level + 1).join(indent);
r = '';
if (pretty) {
r += space;
}
if (!(this.value != null)) {
r += '<' + this.name;
} else {
r += '' + this.value;
}
_ref = this.attributes;
for (attName in _ref) {
if (!__hasProp.call(_ref, attName)) continue;
attValue = _ref[attName];
if (this.name === '!DOCTYPE') {
r += ' ' + attValue;
} else {
r += ' ' + attName + '="' + attValue + '"';
}
}
if (this.children.length === 0) {
if (!(this.value != null)) {
r += this.name === '?xml' ? '?>' : this.name === '!DOCTYPE' ? '>' : '/>';
}
if (pretty) {
r += newline;
}
} else if (pretty && this.children.length === 1 && (this.children[0].value != null)) {
r += '>';
r += this.children[0].value;
r += '</' + this.name + '>';
r += newline;
} else {
r += '>';
if (pretty) {
r += newline;
}
_ref1 = this.children;
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
child = _ref1[_i];
r += child.toString(options, level + 1);
}
if (pretty) {
r += space;
}
r += '</' + this.name + '>';
if (pretty) {
r += newline;
}
}
return r;
};
XMLFragment.prototype.escape = function(str) {
return str.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/'/g, '&apos;').replace(/"/g, '&quot;');
};
XMLFragment.prototype.is = function(obj, type) {
var clas;
clas = Object.prototype.toString.call(obj).slice(8, -1);
return (obj != null) && clas === type;
};
XMLFragment.prototype.ele = function(name, attributes, text) {
return this.element(name, attributes, text);
};
XMLFragment.prototype.txt = function(value) {
return this.text(value);
};
XMLFragment.prototype.dat = function(value) {
return this.cdata(value);
};
XMLFragment.prototype.att = function(name, value) {
return this.attribute(name, value);
};
XMLFragment.prototype.com = function(value) {
return this.comment(value);
};
XMLFragment.prototype.doc = function() {
return this.document();
};
XMLFragment.prototype.e = function(name, attributes, text) {
return this.element(name, attributes, text);
};
XMLFragment.prototype.t = function(value) {
return this.text(value);
};
XMLFragment.prototype.d = function(value) {
return this.cdata(value);
};
XMLFragment.prototype.a = function(name, value) {
return this.attribute(name, value);
};
XMLFragment.prototype.c = function(value) {
return this.comment(value);
};
XMLFragment.prototype.r = function(value) {
return this.raw(value);
};
XMLFragment.prototype.u = function() {
return this.up();
};
return XMLFragment;
})();
module.exports = XMLFragment;
}).call(this);
+15
View File
@@ -0,0 +1,15 @@
// Generated by CoffeeScript 1.3.3
(function() {
var XMLBuilder;
XMLBuilder = require('./XMLBuilder');
module.exports.create = function(name, xmldec, doctype, options) {
if (name != null) {
return new XMLBuilder(name, xmldec, doctype, options).root();
} else {
return new XMLBuilder();
}
};
}).call(this);
+88
View File
@@ -0,0 +1,88 @@
{
"_args": [
[
"xmlbuilder@0.4.3",
"c:\\users\\luis\\source\\repos\\AACharly\\node_modules\\azure-storage"
]
],
"_defaultsLoaded": true,
"_engineSupported": true,
"_from": "xmlbuilder@0.4.3",
"_id": "xmlbuilder@0.4.3",
"_inCache": true,
"_location": "/xmlbuilder",
"_nodeVersion": "v0.6.3",
"_npmUser": {
"email": "oozcitak@gmail.com",
"name": "oozcitak"
},
"_npmVersion": "1.1.0-alpha-2",
"_phantomChildren": {},
"_requested": {
"name": "xmlbuilder",
"raw": "xmlbuilder@0.4.3",
"rawSpec": "0.4.3",
"scope": null,
"spec": "0.4.3",
"type": "version"
},
"_requiredBy": [
"/azure-storage"
],
"_resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-0.4.3.tgz",
"_shasum": "c4614ba74e0ad196e609c9272cd9e1ddb28a8a58",
"_shrinkwrap": null,
"_spec": "xmlbuilder@0.4.3",
"_where": "c:\\users\\luis\\source\\repos\\AACharly\\node_modules\\azure-storage",
"author": {
"email": "oozcitak@gmail.com",
"name": "Ozgur Ozcitak"
},
"bugs": {
"url": "http://github.com/oozcitak/xmlbuilder-js/issues"
},
"dependencies": {},
"description": "An XML builder for node.js",
"devDependencies": {
"coffee-script": "1.1.x"
},
"directories": {},
"dist": {
"shasum": "c4614ba74e0ad196e609c9272cd9e1ddb28a8a58",
"tarball": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-0.4.3.tgz"
},
"engines": {
"node": ">=0.2.0"
},
"homepage": "http://github.com/oozcitak/xmlbuilder-js",
"installable": true,
"keywords": [
"xml",
"xmlbuilder"
],
"licenses": [
{
"type": "MIT",
"url": "http://opensource.org/licenses/mit-license.php"
}
],
"main": "./lib/index",
"maintainers": [
{
"name": "oozcitak",
"email": "oozcitak@gmail.com"
}
],
"name": "xmlbuilder",
"optionalDependencies": {},
"repository": {
"type": "git",
"url": "git://github.com/oozcitak/xmlbuilder-js.git"
},
"scripts": {
"postpublish": "make clean",
"prepublish": "make release",
"test": "make test"
},
"version": "0.4.3"
}