New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

libxml-to-js

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

libxml-to-js - npm Package Compare versions

Comparing version 0.3.4 to 0.3.5

tests/data/text.xml

3

CHANGELOG.md

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

## v0.3.5
* Improved the text kludge and namespaces support. Thanks to @[VirgileD](https://github.com/VirgileD) for the contribution.
## v0.3.4

@@ -2,0 +5,0 @@ * XPath queries support for parsing just parts of the XML document. Thanks to @[Marsup](https://github.com/Marsup) for the contribution.

@@ -25,2 +25,16 @@ var libxmljs = require('libxmljs');

/**
* Checks if an object is empty
* @param obj
* @returns bool
*/
var isEmpty = function (obj) {
for(var prop in obj) {
if(obj.hasOwnProperty(prop)) {
return false;
}
}
return true;
}
/**
* The core function of this module

@@ -55,3 +69,3 @@ * @param obj

// <"text" kludge>
if (children[i].name() == 'text') {
if (children[i].name() == 'text' && children[i].type() == 'text') {
jsobj['#'] = children[i].text().trim();

@@ -119,3 +133,3 @@ if (jsobj['#'].match(/^\s*$/)) {

if ( ! recurse) {
if (namespaces) {
if (namespaces && ! isEmpty(namespaces)) {
if ( ! jsobj['@']) {

@@ -136,3 +150,3 @@ jsobj['@'] = {};

module.exports = function (xml, xpath, callback) {
if(!callback) {
if( ! callback) {
callback = xpath;

@@ -145,3 +159,3 @@ xpath = null;

jsDocument = libxml2js(xmlDocument);
if(!!xpath) {
if( !! xpath) {
xmlDocument.find(xpath, jsDocument['@'].xmlns).forEach(function(item) {

@@ -148,0 +162,0 @@ selected.push(libxml2js(item, true).jsobj);

5

package.json
{
"name": "libxml-to-js",
"version": "0.3.4",
"version": "0.3.5",
"main": "./lib/libxml-to-js.js",

@@ -23,2 +23,5 @@ "description": "XML to JavaScript object parser based on libxmljs",

"name": "Marsup"
},
{
"name": "VirgileD"
}

@@ -25,0 +28,0 @@ ],

@@ -83,1 +83,2 @@ ## About

* @[Marsup](https://github.com/Marsup): XPath queries support.
* @[VirgileD](https://github.com/VirgileD): improved text kludge and namespaces support

@@ -6,5 +6,12 @@ var parser = require('../');

var callback = false;
parser(fs.readFileSync('data/broken.xml').toString(), function (err, res) {
callback = true;
assert.ok(err instanceof Error);
assert.equal(err.code, 4);
});
process.on('exit', function () {
assert.ok(callback);
});

@@ -6,3 +6,7 @@ var parser = require('../');

var callback = false;
var callbackXPath = false;
parser(fs.readFileSync('data/ec2-describeimages.xml').toString(), function (err, res) {
callback = true;
assert.ifError(err);

@@ -14,5 +18,11 @@ assert.equal(res.imagesSet.item[0].imageId, 'ami-be3adfd7');

parser(fs.readFileSync('data/ec2-describeimages.xml').toString(), '//xmlns:blockDeviceMapping', function (err, res) {
assert.ifError(err);
assert.strictEqual(res.length, 2);
assert.strictEqual(res[0].item.deviceName, '/dev/sda');
callbackXPath = true;
assert.ifError(err);
assert.strictEqual(res.length, 2);
assert.strictEqual(res[0].item.deviceName, '/dev/sda');
});
process.on('exit', function () {
assert.ok(callback);
assert.ok(callbackXPath);
});

@@ -6,3 +6,6 @@ var parser = require('../');

var callback = false;
parser(fs.readFileSync('data/ec2-describevolumes-large.xml').toString(), function (err, res) {
callback = true;
assert.ifError(err);

@@ -14,1 +17,5 @@ for (var i in res.volumeSet.item) {

});
process.on('exit', function () {
assert.ok(callback);
});

@@ -6,3 +6,6 @@ var parser = require('../');

var callback = false;
parser(fs.readFileSync('data/namespace.xml').toString(), function (err, res) {
callback = true;
assert.ifError(err);

@@ -18,1 +21,5 @@ assert.equal(res['@'].xmlns.atom, 'http://www.w3.org/2005/Atom');

});
process.on('exit', function () {
assert.ok(callback);
});

@@ -6,3 +6,7 @@ var parser = require('../');

var callback = false;
var callbackXPath = false;
parser(fs.readFileSync('data/wordpress-rss2.xml').toString(), function (err, res) {
callback = true;
assert.ifError(err);

@@ -18,5 +22,11 @@ assert.equal(res['@'].version, '2.0');

parser(fs.readFileSync('data/wordpress-rss2.xml').toString(), '//dc:creator', function (err, res) {
assert.ifError(err);
assert.strictEqual(res.length, 1);
assert.strictEqual(res[0]['#'], 'admin');
callbackXPath = true;
assert.ifError(err);
assert.strictEqual(res.length, 1);
assert.strictEqual(res[0]['#'], 'admin');
});
process.on('exit', function () {
assert.ok(callback);
assert.ok(callbackXPath);
});
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