Socket
Socket
Sign inDemoInstall

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.13 to 0.1.14

121

lib/xml2js.js

@@ -0,4 +1,7 @@

// Generated by CoffeeScript 1.3.1
(function() {
var events, isEmpty, sax;
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, __hasProp = Object.prototype.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 events, isEmpty, sax,
__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; },
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };

@@ -13,20 +16,62 @@ sax = require('sax');

exports.Parser = (function() {
exports.defaults = {
"0.1": {
explicitCharkey: false,
trim: true,
normalize: true,
attrkey: "@",
charkey: "#",
explicitArray: false,
ignoreAttrs: false,
mergeAttrs: false,
explicitRoot: false,
validator: null
},
"0.2": {
explicitCharkey: false,
trim: false,
normalize: false,
attrkey: "$",
charkey: "_",
explicitArray: true,
ignoreAttrs: false,
mergeAttrs: false,
explicitRoot: true,
validator: null
}
};
__extends(Parser, events.EventEmitter);
exports.ValidationError = (function(_super) {
__extends(ValidationError, _super);
ValidationError.name = 'ValidationError';
function ValidationError(message) {
this.message = message;
}
return ValidationError;
})(Error);
exports.Parser = (function(_super) {
__extends(Parser, _super);
Parser.name = 'Parser';
function Parser(opts) {
this.parseString = __bind(this.parseString, this);
this.reset = __bind(this.reset, this);
var key, value;
this.options = {
explicitCharkey: false,
trim: true,
normalize: true,
attrkey: "@",
charkey: "#",
explicitArray: false,
ignoreAttrs: false,
mergeAttrs: false
};
var key, value, _ref;
this.options = {};
_ref = exports.defaults["0.1"];
for (key in _ref) {
if (!__hasProp.call(_ref, key)) continue;
value = _ref[key];
this.options[key] = value;
}
for (key in opts) {

@@ -41,4 +86,4 @@ if (!__hasProp.call(opts, key)) continue;

Parser.prototype.reset = function() {
var attrkey, charkey, err, stack;
var _this = this;
var attrkey, charkey, err, stack,
_this = this;
this.removeAllListeners();

@@ -69,3 +114,5 @@ this.saxParser = sax.parser(true, {

if (!__hasProp.call(_ref, key)) continue;
if (!(attrkey in obj) && !_this.options.mergeAttrs) obj[attrkey] = {};
if (!(attrkey in obj) && !_this.options.mergeAttrs) {
obj[attrkey] = {};
}
if (_this.options.mergeAttrs) {

@@ -82,3 +129,3 @@ obj[key] = node.attributes[key];

this.saxParser.onclosetag = function() {
var nodeName, obj, old, s;
var node, nodeName, obj, old, s, xpath;
obj = stack.pop();

@@ -91,3 +138,5 @@ nodeName = obj["#name"];

} else {
if (_this.options.trim) obj[charkey] = obj[charkey].trim();
if (_this.options.trim) {
obj[charkey] = obj[charkey].trim();
}
if (_this.options.normalize) {

@@ -103,2 +152,14 @@ obj[charkey] = obj[charkey].replace(/\s{2,}/g, " ").trim();

}
if (_this.options.validator != null) {
xpath = "/" + ((function() {
var _i, _len, _results;
_results = [];
for (_i = 0, _len = stack.length; _i < _len; _i++) {
node = stack[_i];
_results.push(node["#name"]);
}
return _results;
})()).concat(nodeName).join("/");
obj = _this.options.validator(xpath, s && s[nodeName], obj);
}
if (stack.length > 0) {

@@ -116,3 +177,5 @@ if (!_this.options.explicitArray) {

} else {
if (!(s[nodeName] instanceof Array)) s[nodeName] = [];
if (!(s[nodeName] instanceof Array)) {
s[nodeName] = [];
}
return s[nodeName].push(obj);

@@ -133,3 +196,5 @@ }

s = stack[stack.length - 1];
if (s) return s[charkey] += text;
if (s) {
return s[charkey] += text;
}
};

@@ -153,3 +218,11 @@ };

}
return this.saxParser.write(str.toString());
try {
return this.saxParser.write(str.toString());
} catch (ex) {
if (ex instanceof exports.ValidationError) {
return this.emit("error", ex.message);
} else {
throw ex;
}
}
};

@@ -159,4 +232,4 @@

})();
})(events.EventEmitter);
}).call(this);

8

package.json

@@ -6,3 +6,3 @@ {

"homepage" : "https://github.com/Leonidas-from-XIV/node-xml2js",
"version" : "0.1.13",
"version" : "0.1.14",
"author" : "Marek Kubica <marek@xivilization.net> (http://xivilization.net)",

@@ -21,3 +21,4 @@ "contributors" : [

"Zachary Scott <zachary@zacharyscott.net> (http://zacharyscott.net/)",
"Raoul Millais (https://github.com/raoulmillais)"
"Raoul Millais (https://github.com/raoulmillais)",
"Salsita Software (http://www.salsitasoft.com/)"
],

@@ -37,4 +38,5 @@ "main" : "./lib/xml2js",

"coffee-script" : ">=1.0.1",
"zap" : ">=0.2.3"
"zap" : ">=0.2.3",
"docco" : ">=0.3.0"
}
}

@@ -129,2 +129,5 @@ node-xml2js

attribute object. This option is ignored if `ignoreAttrs` is `false`.
* `validator` (default `null`): You can specify a callable that validates
the resulting structure somehow, however you want. See unit tests
for an example.

@@ -131,0 +134,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

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