mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-01-15 13:43:39 +01:00
29 lines
705 B
TypeScript
29 lines
705 B
TypeScript
import { useQuery } from '@tanstack/react-query';
|
|
import { tryFormatJson, tryFormatXml } from '../lib/formatters';
|
|
import type { EditorProps } from '../components/core/Editor/Editor';
|
|
|
|
export function useFormatText({
|
|
text,
|
|
language,
|
|
pretty,
|
|
}: {
|
|
text: string;
|
|
language: EditorProps['language'];
|
|
pretty: boolean;
|
|
}) {
|
|
return useQuery({
|
|
queryKey: [text, language, pretty],
|
|
queryFn: async () => {
|
|
if (text === '' || !pretty) {
|
|
return text;
|
|
} else if (language === 'json') {
|
|
return tryFormatJson(text);
|
|
} else if (language === 'xml' || language === 'html') {
|
|
return tryFormatXml(text);
|
|
} else {
|
|
return text;
|
|
}
|
|
},
|
|
});
|
|
}
|