Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

xml2js

Package Overview
Dependencies
Maintainers
2
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xml2js - npm Package Compare versions

Comparing version 0.1.11 to 0.1.12

53

lib/xml2js.js

@@ -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

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