Refactor: removed redundancy on array conversion

This commit is contained in:
Luís Jesus
2025-03-26 11:22:57 +00:00
parent 63884cd5ea
commit 52134e82a3

View File

@@ -47,14 +47,7 @@ const convertObjectToXml = (
if (Array.isArray(value)) { if (Array.isArray(value)) {
value.forEach((item) => { value.forEach((item) => {
xml += `${getIndentation(options, depth)}<${keyString}>`; xml += `${getIndentation(options, depth)}<${keyString}>`;
xml += xml += convertObjectToXml(item, options, depth + 1);
typeof item === 'object' && item !== null
? `${newline}${convertObjectToXml(
item,
options,
depth + 1
)}${getIndentation(options, depth)}`
: `${escapeXml(String(item))}`;
xml += `</${keyString}>${newline}`; xml += `</${keyString}>${newline}`;
}); });
} else if (value === null) { } else if (value === null) {
@@ -66,6 +59,8 @@ const convertObjectToXml = (
xml += `${getIndentation(options, depth)}<${keyString}>${newline}`; xml += `${getIndentation(options, depth)}<${keyString}>${newline}`;
xml += convertObjectToXml(value, options, depth + 1); xml += convertObjectToXml(value, options, depth + 1);
xml += `${getIndentation(options, depth)}</${keyString}>${newline}`; xml += `${getIndentation(options, depth)}</${keyString}>${newline}`;
// All other types are tre
} else { } else {
xml += `${getIndentation(options, depth)}<${keyString}>${escapeXml( xml += `${getIndentation(options, depth)}<${keyString}>${escapeXml(
String(value) String(value)