mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-04-20 23:06:14 -04:00
feat(new-tool): json viewer
This commit is contained in:
parent
a60f64f744
commit
d356b1488f
6 changed files with 70 additions and 1 deletions
1
package-lock.json
generated
1
package-lock.json
generated
|
@ -20,6 +20,7 @@
|
||||||
"cronstrue": "^2.2.0",
|
"cronstrue": "^2.2.0",
|
||||||
"crypto-js": "^4.1.1",
|
"crypto-js": "^4.1.1",
|
||||||
"date-fns": "^2.28.0",
|
"date-fns": "^2.28.0",
|
||||||
|
"highlight.js": "^11.5.1",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"naive-ui": "^2.28.0",
|
"naive-ui": "^2.28.0",
|
||||||
"pinia": "^2.0.11",
|
"pinia": "^2.0.11",
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
"cronstrue": "^2.2.0",
|
"cronstrue": "^2.2.0",
|
||||||
"crypto-js": "^4.1.1",
|
"crypto-js": "^4.1.1",
|
||||||
"date-fns": "^2.28.0",
|
"date-fns": "^2.28.0",
|
||||||
|
"highlight.js": "^11.5.1",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"naive-ui": "^2.28.0",
|
"naive-ui": "^2.28.0",
|
||||||
"pinia": "^2.0.11",
|
"pinia": "^2.0.11",
|
||||||
|
|
|
@ -50,9 +50,11 @@ import {
|
||||||
NImage,
|
NImage,
|
||||||
NScrollbar,
|
NScrollbar,
|
||||||
NGradientText,
|
NGradientText,
|
||||||
|
NCode,
|
||||||
} from 'naive-ui';
|
} from 'naive-ui';
|
||||||
|
|
||||||
const components = [
|
const components = [
|
||||||
|
NCode,
|
||||||
NGradientText,
|
NGradientText,
|
||||||
NScrollbar,
|
NScrollbar,
|
||||||
NImage,
|
NImage,
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import { LockOpen } from '@vicons/tabler';
|
import { LockOpen } from '@vicons/tabler';
|
||||||
import type { ToolCategory } from './Tool';
|
import type { ToolCategory } from './Tool';
|
||||||
|
|
||||||
|
import { tool as jsonViewer } from './json-viewer';
|
||||||
import { tool as htmlEntities } from './html-entities';
|
import { tool as htmlEntities } from './html-entities';
|
||||||
import { tool as urlParser } from './url-parser';
|
import { tool as urlParser } from './url-parser';
|
||||||
import { tool as deviceInformation } from './device-information';
|
import { tool as deviceInformation } from './device-information';
|
||||||
|
@ -50,7 +51,7 @@ export const toolsByCategory: ToolCategory[] = [
|
||||||
{
|
{
|
||||||
name: 'Development',
|
name: 'Development',
|
||||||
icon: LockOpen,
|
icon: LockOpen,
|
||||||
components: [gitMemo, randomPortGenerator, crontabGenerator],
|
components: [gitMemo, randomPortGenerator, crontabGenerator, jsonViewer],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Text',
|
name: 'Text',
|
||||||
|
|
11
src/tools/json-viewer/index.ts
Normal file
11
src/tools/json-viewer/index.ts
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
import { Braces } from '@vicons/tabler';
|
||||||
|
import type { ITool } from './../Tool';
|
||||||
|
|
||||||
|
export const tool: ITool = {
|
||||||
|
name: 'JSON viewer',
|
||||||
|
path: '/json-viewer',
|
||||||
|
description: 'Prettify JSON string to a human friendly readable format.',
|
||||||
|
keywords: ['json', 'viewer', 'prettify', 'format'],
|
||||||
|
component: () => import('./json-viewer.vue'),
|
||||||
|
icon: Braces,
|
||||||
|
};
|
53
src/tools/json-viewer/json-viewer.vue
Normal file
53
src/tools/json-viewer/json-viewer.vue
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
<template>
|
||||||
|
<n-card>
|
||||||
|
<n-form-item
|
||||||
|
label="Your raw json:"
|
||||||
|
:feedback="rawJsonValidation.message"
|
||||||
|
:validation-status="rawJsonValidation.status"
|
||||||
|
>
|
||||||
|
<n-input v-model:value="rawJson" class="json-input" type="textarea" placeholder="Paste your raw json here..." />
|
||||||
|
</n-form-item>
|
||||||
|
</n-card>
|
||||||
|
|
||||||
|
<n-card v-if="cleanJson.length > 0">
|
||||||
|
<n-scrollbar :x-scrollable="true">
|
||||||
|
<n-config-provider :hljs="hljs">
|
||||||
|
<n-code :code="cleanJson" language="json" />
|
||||||
|
</n-config-provider>
|
||||||
|
</n-scrollbar>
|
||||||
|
</n-card>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { ref, computed } from 'vue';
|
||||||
|
import hljs from 'highlight.js/lib/core';
|
||||||
|
import json from 'highlight.js/lib/languages/json';
|
||||||
|
import { useValidation } from '@/composable/validation';
|
||||||
|
|
||||||
|
hljs.registerLanguage('json', json);
|
||||||
|
|
||||||
|
const rawJson = ref('');
|
||||||
|
const cleanJson = computed(() => {
|
||||||
|
try {
|
||||||
|
return JSON.stringify(JSON.parse(rawJson.value), null, 3);
|
||||||
|
} catch (_) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const rawJsonValidation = useValidation({
|
||||||
|
source: rawJson,
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
validator: (v) => JSON.parse(v),
|
||||||
|
message: 'Invalid json string',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="less" scoped>
|
||||||
|
.json-input ::v-deep(.n-input-wrapper) {
|
||||||
|
resize: both !important;
|
||||||
|
}
|
||||||
|
</style>
|
Loading…
Add table
Add a link
Reference in a new issue