Comparing version 0.4.4 to 0.4.5
@@ -1,2 +0,2 @@ | ||
// Generated by CoffeeScript 1.7.1 | ||
// Generated by CoffeeScript 1.8.0 | ||
(function() { | ||
@@ -3,0 +3,0 @@ var xml2js; |
@@ -1,2 +0,2 @@ | ||
// Generated by CoffeeScript 1.7.1 | ||
// Generated by CoffeeScript 1.8.0 | ||
(function() { | ||
@@ -3,0 +3,0 @@ var prefixMatch; |
@@ -1,4 +0,4 @@ | ||
// Generated by CoffeeScript 1.7.1 | ||
// Generated by CoffeeScript 1.8.0 | ||
(function() { | ||
var bom, builder, events, isEmpty, processName, processors, sax, | ||
var bom, builder, escapeCDATA, events, isEmpty, processName, processors, requiresCDATA, sax, wrapCDATA, | ||
__hasProp = {}.hasOwnProperty, | ||
@@ -31,2 +31,14 @@ __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; }, | ||
requiresCDATA = function(entry) { | ||
return entry.indexOf('&') >= 0 || entry.indexOf('>') >= 0 || entry.indexOf('<') >= 0; | ||
}; | ||
wrapCDATA = function(entry) { | ||
return "<![CDATA[" + (escapeCDATA(entry)) + "]]>"; | ||
}; | ||
escapeCDATA = function(entry) { | ||
return entry.replace(']]>', ']]]]><![CDATA[>'); | ||
}; | ||
exports.processors = processors; | ||
@@ -54,3 +66,4 @@ | ||
attrNameProcessors: null, | ||
tagNameProcessors: null | ||
tagNameProcessors: null, | ||
emptyTag: '' | ||
}, | ||
@@ -89,3 +102,6 @@ "0.2": { | ||
}, | ||
headless: false | ||
headless: false, | ||
chunkSize: 10000, | ||
emptyTag: '', | ||
cdata: false | ||
} | ||
@@ -132,38 +148,52 @@ }; | ||
} | ||
render = function(element, obj) { | ||
var attr, child, entry, index, key, value, _ref, _ref1; | ||
if (typeof obj !== 'object') { | ||
element.txt(obj); | ||
} else { | ||
for (key in obj) { | ||
if (!__hasProp.call(obj, key)) continue; | ||
child = obj[key]; | ||
if (key === attrkey) { | ||
if (typeof child === "object") { | ||
for (attr in child) { | ||
value = child[attr]; | ||
element = element.att(attr, value); | ||
render = (function(_this) { | ||
return function(element, obj) { | ||
var attr, child, entry, index, key, value; | ||
if (typeof obj !== 'object') { | ||
if (_this.options.cdata && requiresCDATA(obj)) { | ||
element.raw(wrapCDATA(obj)); | ||
} else { | ||
element.txt(obj); | ||
} | ||
} else { | ||
for (key in obj) { | ||
if (!__hasProp.call(obj, key)) continue; | ||
child = obj[key]; | ||
if (key === attrkey) { | ||
if (typeof child === "object") { | ||
for (attr in child) { | ||
value = child[attr]; | ||
element = element.att(attr, value); | ||
} | ||
} | ||
} | ||
} else if (key === charkey) { | ||
element = element.txt(child); | ||
} else if (typeof child === 'object' && ((child != null ? child.constructor : void 0) != null) && ((child != null ? (_ref = child.constructor) != null ? _ref.name : void 0 : void 0) != null) && (child != null ? (_ref1 = child.constructor) != null ? _ref1.name : void 0 : void 0) === 'Array') { | ||
for (index in child) { | ||
if (!__hasProp.call(child, index)) continue; | ||
entry = child[index]; | ||
if (typeof entry === 'string') { | ||
element = element.ele(key, entry).up(); | ||
} else if (key === charkey) { | ||
if (_this.options.cdata && requiresCDATA(child)) { | ||
element = element.raw(wrapCDATA(child)); | ||
} else { | ||
element = arguments.callee(element.ele(key), entry).up(); | ||
element = element.txt(child); | ||
} | ||
} else if (typeof child === 'object' && child instanceof Array) { | ||
for (index in child) { | ||
if (!__hasProp.call(child, index)) continue; | ||
entry = child[index]; | ||
if (typeof entry === 'string') { | ||
if (_this.options.cdata && requiresCDATA(entry)) { | ||
element = element.ele(key).raw(wrapCDATA(entry)).up(); | ||
} else { | ||
element = element.ele(key, entry).up(); | ||
} | ||
} else { | ||
element = arguments.callee(element.ele(key), entry).up(); | ||
} | ||
} | ||
} else if (typeof child === "object") { | ||
element = arguments.callee(element.ele(key), child).up(); | ||
} else { | ||
element = element.ele(key, child.toString()).up(); | ||
} | ||
} else if (typeof child === "object") { | ||
element = arguments.callee(element.ele(key), child).up(); | ||
} else { | ||
element = element.ele(key, child.toString()).up(); | ||
} | ||
} | ||
} | ||
return element; | ||
}; | ||
return element; | ||
}; | ||
})(this); | ||
rootElement = builder.create(rootName, this.options.xmldec, this.options.doctype, { | ||
@@ -186,2 +216,3 @@ headless: this.options.headless | ||
this.assignOrPush = __bind(this.assignOrPush, this); | ||
this.processAsync = __bind(this.processAsync, this); | ||
var key, value, _ref; | ||
@@ -215,2 +246,17 @@ if (!(this instanceof exports.Parser)) { | ||
Parser.prototype.processAsync = function() { | ||
var chunk; | ||
if (this.remaining.length <= this.options.chunkSize) { | ||
chunk = this.remaining; | ||
this.remaining = ''; | ||
this.saxParser = this.saxParser.write(chunk); | ||
return this.saxParser.close(); | ||
} else { | ||
chunk = this.remaining.substr(0, this.options.chunkSize); | ||
this.remaining = this.remaining.substr(this.options.chunkSize, this.remaining.length); | ||
this.saxParser = this.saxParser.write(chunk); | ||
return setImmediate(this.processAsync); | ||
} | ||
}; | ||
Parser.prototype.assignOrPush = function(obj, key, newValue) { | ||
@@ -310,3 +356,3 @@ if (!(key in obj)) { | ||
if (isEmpty(obj)) { | ||
obj = _this.options.emptyTag !== void 0 ? _this.options.emptyTag : emptyStr; | ||
obj = _this.options.emptyTag !== '' ? _this.options.emptyTag : emptyStr; | ||
} | ||
@@ -386,22 +432,11 @@ if (_this.options.validator != null) { | ||
this.reset(); | ||
if (this.options.async) { | ||
return process.nextTick(function() { | ||
return cb(null, result); | ||
}); | ||
} else { | ||
return cb(null, result); | ||
} | ||
return cb(null, result); | ||
}); | ||
this.on("error", function(err) { | ||
this.reset(); | ||
if (this.options.async) { | ||
return process.nextTick(function() { | ||
return cb(err); | ||
}); | ||
} else { | ||
return cb(err); | ||
} | ||
return cb(err); | ||
}); | ||
} | ||
if (str.toString().trim() === '') { | ||
str = str.toString(); | ||
if (str.trim() === '') { | ||
this.emit("end", null); | ||
@@ -411,3 +446,9 @@ return true; | ||
try { | ||
return this.saxParser.write(bom.stripBOM(str.toString())).close(); | ||
str = bom.stripBOM(str); | ||
if (this.options.async) { | ||
this.remaining = str; | ||
setImmediate(this.processAsync); | ||
this.saxParser; | ||
} | ||
return this.saxParser.write(str).close(); | ||
} catch (_error) { | ||
@@ -418,2 +459,4 @@ err = _error; | ||
return this.saxParser.errThrown = true; | ||
} else if (this.saxParser.ended) { | ||
throw err; | ||
} | ||
@@ -420,0 +463,0 @@ } |
@@ -6,3 +6,3 @@ { | ||
"homepage" : "https://github.com/Leonidas-from-XIV/node-xml2js", | ||
"version" : "0.4.4", | ||
"version" : "0.4.5", | ||
"author" : "Marek Kubica <marek@xivilization.net> (http://xivilization.net)", | ||
@@ -35,3 +35,6 @@ "contributors" : [ | ||
"Leore Avidar <leore.avidar@gmail.com> (http://leoreavidar.com/)", | ||
"Dave Aitken <dave.aitken@gmail.com> (http://www.actionshrimp.com/)" | ||
"Dave Aitken <dave.aitken@gmail.com> (http://www.actionshrimp.com/)", | ||
"Shaney Orrowe <shaney.orrowe@practiceweb.co.uk>", | ||
"Candle <candle@candle.me.uk>", | ||
"Jess Telford <hi@jes.st> (http://jes.st)" | ||
], | ||
@@ -38,0 +41,0 @@ "main" : "./lib/xml2js", |
@@ -174,3 +174,4 @@ node-xml2js | ||
default configuration, except for `attrkey`, `charkey` and `explicitArray` options | ||
you can redefine to your taste. Writing CDATA is not currently supported. | ||
you can redefine to your taste. Writing CDATA is supported via setting the `cdata` | ||
option to `true`. | ||
@@ -230,4 +231,3 @@ Processing attribute and tag names | ||
node in the resulting object. | ||
* `emptyTag` (default: `undefined`): what will the value of empty nodes be. | ||
Default is `{}`. | ||
* `emptyTag` (default: `''`): what will the value of empty nodes be. | ||
* `explicitArray` (default: `true`): Always put child nodes in an array if | ||
@@ -296,2 +296,3 @@ true; otherwise an array is created only if there is more than one. | ||
* `headless` (default: `false`): omit the XML header. Added in 0.4.3. | ||
* `cdata` (default: `false`): wrap text nodes in `<![CDATA[ ... ]]>`. Added in 0.4.5. | ||
@@ -298,0 +299,0 @@ `renderOpts`, `xmldec`,`doctype` and `headless` pass through to |
4
x.js
@@ -19,7 +19,9 @@ var util = require('util'); | ||
</Items>" | ||
var myxml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\ | ||
<empty />" | ||
xml2js.parseString(myxml, function (e, r) { | ||
console.log(util.inspect(r, false, null)); | ||
console.log(new xml2js.Builder().buildObject(r)); | ||
//console.log(new xml2js.Builder().buildObject(r)); | ||
}); | ||
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
105138
19
531
345
1