Comparing version 0.1.11 to 0.1.12
@@ -20,4 +20,5 @@ (function() { | ||
this.parseString = __bind(this.parseString, this); | ||
var attrkey, charkey, err, key, options, stack, value; | ||
options = { | ||
this.reset = __bind(this.reset, this); | ||
var key, value; | ||
this.options = { | ||
explicitCharkey: false, | ||
@@ -28,3 +29,4 @@ trim: true, | ||
charkey: "#", | ||
explicitArray: false | ||
explicitArray: false, | ||
ignoreAttrs: false | ||
}; | ||
@@ -34,4 +36,9 @@ for (key in opts) { | ||
value = opts[key]; | ||
options[key] = value; | ||
this.options[key] = value; | ||
} | ||
this.reset(); | ||
} | ||
Parser.prototype.reset = function() { | ||
var attrkey, charkey, err, stack; | ||
this.removeAllListeners(); | ||
this.saxParser = sax.parser(true, { | ||
@@ -48,7 +55,7 @@ trim: false, | ||
}, this); | ||
this.EXPLICIT_CHARKEY = options.explicitCharkey; | ||
this.EXPLICIT_CHARKEY = this.options.explicitCharkey; | ||
this.resultObject = null; | ||
stack = []; | ||
attrkey = options.attrkey; | ||
charkey = options.charkey; | ||
attrkey = this.options.attrkey; | ||
charkey = this.options.charkey; | ||
this.saxParser.onopentag = __bind(function(node) { | ||
@@ -58,9 +65,11 @@ var key, obj, _ref; | ||
obj[charkey] = ""; | ||
_ref = node.attributes; | ||
for (key in _ref) { | ||
if (!__hasProp.call(_ref, key)) continue; | ||
if (!(attrkey in obj)) { | ||
obj[attrkey] = {}; | ||
if (!this.options.ignoreAttrs) { | ||
_ref = node.attributes; | ||
for (key in _ref) { | ||
if (!__hasProp.call(_ref, key)) continue; | ||
if (!(attrkey in obj)) { | ||
obj[attrkey] = {}; | ||
} | ||
obj[attrkey][key] = node.attributes[key]; | ||
} | ||
obj[attrkey][key] = node.attributes[key]; | ||
} | ||
@@ -79,6 +88,6 @@ obj["#name"] = node.name; | ||
} else { | ||
if (options.trim) { | ||
if (this.options.trim) { | ||
obj[charkey] = obj[charkey].trim(); | ||
} | ||
if (options.normalize) { | ||
if (this.options.normalize) { | ||
obj[charkey] = obj[charkey].replace(/\s{2,}/g, " ").trim(); | ||
@@ -90,7 +99,7 @@ } | ||
} | ||
if (options.emptyTag !== void 0 && isEmpty(obj)) { | ||
obj = options.emptyTag; | ||
if (this.options.emptyTag !== void 0 && isEmpty(obj)) { | ||
obj = this.options.emptyTag; | ||
} | ||
if (stack.length > 0) { | ||
if (!options.explicitArray) { | ||
if (!this.options.explicitArray) { | ||
if (!(nodeName in s)) { | ||
@@ -112,3 +121,3 @@ return s[nodeName] = obj; | ||
} else { | ||
if (options.explicitRoot) { | ||
if (this.options.explicitRoot) { | ||
old = obj; | ||
@@ -122,3 +131,3 @@ obj = {}; | ||
}, this); | ||
this.saxParser.ontext = this.saxParser.oncdata = __bind(function(text) { | ||
return this.saxParser.ontext = this.saxParser.oncdata = __bind(function(text) { | ||
var s; | ||
@@ -130,9 +139,11 @@ s = stack[stack.length - 1]; | ||
}, this); | ||
} | ||
}; | ||
Parser.prototype.parseString = function(str, cb) { | ||
if ((cb != null) && typeof cb === "function") { | ||
this.on("end", function(result) { | ||
this.reset(); | ||
return cb(null, result); | ||
}); | ||
this.on("error", function(err) { | ||
this.reset(); | ||
return cb(err); | ||
@@ -139,0 +150,0 @@ }); |
@@ -6,3 +6,3 @@ { | ||
"homepage" : "https://github.com/Leonidas-from-XIV/node-xml2js", | ||
"version" : "0.1.11", | ||
"version" : "0.1.12", | ||
"author" : "Marek Kubica <marek@xivilization.net> (http://xivilization.net)", | ||
@@ -18,3 +18,4 @@ "contributors" : [ | ||
"Contra <contra@australia.edu> (https://github.com/Contra)", | ||
"Marcelo Diniz <marudiniz@gmail.com> (https://github.com/mdiniz)" | ||
"Marcelo Diniz <marudiniz@gmail.com> (https://github.com/mdiniz)", | ||
"Michael Hart (https://github.com/mhart)" | ||
], | ||
@@ -21,0 +22,0 @@ "main" : "./lib/xml2js", |
@@ -86,3 +86,3 @@ node-xml2js | ||
Just wrap the `result` object in a call to `JSON.stringify` like this | ||
`JSON.strintify(result)`. You get a string containing the JSON representation | ||
`JSON.stringify(result)`. You get a string containing the JSON representation | ||
of the parsed object that you can feed to JSON-hungry consumers. | ||
@@ -125,2 +125,4 @@ | ||
true; otherwise an array is created only if there is more than one. | ||
* `ignoreAttrs` (default: `false`): Ignore all XML attributes and only create | ||
text nodes. | ||
@@ -127,0 +129,0 @@ These default settings are for backward-compatibility (and might change in the |
Sorry, the diff of this file is not supported yet
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
23265
150
137
0
1