mirror of
https://github.com/iib0011/omni-tools.git
synced 2026-11-30 09:00:33 +03:00
chore: imports updated in json-to-xml
This commit is contained in:
1 parent
c012ec038c
commit
ec5ec65149
1 file changed
+5
-20
@@ -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, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, ''');
|
||||
};
|
||||
|
||||
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}`;
|
||||
};
|
||||
Reference in new issue
Block a user