mirror of
https://github.com/iib0011/omni-tools.git
synced 2025-12-17 09:46:02 +00:00
17 lines
440 B
TypeScript
17 lines
440 B
TypeScript
import { InitialValuesType } from './types';
|
|
import { XMLParser, XMLBuilder } from 'fast-xml-parser';
|
|
|
|
export function beautifyXml(
|
|
input: string,
|
|
_options: InitialValuesType
|
|
): string {
|
|
try {
|
|
const parser = new XMLParser();
|
|
const obj = parser.parse(input);
|
|
const builder = new XMLBuilder({ format: true, indentBy: ' ' });
|
|
return builder.build(obj);
|
|
} catch (e: any) {
|
|
return `Invalid XML: ${e.message}`;
|
|
}
|
|
}
|