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.8.2 to 0.9.0

2

lib/xml2json.js

@@ -147,3 +147,3 @@ var expat = require('node-expat');

reversible: joi.boolean().default(false),
coerce: joi.alternatives([joi.boolean(), joi.object()]).default(true),
coerce: joi.alternatives([joi.boolean(), joi.object()]).default(false),
sanitize: joi.boolean().default(true),

@@ -150,0 +150,0 @@ trim: joi.boolean().default(true),

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

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

"scripts": {
"test": "make test"
"test": "lab -a code -v -t 93 test/test.js"
},

@@ -15,3 +15,3 @@ "dependencies": {

"joi": "^6.4.3",
"node-expat": "^2.3.7"
"node-expat": "^2.3.9"
},

@@ -18,0 +18,0 @@ "bin": {

# Simple XML2JSON Parser
[![Gitter](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/buglabs/node-xml2json?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Build Status](https://travis-ci.org/buglabs/node-xml2json.svg?branch=master)](https://travis-ci.org/buglabs/node-xml2json)

@@ -44,3 +45,3 @@ It does not parse the following elements:

reversible: false,
coerce: true,
coerce: false,
sanitize: true,

@@ -47,0 +48,0 @@ trim: true,

@@ -109,2 +109,46 @@ var fs = require('fs');

});
describe('coercion', function () {
var file = __dirname + '/fixtures/coerce.xml';
var data = fs.readFileSync(file);
it('works with coercion', function(done) {
// With coercion
var result = parser.toJson(data, {reversible: true, coerce: true, object: true});
expect(result.itemRecord.value[0].longValue['$t']).to.equal(12345);
expect(result.itemRecord.value[1].stringValue.number).to.equal(false);
expect(result.itemRecord.value[2].moneyValue.number).to.equal(true);
expect(result.itemRecord.value[2].moneyValue['$t']).to.equal(104.95);
expect(result.itemRecord.value[2].moneyValue.text).to.equal(123.45);
expect(result.itemRecord.value[8].text['$t']).to.equal(42.42);
done();
});
it('works without coercion', function(done) {
var result = parser.toJson(data, {reversible: true, coerce: false, object: true});
expect(result.itemRecord.value[0].longValue['$t']).to.equal('12345');
expect(result.itemRecord.value[1].stringValue.number).to.equal('false');
expect(result.itemRecord.value[2].moneyValue.number).to.equal('true');
expect(result.itemRecord.value[2].moneyValue['$t']).to.equal('104.95');
expect(result.itemRecord.value[2].moneyValue.text).to.equal('123.45');
expect(result.itemRecord.value[8].text['$t']).to.equal('42.42');
done();
});
it('works with coercion as an optional object', function(done) {
var result = parser.toJson(data, {reversible: true, coerce: {text:String}, object: true});
expect(result.itemRecord.value[0].longValue['$t']).to.equal(12345);
expect(result.itemRecord.value[1].stringValue.number).to.equal(false);
expect(result.itemRecord.value[2].moneyValue.number).to.equal(true);
expect(result.itemRecord.value[2].moneyValue['$t']).to.equal(104.95);
expect(result.itemRecord.value[2].moneyValue.text).to.equal('123.45');
expect(result.itemRecord.value[8].text['$t']).to.equal('42.42');
done();
});
})
});

@@ -126,2 +170,13 @@

it('works with array notation', function (done) {
var xml = fs.readFileSync('./test/fixtures/array-notation.xml');
var expectedJson = JSON.parse( fs.readFileSync('./test/fixtures/array-notation.json') );
var json = parser.toJson(xml, {object: true, arrayNotation: true});
expect(json).to.deep.equal(expectedJson);
done();
});
});

@@ -128,0 +183,0 @@

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