fast-xml-parser
Advanced tools
Comparing version 2.6.0 to 2.7.0
@@ -26,3 +26,4 @@ var getAllMatches = require("./util").getAllMatches; | ||
textNodeConversion : true, | ||
textAttrConversion : false | ||
textAttrConversion : false, | ||
arrayMode : false | ||
}; | ||
@@ -32,3 +33,3 @@ | ||
if(!options) options = {}; | ||
var props = ["attrPrefix","ignoreNonTextNodeAttr","ignoreTextNodeAttr","ignoreNameSpace","ignoreRootElement","textNodeName","textNodeConversion","textAttrConversion"]; | ||
var props = ["attrPrefix","ignoreNonTextNodeAttr","ignoreTextNodeAttr","ignoreNameSpace","ignoreRootElement","textNodeName","textNodeConversion","textAttrConversion","arrayMode"]; | ||
for (var i = 0; i < props.length; i++) { | ||
@@ -95,3 +96,3 @@ if(options[props[i]] === undefined){ | ||
var xml2json = function (xmlData,options){ | ||
return convertToJson(getTraversalObj(xmlData,options)); | ||
return convertToJson(getTraversalObj(xmlData,options), buildOptions(options).arrayMode); | ||
}; | ||
@@ -156,3 +157,3 @@ | ||
var convertToJson = function (node){ | ||
var convertToJson = function (node, arrayMode){ | ||
var jObj = {}; | ||
@@ -164,3 +165,3 @@ if(node.val || node.val === "") { | ||
var prop = node.child[index].tagname; | ||
var obj = convertToJson(node.child[index]); | ||
var obj = convertToJson(node.child[index], arrayMode); | ||
if(jObj[prop] !== undefined){ | ||
@@ -174,3 +175,3 @@ if(!Array.isArray(jObj[prop])){ | ||
}else{ | ||
jObj[prop] = obj; | ||
jObj[prop] = arrayMode ? [obj] : obj; | ||
} | ||
@@ -177,0 +178,0 @@ } |
@@ -27,3 +27,4 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.parser = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
textNodeConversion : true, | ||
textAttrConversion : false | ||
textAttrConversion : false, | ||
arrayMode : false | ||
}; | ||
@@ -33,3 +34,3 @@ | ||
if(!options) options = {}; | ||
var props = ["attrPrefix","ignoreNonTextNodeAttr","ignoreTextNodeAttr","ignoreNameSpace","ignoreRootElement","textNodeName","textNodeConversion","textAttrConversion"]; | ||
var props = ["attrPrefix","ignoreNonTextNodeAttr","ignoreTextNodeAttr","ignoreNameSpace","ignoreRootElement","textNodeName","textNodeConversion","textAttrConversion","arrayMode"]; | ||
for (var i = 0; i < props.length; i++) { | ||
@@ -96,3 +97,3 @@ if(options[props[i]] === undefined){ | ||
var xml2json = function (xmlData,options){ | ||
return convertToJson(getTraversalObj(xmlData,options)); | ||
return convertToJson(getTraversalObj(xmlData,options), buildOptions(options).arrayMode); | ||
}; | ||
@@ -157,3 +158,3 @@ | ||
var convertToJson = function (node){ | ||
var convertToJson = function (node, arrayMode){ | ||
var jObj = {}; | ||
@@ -165,3 +166,3 @@ if(node.val || node.val === "") { | ||
var prop = node.child[index].tagname; | ||
var obj = convertToJson(node.child[index]); | ||
var obj = convertToJson(node.child[index], arrayMode); | ||
if(jObj[prop] !== undefined){ | ||
@@ -175,3 +176,3 @@ if(!Array.isArray(jObj[prop])){ | ||
}else{ | ||
jObj[prop] = obj; | ||
jObj[prop] = arrayMode ? [obj] : obj; | ||
} | ||
@@ -178,0 +179,0 @@ } |
{ | ||
"name": "fast-xml-parser", | ||
"version": "2.6.0", | ||
"version": "2.7.0", | ||
"description": "Validate XML or Parse XML to JS/JSON very fast without C/C++ based libraries", | ||
@@ -35,5 +35,13 @@ "main": "./bin/parser.js", | ||
"checker", | ||
"assert" | ||
"assert", | ||
"arrayMode" | ||
], | ||
"author": "Amit Gupta (https://github.com/amitguptagwl)", | ||
"contributors" : [ | ||
{ | ||
"name" : "Alfonso Muñoz-Pomer Fuentes", | ||
"email" : "amunoz@ebi.ac.uk", | ||
"url" : "https://github.com/alfonsomunozpomer" | ||
} | ||
], | ||
"license": "MIT", | ||
@@ -40,0 +48,0 @@ "devDependencies": { |
@@ -37,3 +37,4 @@ # [fast-xml-parser](https://www.npmjs.com/package/fast-xml-parser) | ||
textNodeConversion : true, | ||
textAttrConversion : false | ||
textAttrConversion : false, | ||
arrayMode : false | ||
}; | ||
@@ -40,0 +41,0 @@ if(fastXmlParser.validate(xmlData)=== true){//optional |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
186051
571
104