Comparing version 1.6.8 to 1.6.9
@@ -1,1 +0,1 @@ | ||
!function(t,e){if("function"==typeof define&&define.amd)define(["exports"],e);else if("undefined"!=typeof exports)e(exports);else{var n={exports:{}};e(n.exports),t.jstoxml=n.exports}}("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:this,function(t){"use strict";function e(t){return function(t){if(Array.isArray(t))return n(t)}(t)||function(t){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(t))return Array.from(t)}(t)||function(t,e){if(!t)return;if("string"==typeof t)return n(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);"Object"===r&&t.constructor&&(r=t.constructor.name);if("Map"===r||"Set"===r)return Array.from(t);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return n(t,e)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function n(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function r(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,r)}return n}function o(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?r(Object(n),!0).forEach(function(e){c(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):r(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function c(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function a(t){"@babel/helpers - typeof";return(a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}Object.defineProperty(t,"__esModule",{value:!0}),t.default=t.toXML=void 0;var i=["_selfCloseTag","_attrs"],u=new RegExp(i.join("|"),"g"),f=function(t){return(Array.isArray(t)?"array":"object"===a(t)&&null!==t&&t._name&&"special-object")||t instanceof Date&&"date"||null===t&&"null"||a(t)},l=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=new RegExp("(".concat(Object.keys(e).join("|"),")"),"g");return String(t).replace(n,function(t,n){return e[n]||""})},s=function(){var t=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=arguments.length>1?arguments[1]:void 0,n=[];n=Array.isArray(t)?t.map(function(t){var n=Object.keys(t)[0],r=t[n],o=e?l(r,e):r,c=!0===o?"":'="'.concat(o,'"');return"".concat(n).concat(c)}):Object.keys(t).map(function(n){var r=e?l(t[n],e):t[n],o=!0===t[n]?"":'="'.concat(r,'"');return"".concat(n).concat(o)});return n}(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},arguments.length>1?arguments[1]:void 0);if(0===t.length)return"";var e=t.join(" ");return" ".concat(e)},b=["string","number","boolean"],p=function(t){return b.includes(f(t))},d=[].concat(b,["date","special-object"]),y=function t(){var n,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},c=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},b=c.depth,y=void 0===b?0:b,v=c.indent,m=c._isFirstItem,g=c.attributesFilter,h=c.header,j=c.filter,O=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return t.repeat(e)}(v,y),_=f(r),S=(n=r,d.includes(f(n))),k=0===y&&(S||!S&&m),w="";switch(_){case"special-object":var A=r._name,x=r._content;if(null===x){w=A;break}if(Array.isArray(x)&&x.every(p))return x.map(function(e){return t({_name:A,_content:e},o(o({},c),{},{depth:y}))}).join("");if(A.match(u))break;var P=t(x,o(o({},c),{},{depth:y+1})),I=f(P),T=!P.match("<"),E="".concat(v&&!k?"\n":"").concat(O),D="undefined"===I||""===P,F="boolean"===a(r._selfCloseTag)?D&&r._selfCloseTag:D,L=F?"/":"",M=s(r._attrs,g),C="<".concat(A).concat(M).concat(L,">"),X=v&&!T?"\n".concat(O):"",R=F?"":"".concat(P).concat(X,"</").concat(A,">");w="".concat(E).concat(C).concat(R);break;case"object":var U=Object.keys(r);w=U.map(function(n,a){var u=o(o({},c),{},{_isFirstItem:0===a,_isLastItem:a+1===U.length}),l={_name:n};if("object"===f(r[n])&&(i.forEach(function(t){var e=r[n][t];void 0!==e&&(l[t]=e,delete r[n][t])}),void 0!==r[n]._content&&Object.keys(r[n]).length>1)){var s=Object.assign({},r[n]);delete s._content,l._content=[].concat(e(function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return Object.keys(t).map(function(e){return{_name:e,_content:t[e]}})}(s)),[r[n]._content])}return void 0===l._content&&(l._content=r[n]),t(l,u,n)},c).join("");break;case"function":var $=r(c);w=t($,c);break;case"array":w=r.map(function(e,n){var a=o(o({},c),{},{_isFirstItem:0===n,_isLastItem:n+1===r.length});return t(e,a)}).join("");break;default:w=l(r,j)}var q=function(t){var e=t.header,n=t.indent,r=t.isOutputStart;if(!e||!r)return"";var o="boolean"===a(e);return"".concat(o?'<?xml version="1.0" encoding="UTF-8"?>':e).concat(n?"\n":"")}({header:h,indent:v,depth:y,isOutputStart:k});return"".concat(q).concat(w)};t.toXML=y;var v={toXML:y};t.default=v}); | ||
!function(t,e){if("function"==typeof define&&define.amd)define(["exports"],e);else if("undefined"!=typeof exports)e(exports);else{var n={exports:{}};e(n.exports),t.jstoxml=n.exports}}("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:this,function(t){"use strict";function e(t){return function(t){if(Array.isArray(t))return n(t)}(t)||function(t){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(t))return Array.from(t)}(t)||function(t,e){if(!t)return;if("string"==typeof t)return n(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);"Object"===r&&t.constructor&&(r=t.constructor.name);if("Map"===r||"Set"===r)return Array.from(t);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return n(t,e)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function n(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function r(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,r)}return n}function o(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?r(Object(n),!0).forEach(function(e){c(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):r(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function c(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function a(t){"@babel/helpers - typeof";return(a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}Object.defineProperty(t,"__esModule",{value:!0}),t.default=t.toXML=void 0;var i=["_selfCloseTag","_attrs"],u=new RegExp(i.join("|"),"g"),f=function(t){return(Array.isArray(t)?"array":"object"===a(t)&&null!==t&&t._name&&"special-object")||t instanceof Date&&"date"||null===t&&"null"||a(t)},l=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=new RegExp("(".concat(Object.keys(e).join("|"),")"),"g");return String(t).replace(n,function(t,n){return e[n]||""})},s=function(){var t=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=arguments.length>1?arguments[1]:void 0,n=[];n=Array.isArray(t)?t.map(function(t){var n=Object.keys(t)[0],r=t[n],o=e?l(r,e):r,c=!0===o?"":'="'.concat(o,'"');return"".concat(n).concat(c)}):Object.keys(t).map(function(n){var r=e?l(t[n],e):t[n],o=!0===t[n]?"":'="'.concat(r,'"');return"".concat(n).concat(o)});return n}(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},arguments.length>1?arguments[1]:void 0);if(0===t.length)return"";var e=t.join(" ");return" ".concat(e)},b=["string","number","boolean"],p=function(t){return b.includes(f(t))},d=[].concat(b,["date","special-object"]),y=function t(){var n,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},c=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},b=c.depth,y=void 0===b?0:b,v=c.indent,m=c._isFirstItem,g=(c._isLastItem,c.attributesFilter),h=c.header,j=c.filter,O=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return t.repeat(e)}(v,y),_=f(r),S=(n=r,d.includes(f(n))),k=0===y&&(S||!S&&m),w="";switch(_){case"special-object":var A=r._name,x=r._content;if(null===x){w=A;break}if(Array.isArray(x)&&x.every(p))return x.map(function(e){return t({_name:A,_content:e},o(o({},c),{},{depth:y}))}).join("");if(A.match(u))break;var P=t(x,o(o({},c),{},{depth:y+1})),I=f(P),T=!P.match("<"),E="".concat(v&&!k?"\n":"").concat(O),L="undefined"===I||""===P,D="boolean"===a(r._selfCloseTag)?L&&r._selfCloseTag:L,F=D?"/":"",M=s(r._attrs,g),C="<".concat(A).concat(M).concat(F,">"),X=v&&!T?"\n".concat(O):"",R=D?"":"".concat(P).concat(X,"</").concat(A,">");w="".concat(E).concat(C).concat(R);break;case"object":var U=Object.keys(r),$=U.map(function(n,a){var u=o(o({},c),{},{_isFirstItem:0===a,_isLastItem:a+1===U.length}),l={_name:n};if("object"===f(r[n])&&(i.forEach(function(t){var e=r[n][t];void 0!==e&&(l[t]=e,delete r[n][t])}),void 0!==r[n]._content&&Object.keys(r[n]).length>1)){var s=Object.assign({},r[n]);delete s._content,l._content=[].concat(e(function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return Object.keys(t).map(function(e){return{_name:e,_content:t[e]}})}(s)),[r[n]._content])}return void 0===l._content&&(l._content=r[n]),t(l,u,n)},c),q=v&&0===y?"\n":"";w=$.join(q);break;case"function":var z=r(c);w=t(z,c);break;case"array":var B=r.map(function(e,n){var a=o(o({},c),{},{_isFirstItem:0===n,_isLastItem:n+1===r.length});return t(e,a)}),G=v&&0===y?"\n":"";w=B.join(G);break;default:w=l(r,j)}var H=function(t){var e=t.header,n=t.indent,r=t.isOutputStart;if(!e||!r)return"";var o="boolean"===a(e);return"".concat(o?'<?xml version="1.0" encoding="UTF-8"?>':e).concat(n?"\n":"")}({header:h,indent:v,depth:y,isOutputStart:k});return"".concat(H).concat(w)};t.toXML=y;var v={toXML:y};t.default=v}); |
@@ -236,2 +236,3 @@ (function (global, factory) { | ||
_isFirstItem = config._isFirstItem, | ||
_isLastItem = config._isLastItem, | ||
attributesFilter = config.attributesFilter, | ||
@@ -262,3 +263,5 @@ header = config.header, | ||
if (Array.isArray(_content) && _content.every(isPrimitive)) { | ||
var isArrayOfPrimitives = Array.isArray(_content) && _content.every(isPrimitive); | ||
if (isArrayOfPrimitives) { | ||
return _content.map(function (a) { | ||
@@ -342,3 +345,4 @@ return toXML({ | ||
}, config); | ||
outputStr = outputArr.join(""); | ||
var separator = indent && depth === 0 ? "\n" : ""; | ||
outputStr = outputArr.join(separator); | ||
break; | ||
@@ -367,3 +371,5 @@ } | ||
outputStr = _outputArr.join(""); | ||
var _separator = indent && depth === 0 ? "\n" : ""; | ||
outputStr = _outputArr.join(_separator); | ||
break; | ||
@@ -370,0 +376,0 @@ } |
@@ -176,3 +176,3 @@ const ARRAY = "array"; | ||
_isFirstItem, | ||
/* _isLastItem, */ | ||
_isLastItem, | ||
attributesFilter, | ||
@@ -208,3 +208,4 @@ header, | ||
// Handles arrays of primitive values. (#33) | ||
if (Array.isArray(_content) && _content.every(isPrimitive)) { | ||
const isArrayOfPrimitives = Array.isArray(_content) && _content.every(isPrimitive); | ||
if (isArrayOfPrimitives) { | ||
return _content | ||
@@ -253,3 +254,2 @@ .map((a) => { | ||
: ""; | ||
outputStr = `${preTag}${tag}${postTag}`; | ||
@@ -310,3 +310,5 @@ break; | ||
outputStr = outputArr.join(""); | ||
const separator = (indent && depth === 0) ? "\n" : ""; | ||
outputStr = outputArr.join(separator); | ||
break; | ||
@@ -326,3 +328,2 @@ } | ||
// Iterates and converts each value in an array. | ||
const outputArr = obj.map((singleVal, index) => { | ||
@@ -337,4 +338,6 @@ const newConfig = { | ||
outputStr = outputArr.join(""); | ||
const separator = (indent && depth === 0) ? "\n" : ""; | ||
outputStr = outputArr.join(separator); | ||
break; | ||
@@ -341,0 +344,0 @@ } |
{ | ||
"name": "jstoxml", | ||
"version": "1.6.8", | ||
"version": "1.6.9", | ||
"description": "Converts JavaScript/JSON to XML (for RSS, Podcasts, AMP, etc.)", | ||
@@ -33,9 +33,9 @@ "homepage": "http://github.com/davidcalhoun/jstoxml", | ||
"devDependencies": { | ||
"@babel/cli": "^7.10.4", | ||
"@babel/core": "^7.10.4", | ||
"@babel/cli": "^7.10.5", | ||
"@babel/core": "^7.11.1", | ||
"@babel/plugin-transform-modules-umd": "^7.10.4", | ||
"@babel/preset-env": "^7.10.4", | ||
"@babel/preset-env": "^7.11.0", | ||
"babel-eslint": "^10.1.0", | ||
"eslint": "^7.4.0", | ||
"mocha": "^8.0.1", | ||
"eslint": "^7.6.0", | ||
"mocha": "^8.1.1", | ||
"prettier": "^2.0.5", | ||
@@ -42,0 +42,0 @@ "uglify-es": "^3.3.9" |
62
test.js
@@ -925,2 +925,5 @@ const { toXML } = require("./dist/jstoxml"); | ||
}); | ||
describe("issues", () => { | ||
it("issue #33: array of primitives", () => { | ||
@@ -1074,3 +1077,62 @@ const val = { | ||
}); | ||
it("issue #40 forced separator, no indent", () => { | ||
const val = [ | ||
{a: "A Value"}, | ||
'\n', | ||
{b: "B Value"} | ||
]; | ||
const result = toXML(val); | ||
const expectedResult = `<a>A Value</a> | ||
<b>B Value</b>`; | ||
assert.equal(result, expectedResult); | ||
}); | ||
it("issue #40 array with indent", () => { | ||
const val = [ | ||
{a: "A Value"}, | ||
{b: "B Value"} | ||
]; | ||
const result = toXML(val, {indent: ' '}); | ||
const expectedResult = `<a>A Value</a> | ||
<b>B Value</b>`; | ||
assert.equal(result, expectedResult); | ||
}); | ||
it("issue #40 array without indent", () => { | ||
const val = [ | ||
{a: "A Value"}, | ||
{b: "B Value"} | ||
]; | ||
const result = toXML(val); | ||
const expectedResult = `<a>A Value</a><b>B Value</b>`; | ||
assert.equal(result, expectedResult); | ||
}); | ||
it("issue #40 object with indent", () => { | ||
const val = { | ||
a: "A Value", | ||
b: "B Value" | ||
}; | ||
const result = toXML(val, {indent: ' '}); | ||
const expectedResult = `<a>A Value</a> | ||
<b>B Value</b>`; | ||
assert.equal(result, expectedResult); | ||
}); | ||
it("issue #40 object without indent", () => { | ||
const val = { | ||
a: "A Value", | ||
b: "B Value" | ||
}; | ||
const result = toXML(val); | ||
const expectedResult = `<a>A Value</a><b>B Value</b>`; | ||
assert.equal(result, expectedResult); | ||
}); | ||
}); | ||
}); | ||
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
77426
1696