mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-20 21:23:08 +03:00
Merge branch 'up/feat/js-to-json' into chore/all-my-stuffs
This commit is contained in:
commit
de8bb9bfae
8 files changed
+119
-1
No files matched your search
+9
-1
@@ -203,7 +203,15 @@ tools:
|
||||
|
||||
json-to-yaml-converter:
|
||||
title: JSON to YAML converter
|
||||
description: Simply convert JSON to YAML with this online live converter.
|
||||
description: Simply convert JSON to YAML with this live online converter.
|
||||
|
||||
json-to-javascript:
|
||||
title: JSON to JS converter
|
||||
description: Simply convert JSON to Javascript object with this live online converter.
|
||||
|
||||
javascript-to-json:
|
||||
title: JS to JSON converter
|
||||
description: Simply convert Javascript object to JSON with this live online converter.
|
||||
|
||||
url-parser:
|
||||
title: URL parser
|
||||
|
||||
@@ -198,6 +198,14 @@ tools:
|
||||
title: JSON到YAML转换器
|
||||
description: 在线转换将JSON转换为YAML。
|
||||
|
||||
json-to-javascript:
|
||||
title: JSON 到 JS 转换器
|
||||
description: 使用此在线转换器将 JSON 转换为 Javascript 对象。
|
||||
|
||||
javascript-to-json:
|
||||
title: JS 到 JSON 转换器
|
||||
description: 使用此在线转换器将 Javascript 对象转换为 JSON。
|
||||
|
||||
url-parser:
|
||||
title: Url分析器
|
||||
description: 解析url字符串以获取所有不同的部分(协议、来源、参数、端口、用户名密码…)
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import { Copy } from '@vicons/tabler';
|
||||
import { useElementSize } from '@vueuse/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 sqlHljs from 'highlight.js/lib/languages/sql';
|
||||
import xmlHljs from 'highlight.js/lib/languages/xml';
|
||||
@@ -37,6 +38,7 @@ const props = withDefaults(
|
||||
downloadButtonText: 'Download',
|
||||
},
|
||||
);
|
||||
hljs.registerLanguage('javascript', javascriptHljs);
|
||||
hljs.registerLanguage('sql', sqlHljs);
|
||||
hljs.registerLanguage('json', jsonHljs);
|
||||
hljs.registerLanguage('html', xmlHljs);
|
||||
|
||||
@@ -164,6 +164,8 @@ import { tool as jsonDiff } from './json-diff';
|
||||
import { tool as ipv4RangeExpander } from './ipv4-range-expander';
|
||||
import { tool as httpStatusCodes } from './http-status-codes';
|
||||
import { tool as yamlToJson } from './yaml-to-json-converter';
|
||||
import { tool as javascriptToJson } from './javascript-to-json';
|
||||
import { tool as jsonToJavascript } from './json-to-javascript';
|
||||
import { tool as jsonToYaml } from './json-to-yaml-converter';
|
||||
import { tool as ipv6UlaGenerator } from './ipv6-ula-generator';
|
||||
import { tool as ipv4AddressConverter } from './ipv4-address-converter';
|
||||
@@ -289,6 +291,8 @@ export const toolsByCategory: ToolCategory[] = [
|
||||
textToUnicodeNames,
|
||||
yamlToJson,
|
||||
yamlToToml,
|
||||
javascriptToJson,
|
||||
jsonToJavascript,
|
||||
jsonToYaml,
|
||||
jsonToToml,
|
||||
listConverter,
|
||||
|
||||
@@ -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.javascript-to-json.title'),
|
||||
path: '/javascript-to-json',
|
||||
description: translate('tools.javascript-to-json.description'),
|
||||
keywords: ['javascript', 'to', 'json'],
|
||||
component: () => import('./javascript-to-json.vue'),
|
||||
icon: Braces,
|
||||
createdAt: new Date('2024-03-29'),
|
||||
});
|
||||
@@ -0,0 +1,35 @@
|
||||
<script setup lang="ts">
|
||||
import JSON5 from 'json5';
|
||||
import type { UseValidationRule } from '@/composable/validation';
|
||||
import { isNotThrowing } from '@/utils/boolean';
|
||||
import { withDefaultOnError } from '@/utils/defaults';
|
||||
|
||||
const indentSize = useStorage('json-prettify:indent-size', 3);
|
||||
const transformer = (value: string) => withDefaultOnError(() => JSON.stringify(JSON5.parse(value), null, indentSize.value), '');
|
||||
|
||||
const rules: UseValidationRule<string>[] = [
|
||||
{
|
||||
validator: (value: string) => value === '' || isNotThrowing(() => JSON.stringify(JSON5.parse(value))),
|
||||
message: 'Provided JS Object is not valid.',
|
||||
},
|
||||
];
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div style="flex: 0 0 100%">
|
||||
<div style="margin: 0 auto; max-width: 600px" flex justify-center gap-3>
|
||||
<n-form-item label="Indent size :" label-placement="left" label-width="100" :show-feedback="false">
|
||||
<n-input-number v-model:value="indentSize" min="0" max="10" style="width: 100px" />
|
||||
</n-form-item>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<format-transformer
|
||||
input-label="Your JavaScript Object"
|
||||
input-placeholder="Paste your JS Object here..."
|
||||
output-label="JSON from your JavaScript Object"
|
||||
output-language="json"
|
||||
:input-validation-rules="rules"
|
||||
:transformer="transformer"
|
||||
/>
|
||||
</template>
|
||||
@@ -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-javascript.title'),
|
||||
path: '/json-to-javascript',
|
||||
description: translate('tools.json-to-javascript.description'),
|
||||
keywords: ['json', 'to', 'javascript'],
|
||||
component: () => import('./json-to-javascript.vue'),
|
||||
icon: Braces,
|
||||
createdAt: new Date('2024-03-29'),
|
||||
});
|
||||
@@ -0,0 +1,35 @@
|
||||
<script setup lang="ts">
|
||||
import JSON5 from 'json5';
|
||||
import type { UseValidationRule } from '@/composable/validation';
|
||||
import { isNotThrowing } from '@/utils/boolean';
|
||||
import { withDefaultOnError } from '@/utils/defaults';
|
||||
|
||||
const indentSize = useStorage('json-prettify:indent-size', 3);
|
||||
const transformer = (value: string) => withDefaultOnError(() => JSON5.stringify(JSON.parse(value), null, indentSize.value), '');
|
||||
|
||||
const rules: UseValidationRule<string>[] = [
|
||||
{
|
||||
validator: (value: string) => value === '' || isNotThrowing(() => JSON5.stringify(JSON.parse(value))),
|
||||
message: 'Provided JSON is not valid.',
|
||||
},
|
||||
];
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div style="flex: 0 0 100%">
|
||||
<div style="margin: 0 auto; max-width: 600px" flex justify-center gap-3>
|
||||
<n-form-item label="Indent size :" label-placement="left" label-width="100" :show-feedback="false">
|
||||
<n-input-number v-model:value="indentSize" min="0" max="10" style="width: 100px" />
|
||||
</n-form-item>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<format-transformer
|
||||
input-label="Your JSON"
|
||||
input-placeholder="Paste your JSON here..."
|
||||
output-label="JavaScript Object from your JSON"
|
||||
output-language="javascript"
|
||||
:input-validation-rules="rules"
|
||||
:transformer="transformer"
|
||||
/>
|
||||
</template>
|
||||
Reference in new issue
Block a user