chore: imports updated in json-to-xml

This commit is contained in:
Chesterkxng committed 2026-07-26 19:30:50 +02:00
1 parent c012ec038c
commit ec5ec65149
1 file changed
+5 -20
+5 -20
View File
@@ -1,4 +1,6 @@
import { InitialValuesType } from './types';
import { escapeMarkup } from '@utils/string';
import { normalizeXmlTagName } from '@utils/xml';
type JsonObject = Record<string, any>;
@@ -52,7 +54,7 @@ const convertArrayItemToXml = (
)}${indentation}</item>${newline}`;
}
return `${indentation}<item>${escapeXml(String(item))}</item>${newline}`;
return `${indentation}<item>${escapeMarkup(String(item))}</item>${newline}`;
};
const convertObjectToXml = (
@@ -85,7 +87,7 @@ const convertObjectToXml = (
chunks.push(convertObjectToXml(item, options, depth + 1));
chunks.push(indentation);
} else {
chunks.push(escapeXml(String(item)));
chunks.push(escapeMarkup(String(item)));
}
chunks.push(`</${tagName}>${newline}`);
@@ -105,7 +107,7 @@ const convertObjectToXml = (
}
chunks.push(
`${indentation}<${tagName}>${escapeXml(
`${indentation}<${tagName}>${escapeMarkup(
String(value)
)}</${tagName}>${newline}`
);
@@ -124,20 +126,3 @@ const getIndentation = (options: InitialValuesType, depth: number): string => {
return '';
}
};
const escapeXml = (value: string): string => {
return value
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&apos;');
};
const normalizeXmlTagName = (key: string): string => {
const tagName = key !== '' && !isNaN(Number(key)) ? `row-${key}` : key;
const sanitized = tagName.replace(/[^a-zA-Z0-9_.-]/g, '_');
return /^[a-zA-Z_]/.test(sanitized) ? sanitized : `_${sanitized}`;
};