object-to-xml
Advanced tools
Comparing version 1.1.0 to 2.0.0
22
index.js
@@ -1,3 +0,4 @@ | ||
var sanitizer = require('sanitizer') | ||
, map = require('dank-map') | ||
var sanitizer = require('sanitizer'); | ||
var map = require('dank-map'); | ||
var each = require('dank-each'); | ||
; | ||
@@ -9,5 +10,9 @@ | ||
map(obj, function (key, value) { | ||
each(obj, function (key, value) { | ||
var attributes = ''; | ||
if (key === '@') { | ||
return; | ||
} | ||
if (value && (value.hasOwnProperty('@') || value.hasOwnProperty('#'))) { | ||
@@ -23,7 +28,14 @@ attributes = map(value['@'], function (key, value) { | ||
value = value['#']; | ||
if (value['#']) { | ||
value = value['#']; | ||
} | ||
else if (Object.keys(value).length === 1 && value.hasOwnProperty('@')) { | ||
//if the only property this object has is '@', then set value to null | ||
//so it will generate <key prop="" prop2="" /> | ||
value = null; | ||
} | ||
} | ||
if (Array.isArray(value)) { | ||
map(value, function (ix, value) { | ||
each(value, function (ix, value) { | ||
var tmp = {}; | ||
@@ -30,0 +42,0 @@ |
{ | ||
"name": "object-to-xml", | ||
"version": "1.1.0", | ||
"version": "2.0.0", | ||
"description": "Convert any object to XML", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "nodeunit test/test.js" | ||
"test": "tape test.js" | ||
}, | ||
@@ -24,2 +24,3 @@ "repository": { | ||
"dependencies": { | ||
"dank-each": "^1.0.0", | ||
"dank-map": "~0.1.0", | ||
@@ -29,4 +30,4 @@ "sanitizer": "0.1.3" | ||
"devDependencies": { | ||
"nodeunit": "^0.9.1" | ||
"tape": "^4.9.1" | ||
} | ||
} |
8942
196
3
6
+ Addeddank-each@^1.0.0
+ Addeddank-each@1.0.0(transitive)