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

xml2json

Package Overview
Dependencies
Maintainers
2
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xml2json - npm Package Compare versions

Comparing version 0.11.2 to 0.12.0

.npmignore

7

lib/json2xml.js

@@ -24,2 +24,4 @@ var sanitizer = require('./sanitize.js')

ToXml.prototype.parse = function(obj) {
if (!obj) return;
var self = this;

@@ -64,3 +66,3 @@ var keys = Object.keys(obj);

}
} else if (typeof(obj[key]) == 'object') {
} else if (typeof(obj[key]) == 'object' && !(self.options.ignoreNull && obj[key] === null)) {
self.openTag(key);

@@ -102,3 +104,4 @@ self.parse(obj[key]);

var defaultOpts = {
sanitize: false
sanitize: false,
ignoreNull: false
};

@@ -105,0 +108,0 @@

{
"name": "xml2json",
"version": "0.11.2",
"version": "0.12.0",
"description": "Converts xml to json and vice-versa, using node-expat.",

@@ -14,3 +14,3 @@ "repository": "git://github.com/buglabs/node-xml2json.git",

"joi": "^13.1.2",
"node-expat": "^2.3.15"
"node-expat": "^2.3.18"
},

@@ -22,4 +22,4 @@ "bin": {

"code": "^3.0.2",
"lab": "11.x.x"
"lab": "^18.0.0"
}
}

@@ -14,3 +14,3 @@ # Simple XML2JSON Parser

This module uses node-expat which will require extra steps if you want to get it installed on Windows. Please
refer to its [documentation](http://node-xmpp.org/doc/expat.html#installing-on-windows?). Also, please be aware of known issues installing node-expat on Windows: https://github.com/node-xmpp/node-expat/issues?utf8=✓&q=is%3Aissue+is%3Aopen+windows
refer to its [documentation](https://github.com/astro/node-expat/blob/master/README.md#windows).

@@ -89,7 +89,9 @@ ## Installation

var options = {
sanitize: false
sanitize: false,
ignoreNull: false
};
```
`sanitize: false` is the default option to behave like previous versions
* `sanitize: false` is the default option to behave like previous versions
* **ignoreNull:** Ignores all null values

@@ -96,0 +98,0 @@

@@ -22,3 +22,3 @@ var fs = require('fs');

it('converts with array-notation', function (done) {
it('converts with array-notation', function () {

@@ -31,6 +31,6 @@ var xml = internals.readFixture('array-notation.xml');

done();
return Promise.resolve();
});
it('coerces', function (done) {
it('coerces', function () {

@@ -43,6 +43,6 @@ var xml = internals.readFixture('coerce.xml');

done();
return Promise.resolve();
});
it('handles domain', function (done) {
it('handles domain', function () {

@@ -55,6 +55,6 @@ var xml = internals.readFixture('domain.xml');

done();
return Promise.resolve();
});
it('does large file', function (done) {
it('does large file', function () {

@@ -67,6 +67,6 @@ var xml = internals.readFixture('large.xml');

done();
return Promise.resolve();
});
it('handles reorder', function (done) {
it('handles reorder', function () {

@@ -79,6 +79,6 @@ var xml = internals.readFixture('reorder.xml');

done();
return Promise.resolve();
});
it('handles text with space', function (done) {
it('handles text with space', function () {

@@ -91,6 +91,6 @@ var xml = internals.readFixture('spacetext.xml');

done();
return Promise.resolve();
});
it('does xmlsanitize', function (done) {
it('does xmlsanitize', function () {

@@ -103,6 +103,6 @@ var xml = internals.readFixture('xmlsanitize.xml');

done();
return Promise.resolve();
});
it('does xmlsanitize of text', function (done) {
it('does xmlsanitize of text', function () {

@@ -115,6 +115,6 @@ var xml = internals.readFixture('xmlsanitize2.xml');

done();
return Promise.resolve();
});
it('does json unsanitize', function (done) {
it('does json unsanitize', function () {

@@ -127,6 +127,6 @@ var json = internals.readFixture('xmlsanitize.json');

done();
return Promise.resolve();
});
it('does json unsanitize of text', function (done) {
it('does json unsanitize of text', function () {

@@ -139,6 +139,6 @@ var json = internals.readFixture('xmlsanitize2.json');

done();
return Promise.resolve();
});
it('does doesnt double sanitize', function (done) {
it('does doesnt double sanitize', function () {

@@ -151,6 +151,6 @@ var json = internals.readFixture('xmlsanitize3.json');

done();
return Promise.resolve();
});
it('does doesnt double unsanitize', function (done) {
it('does doesnt double unsanitize', function () {

@@ -162,6 +162,6 @@ var xml = internals.readFixture('xmlsanitize3.xml');

expect(result).to.equal(json);
done();
return Promise.resolve();
});
it('converts with forceArrays', function(done) {
it('converts with forceArrays', function() {
var xml = internals.readFixture('forceArray.xml');

@@ -172,6 +172,6 @@ var result = parser.toJson(xml, {arrayNotation: ['drivers', 'vehicles']});

expect(result).to.equal(json);
done();
return Promise.resolve();
});
it('throws error on bad options', function (done) {
it('throws error on bad options', function () {

@@ -184,3 +184,3 @@ var throws = function() {

expect(throws).to.throw();
done();
return Promise.resolve();
});

@@ -193,3 +193,3 @@

it('works with coercion', function(done) {
it('works with coercion', function() {

@@ -204,6 +204,6 @@ // With coercion

expect(result.itemRecord.value[8].text['$t']).to.equal(42.42);
done();
return Promise.resolve();
});
it('works without coercion', function(done) {
it('works without coercion', function() {

@@ -217,6 +217,6 @@ var result = parser.toJson(data, {reversible: true, coerce: false, object: true});

expect(result.itemRecord.value[8].text['$t']).to.equal('42.42');
done();
return Promise.resolve();
});
it('works with coercion as an optional object', function(done) {
it('works with coercion as an optional object', function() {

@@ -230,3 +230,3 @@ var result = parser.toJson(data, {reversible: true, coerce: {text:String}, object: true});

expect(result.itemRecord.value[8].text['$t']).to.equal('42.42');
done();
return Promise.resolve();
});

@@ -237,3 +237,3 @@ })

it('A1: defaults without the option being defined', function(done) {
it('A1: defaults without the option being defined', function() {

@@ -243,9 +243,9 @@ var xml = internals.readFixture('alternate-text-node-A.xml');

var json = internals.readFixture('alternate-text-node-A.json');
expect(result).to.equal(json);
done();
return Promise.resolve();
});
it('A2: defaults with option as false', function(done) {
it('A2: defaults with option as false', function() {

@@ -255,11 +255,11 @@ var xml = internals.readFixture('alternate-text-node-A.xml');

var json = internals.readFixture('alternate-text-node-A.json');
expect(result).to.equal(json);
done();
return Promise.resolve();
});
it('B: uses alternate text node with option as true', function(done) {
it('B: uses alternate text node with option as true', function() {
var xml = internals.readFixture('alternate-text-node-A.xml');

@@ -271,17 +271,17 @@ var result = parser.toJson(xml, {alternateTextNode: true, reversible: true});

done();
return Promise.resolve();
});
it('C: overrides text node with option as "xx" string', function(done) {
it('C: overrides text node with option as "xx" string', function() {
var xml = internals.readFixture('alternate-text-node-A.xml');
var result = parser.toJson(xml, {alternateTextNode: "xx", reversible: true});
var json = internals.readFixture('alternate-text-node-C.json');
expect(result).to.equal(json);
done();
return Promise.resolve();
});
it('D: double check sanatize and trim', function (done) {
it('D: double check sanatize and trim', function () {

@@ -294,3 +294,3 @@ var xml = internals.readFixture('alternate-text-node-D.xml');

done();
return Promise.resolve();
});

@@ -304,3 +304,3 @@

it('converts domain to json', function (done) {
it('converts domain to json', function () {

@@ -313,6 +313,6 @@ var json = internals.readFixture('domain-reversible.json');

done();
return Promise.resolve();
});
it('works with array notation', function (done) {
it('works with array notation', function () {

@@ -326,4 +326,30 @@ var xml = internals.readFixture('array-notation.xml');

done();
return Promise.resolve();
});
describe('ignore null', function () {
it('ignore null properties {ignoreNull: true}', function () {
var json = JSON.parse( internals.readFixture('null-properties.json') );
var expectedXml = internals.readFixture('null-properties-ignored.xml');
var xml = parser.toXml(json, {ignoreNull: true});
expect(xml).to.equal(expectedXml);
return Promise.resolve();
});
it('don\'t ignore null properties (default)', function () {
var json = JSON.parse( internals.readFixture('null-properties.json') );
var expectedXml = internals.readFixture('null-properties-not-ignored.xml');
var xml = parser.toXml(json);
expect(xml).to.equal(expectedXml);
return Promise.resolve();
});
});
});

@@ -330,0 +356,0 @@

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