mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-23 06:11:06 +03:00
Merge branch 'up/feat/json-to-typescript' into chore/all-my-stuffs
This commit is contained in:
commit
e7b70a5858
10 files changed
+564
-104
No files matched your search
@@ -333,6 +333,10 @@ tools:
|
|||||||
title: JSON to TOML
|
title: JSON to TOML
|
||||||
description: Parse and convert JSON to TOML.
|
description: Parse and convert JSON to TOML.
|
||||||
|
|
||||||
|
json-to-ts:
|
||||||
|
title: JSON to TS
|
||||||
|
description: Parse and convert JSON to TS.
|
||||||
|
|
||||||
device-information:
|
device-information:
|
||||||
title: Device information
|
title: Device information
|
||||||
description: Get information about your current device (screen size, pixel-ratio, user agent, ...)
|
description: Get information about your current device (screen size, pixel-ratio, user agent, ...)
|
||||||
|
|||||||
@@ -308,9 +308,14 @@ tools:
|
|||||||
hash-text:
|
hash-text:
|
||||||
title: Mã hóa văn bản
|
title: Mã hóa văn bản
|
||||||
description: 'Mã hóa một chuỗi văn bản bằng cách sử dụng các hàm bạn cần: MD5, SHA1, SHA256, SHA224, SHA512, SHA384, SHA3 hoặc RIPEMD160'
|
description: 'Mã hóa một chuỗi văn bản bằng cách sử dụng các hàm bạn cần: MD5, SHA1, SHA256, SHA224, SHA512, SHA384, SHA3 hoặc RIPEMD160'
|
||||||
|
|
||||||
json-to-toml:
|
json-to-toml:
|
||||||
title: Chuyển đổi JSON sang TOML
|
title: Chuyển đổi JSON sang TOML
|
||||||
description: Phân tích và chuyển đổi JSON sang TOML.
|
description: Phân tích và chuyển đổi JSON sang TOML.
|
||||||
|
|
||||||
|
json-to-ts:
|
||||||
|
title: Chuyển đổi JSON sang TS
|
||||||
|
description: Phân tích và chuyển đổi JSON sang TS.
|
||||||
|
|
||||||
device-information:
|
device-information:
|
||||||
title: Thông tin thiết bị
|
title: Thông tin thiết bị
|
||||||
|
|||||||
@@ -325,6 +325,10 @@ tools:
|
|||||||
title: JSON 转 TOML
|
title: JSON 转 TOML
|
||||||
description: 解析JSON并将其转换为TOML。
|
description: 解析JSON并将其转换为TOML。
|
||||||
|
|
||||||
|
json-to-ts:
|
||||||
|
title: JSON 转 TS
|
||||||
|
description: 解析JSON并将其转换为TS。
|
||||||
|
|
||||||
device-information:
|
device-information:
|
||||||
title: 设备信息
|
title: 设备信息
|
||||||
description: 获取有关当前设备的信息(屏幕大小、像素比率、用户代理…)
|
description: 获取有关当前设备的信息(屏幕大小、像素比率、用户代理…)
|
||||||
|
|||||||
@@ -127,6 +127,7 @@
|
|||||||
"highlight.js": "^11.7.0",
|
"highlight.js": "^11.7.0",
|
||||||
"iarna-toml-esm": "^3.0.5",
|
"iarna-toml-esm": "^3.0.5",
|
||||||
"ibantools": "^4.3.3",
|
"ibantools": "^4.3.3",
|
||||||
|
"json-to-ts": "^1.7.0",
|
||||||
"ical-generator": "^8.0.1",
|
"ical-generator": "^8.0.1",
|
||||||
"ical.js": "^2.1.0",
|
"ical.js": "^2.1.0",
|
||||||
"iconv-lite": "^0.6.3",
|
"iconv-lite": "^0.6.3",
|
||||||
|
|||||||
Generated
+456
-102
File diff suppressed because it is too large.
Load diff
@@ -2,12 +2,12 @@
|
|||||||
import { Copy } from '@vicons/tabler';
|
import { Copy } from '@vicons/tabler';
|
||||||
import { useElementSize } from '@vueuse/core';
|
import { useElementSize } from '@vueuse/core';
|
||||||
import hljs from 'highlight.js/lib/core';
|
import hljs from 'highlight.js/lib/core';
|
||||||
import javascriptHljs from 'highlight.js/lib/languages/javascript';
|
|
||||||
import jsonHljs from 'highlight.js/lib/languages/json';
|
import jsonHljs from 'highlight.js/lib/languages/json';
|
||||||
import sqlHljs from 'highlight.js/lib/languages/sql';
|
import sqlHljs from 'highlight.js/lib/languages/sql';
|
||||||
import xmlHljs from 'highlight.js/lib/languages/xml';
|
import xmlHljs from 'highlight.js/lib/languages/xml';
|
||||||
import yamlHljs from 'highlight.js/lib/languages/yaml';
|
import yamlHljs from 'highlight.js/lib/languages/yaml';
|
||||||
import iniHljs from 'highlight.js/lib/languages/ini';
|
import iniHljs from 'highlight.js/lib/languages/ini';
|
||||||
|
import tsHljs from 'highlight.js/lib/languages/typescript';
|
||||||
import bashHljs from 'highlight.js/lib/languages/bash';
|
import bashHljs from 'highlight.js/lib/languages/bash';
|
||||||
import markdownHljs from 'highlight.js/lib/languages/markdown';
|
import markdownHljs from 'highlight.js/lib/languages/markdown';
|
||||||
import jsHljs from 'highlight.js/lib/languages/javascript';
|
import jsHljs from 'highlight.js/lib/languages/javascript';
|
||||||
@@ -38,13 +38,13 @@ const props = withDefaults(
|
|||||||
downloadButtonText: 'Download',
|
downloadButtonText: 'Download',
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
hljs.registerLanguage('javascript', javascriptHljs);
|
|
||||||
hljs.registerLanguage('sql', sqlHljs);
|
hljs.registerLanguage('sql', sqlHljs);
|
||||||
hljs.registerLanguage('json', jsonHljs);
|
hljs.registerLanguage('json', jsonHljs);
|
||||||
hljs.registerLanguage('html', xmlHljs);
|
hljs.registerLanguage('html', xmlHljs);
|
||||||
hljs.registerLanguage('xml', xmlHljs);
|
hljs.registerLanguage('xml', xmlHljs);
|
||||||
hljs.registerLanguage('yaml', yamlHljs);
|
hljs.registerLanguage('yaml', yamlHljs);
|
||||||
hljs.registerLanguage('toml', iniHljs);
|
hljs.registerLanguage('toml', iniHljs);
|
||||||
|
hljs.registerLanguage('ts', tsHljs);
|
||||||
hljs.registerLanguage('bash', bashHljs);
|
hljs.registerLanguage('bash', bashHljs);
|
||||||
hljs.registerLanguage('markdown', markdownHljs);
|
hljs.registerLanguage('markdown', markdownHljs);
|
||||||
hljs.registerLanguage('css', cssHljs);
|
hljs.registerLanguage('css', cssHljs);
|
||||||
|
|||||||
@@ -152,6 +152,7 @@ import { tool as emojiPicker } from './emoji-picker';
|
|||||||
import { tool as passwordStrengthAnalyser } from './password-strength-analyser';
|
import { tool as passwordStrengthAnalyser } from './password-strength-analyser';
|
||||||
import { tool as yamlToToml } from './yaml-to-toml';
|
import { tool as yamlToToml } from './yaml-to-toml';
|
||||||
import { tool as jsonToToml } from './json-to-toml';
|
import { tool as jsonToToml } from './json-to-toml';
|
||||||
|
import { tool as jsonToTS } from './json-to-ts';
|
||||||
import { tool as tomlToYaml } from './toml-to-yaml';
|
import { tool as tomlToYaml } from './toml-to-yaml';
|
||||||
import { tool as tomlToJson } from './toml-to-json';
|
import { tool as tomlToJson } from './toml-to-json';
|
||||||
import { tool as jsonToCsv } from './json-to-csv';
|
import { tool as jsonToCsv } from './json-to-csv';
|
||||||
@@ -295,6 +296,7 @@ export const toolsByCategory: ToolCategory[] = [
|
|||||||
jsonToJavascript,
|
jsonToJavascript,
|
||||||
jsonToYaml,
|
jsonToYaml,
|
||||||
jsonToToml,
|
jsonToToml,
|
||||||
|
jsonToTS,
|
||||||
listConverter,
|
listConverter,
|
||||||
listComparer,
|
listComparer,
|
||||||
tomlToJson,
|
tomlToJson,
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import { Braces } from '@vicons/tabler';
|
||||||
|
import { defineTool } from '../tool';
|
||||||
|
import { translate } from '@/plugins/i18n.plugin';
|
||||||
|
|
||||||
|
export const tool = defineTool({
|
||||||
|
name: translate('tools.json-to-ts.title'),
|
||||||
|
path: '/json-to-ts',
|
||||||
|
description: translate('tools.json-to-ts.description'),
|
||||||
|
keywords: ['json', 'parse', 'typescript', 'convert', 'transform'],
|
||||||
|
component: () => import('./json-to-ts.vue'),
|
||||||
|
icon: Braces,
|
||||||
|
createdAt: new Date('2024-04-25'),
|
||||||
|
});
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
import { expect, test } from '@playwright/test';
|
||||||
|
|
||||||
|
test.describe('Tool - JSON to TS', () => {
|
||||||
|
test.beforeEach(async ({ page }) => {
|
||||||
|
await page.goto('/json-to-ts');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Has correct title', async ({ page }) => {
|
||||||
|
await expect(page).toHaveTitle('JSON to TS - IT Tools');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('JSON is parsed and outputs clean TS', async ({ page }) => {
|
||||||
|
await page.getByTestId('input').fill(`
|
||||||
|
{
|
||||||
|
"foo": "bar",
|
||||||
|
"list": {
|
||||||
|
"name": "item",
|
||||||
|
"another": {
|
||||||
|
"key": "value"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`.trim());
|
||||||
|
|
||||||
|
const generatedJson = await page.getByTestId('area-content').innerText();
|
||||||
|
|
||||||
|
expect(generatedJson.trim()).toEqual(
|
||||||
|
`
|
||||||
|
interface DataProps {
|
||||||
|
foo: string;
|
||||||
|
list: List;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface List {
|
||||||
|
name: string;
|
||||||
|
another: Another;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Another {
|
||||||
|
key: string;
|
||||||
|
}
|
||||||
|
`.trim(),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import JSON2TS from 'json-to-ts';
|
||||||
|
import JSON5 from 'json5';
|
||||||
|
import { withDefaultOnError } from '../../utils/defaults';
|
||||||
|
import type { UseValidationRule } from '@/composable/validation';
|
||||||
|
|
||||||
|
function convertJsonToTs(value: string) {
|
||||||
|
return JSON2TS(JSON5.parse(value), { rootName: 'DataProps' }).join('\n\n').trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
function transformer(value: string) {
|
||||||
|
return value.trim() === '' ? '' : withDefaultOnError(() => convertJsonToTs(value), '');
|
||||||
|
}
|
||||||
|
|
||||||
|
const rules: UseValidationRule<string>[] = [
|
||||||
|
{
|
||||||
|
validator: (v: string) => v === '' || JSON5.parse(v),
|
||||||
|
message: 'Provided JSON is not valid.',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<format-transformer
|
||||||
|
input-label="Your JSON"
|
||||||
|
input-placeholder="Paste your JSON here..."
|
||||||
|
output-label="TS from your JSON"
|
||||||
|
output-language="ts"
|
||||||
|
:input-validation-rules="rules"
|
||||||
|
:transformer="transformer"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
Reference in new issue
Block a user