mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-05-10 08:05:00 -04:00
feat: Synchronous Update
This commit is contained in:
commit
e7ccf65fe5
95 changed files with 8870 additions and 5322 deletions
13
src/tools/xml-to-json/index.ts
Normal file
13
src/tools/xml-to-json/index.ts
Normal file
|
@ -0,0 +1,13 @@
|
|||
import { Braces } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
import { translate as t } from '@/plugins/i18n.plugin';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: t('tools.xml-to-json.title'),
|
||||
path: '/xml-to-json',
|
||||
description: t('tools.xml-to-json.description'),
|
||||
keywords: ['xml', 'json'],
|
||||
component: () => import('./xml-to-json.vue'),
|
||||
icon: Braces,
|
||||
createdAt: new Date('2024-08-09'),
|
||||
});
|
10
src/tools/xml-to-json/locales/en.yml
Normal file
10
src/tools/xml-to-json/locales/en.yml
Normal file
|
@ -0,0 +1,10 @@
|
|||
tools:
|
||||
xml-to-json:
|
||||
title: XML to JSON
|
||||
description: Convert XML to JSON.
|
||||
|
||||
inputLabel: Your XML content
|
||||
inputPlaceholder: Paste your XML content here...
|
||||
outputLabel: Converted JSON
|
||||
|
||||
invalidMessage: Provided XML is not valid.
|
10
src/tools/xml-to-json/locales/fr.yml
Normal file
10
src/tools/xml-to-json/locales/fr.yml
Normal file
|
@ -0,0 +1,10 @@
|
|||
tools:
|
||||
xml-to-json:
|
||||
title: XML vers JSON
|
||||
description: Convertir XML en JSON.
|
||||
|
||||
inputLabel: Votre contenu XML
|
||||
inputPlaceholder: Collez votre contenu XML ici...
|
||||
outputLabel: JSON converti
|
||||
|
||||
invalidMessage: Le XML fourni n'est pas valide.
|
10
src/tools/xml-to-json/locales/zh.yml
Normal file
10
src/tools/xml-to-json/locales/zh.yml
Normal file
|
@ -0,0 +1,10 @@
|
|||
tools:
|
||||
xml-to-json:
|
||||
title: XML 转 JSON
|
||||
description: 将 XML 转换为 JSON。
|
||||
|
||||
inputLabel: 您的 XML 内容
|
||||
inputPlaceholder: 在此粘贴您的 XML 内容...
|
||||
outputLabel: 转换后的 JSON
|
||||
|
||||
invalidMessage: 提供的 XML 不是有效的。
|
33
src/tools/xml-to-json/xml-to-json.vue
Normal file
33
src/tools/xml-to-json/xml-to-json.vue
Normal file
|
@ -0,0 +1,33 @@
|
|||
<script setup lang="ts">
|
||||
import convert from 'xml-js';
|
||||
import { isValidXML } from '../xml-formatter/xml-formatter.service';
|
||||
import { withDefaultOnError } from '@/utils/defaults';
|
||||
import type { UseValidationRule } from '@/composable/validation';
|
||||
|
||||
const { t } = useI18n();
|
||||
const defaultValue = '<a x="1.234" y="It\'s"/>';
|
||||
function transformer(value: string) {
|
||||
return withDefaultOnError(() => {
|
||||
return JSON.stringify(convert.xml2js(value, { compact: true }), null, 2);
|
||||
}, '');
|
||||
}
|
||||
|
||||
const rules: UseValidationRule<string>[] = [
|
||||
{
|
||||
validator: isValidXML,
|
||||
message: t('tools.xml-to-json.invalidMessage'),
|
||||
},
|
||||
];
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<format-transformer
|
||||
input-label="t('tools.xml-to-json.inputLabel')"
|
||||
:input-default="defaultValue"
|
||||
input-placeholder="t('tools.xml-to-json.inputPlaceholder')"
|
||||
output-label="t('tools.xml-to-json.outputLabel')"
|
||||
output-language="json"
|
||||
:transformer="transformer"
|
||||
:input-validation-rules="rules"
|
||||
/>
|
||||
</template>
|
Loading…
Add table
Add a link
Reference in a new issue