mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-22 14:01:42 +03:00
1 parent
99f4be60ec
commit
f0d2347ee2
3 files changed
+19
-3
No files matched your search
@@ -2407,6 +2407,8 @@ tools:
|
|||||||
title-schema-validation-errors: Schema Validation Errors
|
title-schema-validation-errors: Schema Validation Errors
|
||||||
title-formatted-version: Formatted version
|
title-formatted-version: Formatted version
|
||||||
label-indent-size-0-compact: 'Indent size (0 = Compact):'
|
label-indent-size-0-compact: 'Indent size (0 = Compact):'
|
||||||
|
title-repaired-version: Auto Repaired and Formatted version
|
||||||
|
label-auto-repair-json: 'Auto Repair JSON:'
|
||||||
json-size-analyzer:
|
json-size-analyzer:
|
||||||
title: Json Size Analyzer
|
title: Json Size Analyzer
|
||||||
description: Measure JSON nodes relative weights
|
description: Measure JSON nodes relative weights
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ export const tool = defineTool({
|
|||||||
name: t('tools.json-linter.title'),
|
name: t('tools.json-linter.title'),
|
||||||
path: '/json-linter',
|
path: '/json-linter',
|
||||||
description: t('tools.json-linter.description'),
|
description: t('tools.json-linter.description'),
|
||||||
keywords: ['json', 'linter', 'check', 'validator'],
|
keywords: ['json', 'linter', 'check', 'validator', 'repair'],
|
||||||
component: () => import('./json-linter.vue'),
|
component: () => import('./json-linter.vue'),
|
||||||
icon: Braces,
|
icon: Braces,
|
||||||
createdAt: new Date('2024-03-20'),
|
createdAt: new Date('2024-03-20'),
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import linter from 'jsonlint-mod';
|
import linter from 'jsonlint-mod';
|
||||||
|
import { jsonrepair } from 'jsonrepair';
|
||||||
import { useJsonSchemaValidation } from '../json-viewer/useJsonSchemaValidation';
|
import { useJsonSchemaValidation } from '../json-viewer/useJsonSchemaValidation';
|
||||||
import { useITStorage, useQueryParamOrStorage } from '@/composable/queryParams';
|
import { useITStorage, useQueryParamOrStorage } from '@/composable/queryParams';
|
||||||
|
|
||||||
@@ -36,9 +37,16 @@ const schemaUrl = useQueryParamOrStorage<string>({ name: 'schema', storageName:
|
|||||||
const { schemas, errors: validationErrors } = useJsonSchemaValidation({ json: jsonContent, schemaUrl, schemaData });
|
const { schemas, errors: validationErrors } = useJsonSchemaValidation({ json: jsonContent, schemaUrl, schemaData });
|
||||||
|
|
||||||
const indentSize = useITStorage('json-linter:indent-size', 3);
|
const indentSize = useITStorage('json-linter:indent-size', 3);
|
||||||
|
const autoRepair = useITStorage('json-linter:repair', false);
|
||||||
const cleanJson = computed(() => {
|
const cleanJson = computed(() => {
|
||||||
try {
|
try {
|
||||||
return JSON.stringify(JSON.parseBigInt(jsonContent.value), null, indentSize.value);
|
let jsonContentValue = jsonContent.value;
|
||||||
|
if (autoRepair.value) {
|
||||||
|
jsonContentValue = jsonrepair(jsonContentValue);
|
||||||
|
}
|
||||||
|
return JSON.stringify(
|
||||||
|
JSON.parseBigInt(jsonContentValue),
|
||||||
|
null, indentSize.value);
|
||||||
}
|
}
|
||||||
catch (e: any) {
|
catch (e: any) {
|
||||||
return e.toString();
|
return e.toString();
|
||||||
@@ -60,6 +68,12 @@ const cleanJson = computed(() => {
|
|||||||
</div>
|
</div>
|
||||||
</c-label>
|
</c-label>
|
||||||
|
|
||||||
|
<n-space justify="center" mb-2>
|
||||||
|
<n-form-item :label="t('tools.json-linter.texts.label-auto-repair-json')" label-placement="left">
|
||||||
|
<n-switch v-model:value="autoRepair" />
|
||||||
|
</n-form-item>
|
||||||
|
</n-space>
|
||||||
|
|
||||||
<n-form-item :label="t('tools.json-linter.texts.label-json-schema')" label-placement="left" label-width="130px" label-align="right">
|
<n-form-item :label="t('tools.json-linter.texts.label-json-schema')" label-placement="left" label-width="130px" label-align="right">
|
||||||
<n-select
|
<n-select
|
||||||
v-model:value="schemaUrl"
|
v-model:value="schemaUrl"
|
||||||
@@ -109,7 +123,7 @@ const cleanJson = computed(() => {
|
|||||||
</n-alert>
|
</n-alert>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<c-card v-if="!conversionError" :title="t('tools.json-linter.texts.title-formatted-version')" mt-5>
|
<c-card v-if="!conversionError || autoRepair" :title="autoRepair ? t('tools.json-linter.texts.title-repaired-version') : t('tools.json-linter.texts.title-formatted-version')" mt-5>
|
||||||
<n-form-item :label="t('tools.json-linter.texts.label-indent-size-0-compact')" label-placement="left">
|
<n-form-item :label="t('tools.json-linter.texts.label-indent-size-0-compact')" label-placement="left">
|
||||||
<n-input-number-i18n v-model:value="indentSize" min="0" max="10" style="width: 100px" />
|
<n-input-number-i18n v-model:value="indentSize" min="0" max="10" style="width: 100px" />
|
||||||
</n-form-item>
|
</n-form-item>
|
||||||
|
|||||||
Reference in new issue
Block a user