Comparing version 0.9.0 to 0.9.1
@@ -45,9 +45,10 @@ /*jslint node:true */ | ||
var i, j, options = {}; | ||
function findIndex (argument, index) { | ||
if (argument.alias === process.argv[i].slice(1) || argument.arg === process.argv[i].slice(2)) { | ||
j = index; | ||
} | ||
} | ||
for (i = 2; i < process.argv.length; i += 1) { | ||
j = -1; | ||
optionalArgs.forEach(function (argument, index) { | ||
if (argument.alias === process.argv[i].slice(1) || argument.arg === process.argv[i].slice(2)) { | ||
j = index; | ||
} | ||
}); | ||
optionalArgs.forEach(findIndex); | ||
if (j >= 0) { | ||
@@ -54,0 +55,0 @@ switch (optionalArgs[j].type) { |
@@ -59,2 +59,33 @@ /*jslint node:true */ | ||
function writeElement (element, options, depth) { | ||
var xml = ''; | ||
xml += '<' + element.name; | ||
if (element[options.attributesKey]) { | ||
xml += writeAttributes(element[options.attributesKey]); | ||
} | ||
if (options.fullTagEmptyElement || (element[options.elementsKey] && element[options.elementsKey].length) || (element[options.attributesKey] && element[options.attributesKey]['xml:space'] === 'preserve')) { | ||
xml += '>'; | ||
if (element[options.elementsKey] && element[options.elementsKey].length) { | ||
xml += writeElements(element[options.elementsKey], options, depth + 1); | ||
} | ||
xml += (options.spaces && element[options.elementsKey] && element[options.elementsKey].length && (element[options.elementsKey].length > 1 || element[options.elementsKey][0].type !== 'text') ? '\n' : '') + Array(depth + 1).join(options.spaces); | ||
xml += '</' + element.name + '>'; | ||
} else { | ||
xml += '/>'; | ||
} | ||
return xml; | ||
} | ||
function writeElements (elements, options, depth, firstLine) { | ||
var sep = writeIndentation(options, depth, firstLine); | ||
return elements.reduce(function (xml, element) { | ||
switch (element.type) { | ||
case 'element': return xml + sep + writeElement(element, options, depth); | ||
case 'comment': return xml + sep + writeComment(element, options); | ||
case 'cdata': return xml + sep + writeCdata(element, options); | ||
case 'text': return xml + writeText(element, options); | ||
} | ||
}, ''); | ||
} | ||
function writeElementCompact (element, name, options, depth, firstLine) { | ||
@@ -94,33 +125,2 @@ var xml = '', key; | ||
function writeElements (elements, options, depth, firstLine) { | ||
var sep = writeIndentation(options, depth, firstLine); | ||
return elements.reduce(function (xml, element) { | ||
switch (element.type) { | ||
case 'element': return xml + sep + writeElement(element, options, depth); | ||
case 'comment': return xml + sep + writeComment(element, options); | ||
case 'cdata': return xml + sep + writeCdata(element, options); | ||
case 'text': return xml + writeText(element, options); | ||
} | ||
}, ''); | ||
} | ||
function writeElement (element, options, depth) { | ||
var xml = ''; | ||
xml += '<' + element.name; | ||
if (element[options.attributesKey]) { | ||
xml += writeAttributes(element[options.attributesKey]); | ||
} | ||
if (options.fullTagEmptyElement || (element[options.elementsKey] && element[options.elementsKey].length) || (element[options.attributesKey] && element[options.attributesKey]['xml:space'] === 'preserve')) { | ||
xml += '>'; | ||
if (element[options.elementsKey] && element[options.elementsKey].length) { | ||
xml += writeElements(element[options.elementsKey], options, depth + 1); | ||
} | ||
xml += (options.spaces && element[options.elementsKey] && element[options.elementsKey].length && (element[options.elementsKey].length > 1 || element[options.elementsKey][0].type !== 'text') ? '\n' : '') + Array(depth + 1).join(options.spaces); | ||
xml += '</' + element.name + '>'; | ||
} else { | ||
xml += '/>'; | ||
} | ||
return xml; | ||
} | ||
module.exports = function (js, options) { | ||
@@ -127,0 +127,0 @@ 'use strict'; |
{ | ||
"name": "xml-js", | ||
"version": "0.9.0", | ||
"version": "0.9.1", | ||
"description": "A convertor between XML text and Javascript object / JSON text.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
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
1371375
22994