Skip to content

Commit 9cd3841

Browse files
committed
Merge branch 'feat/json-linter' into chore/all-my-stuffs
# Conflicts: # components.d.ts # package.json # pnpm-lock.yaml # src/tools/index.ts
2 parents 0622e17 + 83a78e9 commit 9cd3841

File tree

6 files changed

+102
-1
lines changed

6 files changed

+102
-1
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@
223223
"jsonar-mod": "^1.9.0",
224224
"jsstack.js": "^2.0.0",
225225
"jsvat-next": "^3.0.4",
226+
"jsonlint-mod": "^1.7.6",
226227
"jwt-decode": "^3.1.2",
227228
"korean-unpacker": "^1.0.3",
228229
"libphonenumber-js": "^1.10.28",

pnpm-lock.yaml

Lines changed: 21 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/tools/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ import { tool as htmlCleaner } from './html-cleaner';
119119
import { tool as imageToAsciiArt } from './image-to-ascii-art';
120120
import { tool as ipv6SubnetCalculator } from './ipv6-subnet-calculator';
121121
import { tool as jsonEscaper } from './json-escaper';
122+
import { tool as jsonLinter } from './json-linter';
122123
import { tool as pdfSignatureChecker } from './pdf-signature-checker';
123124
import { tool as numeronymGenerator } from './numeronym-generator';
124125
import { tool as macAddressGenerator } from './mac-address-generator';
@@ -370,6 +371,7 @@ export const toolsByCategory: ToolCategory[] = [
370371
jsonViewer,
371372
jsonMinify,
372373
jsonSizeAnalyzer,
374+
jsonLinter,
373375
jsonToCsv,
374376
sqlPrettify,
375377
chmodCalculator,

src/tools/json-linter/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Braces } from '@vicons/tabler';
2+
import { defineTool } from '../tool';
3+
4+
export const tool = defineTool({
5+
name: 'JSON Linter',
6+
path: '/json-linter',
7+
description: 'Check and lint JSON content',
8+
keywords: ['json', 'linter', 'check'],
9+
component: () => import('./json-linter.vue'),
10+
icon: Braces,
11+
createdAt: new Date('2024-03-20'),
12+
});

src/tools/json-linter/json-linter.vue

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<script setup lang="ts">
2+
import linter from 'jsonlint-mod';
3+
4+
const jsonContent = ref(
5+
`{
6+
a: True;
7+
b=5
8+
}`,
9+
);
10+
11+
const conversionError = computed(() => {
12+
try {
13+
linter.parse(jsonContent.value);
14+
return null;
15+
}
16+
catch (e: any) {
17+
return e.toString();
18+
}
19+
});
20+
21+
const MONACO_EDITOR_OPTIONS = {
22+
automaticLayout: true,
23+
formatOnType: true,
24+
formatOnPaste: true,
25+
};
26+
</script>
27+
28+
<template>
29+
<div>
30+
<c-label label="Paste your JSON file content:">
31+
<div relative w-full>
32+
<c-monaco-editor
33+
v-model:value="jsonContent"
34+
theme="vs-dark"
35+
language="yaml"
36+
height="250px"
37+
:options="MONACO_EDITOR_OPTIONS"
38+
/>
39+
</div>
40+
</c-label>
41+
42+
<div v-if="conversionError">
43+
<n-alert title="The following errors occured" type="error" mt-5>
44+
<pre>
45+
{{ conversionError }}
46+
</pre>
47+
</n-alert>
48+
</div>
49+
<div v-else>
50+
<n-alert type="success" mt-5>
51+
Validation successful!
52+
</n-alert>
53+
</div>
54+
</div>
55+
</template>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
declare module 'jsonlint-mod'{
2+
/**
3+
* Parse a JSON string to Typescript Object. If there is an error will print it
4+
* as human readible.
5+
*
6+
* Please use `import * as jsonlint from 'jsonlint';`. Instead of,
7+
* `import {parse} from 'jsonlint';`. Otherwise, it cannot reference to the
8+
* correct instance.
9+
*/
10+
export function parse(str: string): Record<string, unknown>;
11+
}

0 commit comments

Comments
 (0)