mirror of
https://github.com/iib0011/omni-tools.git
synced 2025-09-26 09:29:30 +02:00
fix: remove xml viewer
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { tool as xmlXmlValidator } from './xml-validator/meta';
|
||||
import { tool as xmlXmlBeautifier } from './xml-beautifier/meta';
|
||||
import { tool as xmlXmlViewer } from './xml-viewer/meta';
|
||||
export const xmlTools = [xmlXmlViewer, xmlXmlBeautifier, xmlXmlValidator];
|
||||
|
||||
export const xmlTools = [xmlXmlBeautifier, xmlXmlValidator];
|
||||
|
@@ -1,54 +0,0 @@
|
||||
import { Box } from '@mui/material';
|
||||
import React, { useState } from 'react';
|
||||
import ToolContent from '@components/ToolContent';
|
||||
import { ToolComponentProps } from '@tools/defineTool';
|
||||
import ToolTextInput from '@components/input/ToolTextInput';
|
||||
import ToolTextResult from '@components/result/ToolTextResult';
|
||||
import { CardExampleType } from '@components/examples/ToolExamples';
|
||||
import { prettyPrintXml } from './service';
|
||||
import { InitialValuesType } from './types';
|
||||
|
||||
const initialValues: InitialValuesType = {};
|
||||
|
||||
const exampleCards: CardExampleType<InitialValuesType>[] = [
|
||||
{
|
||||
title: 'Pretty Print XML',
|
||||
description: 'View and pretty-print a compact XML string.',
|
||||
sampleText: '<root><item>1</item><item>2</item></root>',
|
||||
sampleResult: `<root>\n <item>1</item>\n <item>2</item>\n</root>`,
|
||||
sampleOptions: {}
|
||||
}
|
||||
];
|
||||
|
||||
export default function XmlViewer({
|
||||
title,
|
||||
longDescription
|
||||
}: ToolComponentProps) {
|
||||
const [input, setInput] = useState<string>('');
|
||||
const [result, setResult] = useState<string>('');
|
||||
|
||||
const compute = (_values: InitialValuesType, input: string) => {
|
||||
setResult(prettyPrintXml(input, {}));
|
||||
};
|
||||
|
||||
return (
|
||||
<ToolContent
|
||||
title={title}
|
||||
input={input}
|
||||
inputComponent={
|
||||
<ToolTextInput
|
||||
value={input}
|
||||
onChange={setInput}
|
||||
placeholder="Paste or import XML here..."
|
||||
/>
|
||||
}
|
||||
resultComponent={<ToolTextResult value={result} extension="xml" />}
|
||||
initialValues={initialValues}
|
||||
exampleCards={exampleCards}
|
||||
getGroups={null}
|
||||
setInput={setInput}
|
||||
compute={compute}
|
||||
toolInfo={{ title: `What is a ${title}?`, description: longDescription }}
|
||||
/>
|
||||
);
|
||||
}
|
@@ -1,13 +0,0 @@
|
||||
import { defineTool } from '@tools/defineTool';
|
||||
import { lazy } from 'react';
|
||||
|
||||
export const tool = defineTool('xml', {
|
||||
name: 'XML Viewer',
|
||||
path: 'xml-viewer',
|
||||
icon: 'mdi:eye-outline',
|
||||
description:
|
||||
'View and pretty-print XML files or strings for easier reading and debugging.',
|
||||
shortDescription: 'Pretty-print and view XML.',
|
||||
keywords: ['xml', 'viewer', 'pretty print', 'format', 'inspect'],
|
||||
component: lazy(() => import('./index'))
|
||||
});
|
@@ -1,23 +0,0 @@
|
||||
import { InitialValuesType } from './types';
|
||||
import { XMLParser, XMLBuilder, XMLValidator } from 'fast-xml-parser';
|
||||
|
||||
export function prettyPrintXml(
|
||||
input: string,
|
||||
_options: InitialValuesType
|
||||
): string {
|
||||
const valid = XMLValidator.validate(input);
|
||||
if (valid !== true) {
|
||||
if (typeof valid === 'object' && valid.err) {
|
||||
return `Invalid XML: ${valid.err.msg} (line ${valid.err.line}, col ${valid.err.col})`;
|
||||
}
|
||||
return 'Invalid XML';
|
||||
}
|
||||
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}`;
|
||||
}
|
||||
}
|
@@ -1,3 +0,0 @@
|
||||
export type InitialValuesType = {
|
||||
// splitSeparator: string;
|
||||
};
|
@@ -1,18 +0,0 @@
|
||||
import { expect, describe, it } from 'vitest';
|
||||
import { prettyPrintXml } from './service';
|
||||
|
||||
describe('xml-viewer', () => {
|
||||
it('pretty prints valid XML', () => {
|
||||
const input = '<root><a>1</a><b>2</b></root>';
|
||||
const result = prettyPrintXml(input, {});
|
||||
expect(result).toContain('<root>');
|
||||
expect(result).toContain(' <a>1</a>');
|
||||
expect(result).toContain(' <b>2</b>');
|
||||
});
|
||||
|
||||
it('returns error for invalid XML', () => {
|
||||
const input = '<root><a>1</b></root>';
|
||||
const result = prettyPrintXml(input, {});
|
||||
expect(result).toMatch(/Invalid XML/i);
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user