Skip to content

Commit 1b69560

Browse files
committed
Merge branch 'up/fix/json-sort' into chore/all-my-stuffs
2 parents 0c1b984 + df343d1 commit 1b69560

File tree

11 files changed

+197
-0
lines changed

11 files changed

+197
-0
lines changed

locales/en.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,10 @@ tools:
345345
title: PDF signature checker
346346
description: Verify the signatures of a PDF file. A signed PDF file contains one or more signatures that may be used to determine whether the contents of the file have been altered since the file was signed.
347347

348+
json-sort-master:
349+
title: JSON sort master
350+
description: Sort your JSON by keys and values.
351+
348352
json-minify:
349353
title: JSON minify
350354
description: Minify and compress your JSON by removing unnecessary whitespace.

locales/es.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ tools:
7171
text: Text
7272
data: Data
7373

74+
json-sort-master:
75+
title: Maestro de clasificación JSON
76+
description: Ordena tu JSON por claves y valores.
77+
7478
csv-to-json:
7579
title: CSV a JSON
7680
description: Convierte CSV a JSON con detección automática de cabeceras.

locales/fr.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,7 @@ tools:
8484
csv-to-json:
8585
title: CSV vers JSON
8686
description: Convertit les fichiers CSV en JSON avec détection automatique des en-têtes.
87+
88+
json-sort-master:
89+
title: Maître de tri JSON
90+
description: Triez votre JSON par clés et valeurs.

locales/pt.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,7 @@ tools:
7474
csv-to-json:
7575
title: CSV para JSON
7676
description: Converte CSV para JSON com detecção automática de cabeçalhos.
77+
78+
json-sort-master:
79+
title: 'Mestre de classificação JSON'
80+
description: 'Ordene seu JSON por chaves e valores.'

locales/uk.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,7 @@ tools:
7474
csv-to-json:
7575
title: 'CSV в JSON'
7676
description: 'Конвертуйте CSV в JSON з автоматичним визначенням заголовків.'
77+
78+
json-sort-master:
79+
title: JSON сортувальник
80+
description: Сортуйте ваш JSON за ключами та значеннями.

locales/vi.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,10 @@ tools:
222222
title: Định dạng và làm đẹp JSON
223223
description: Định dạng chuỗi JSON của bạn thành một định dạng dễ đọc và thân thiện với con người.
224224

225+
json-sort-master:
226+
title: Sắp xếp JSON
227+
description: Sắp xếp JSON của bạn theo các khóa và giá trị.
228+
225229
docker-run-to-docker-compose-converter:
226230
title: Chuyển đổi lệnh docker run thành tệp docker-compose
227231
description: Chuyển đổi các lệnh docker run thành tệp docker-compose!

locales/zh.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,10 @@ tools:
234234
title: JSON美化和格式化
235235
description: 将JSON字符串修饰为友好的可读格式。
236236

237+
json-sort-master:
238+
title: JSON排序大师
239+
description: 按键和值对您的JSON进行排序。
240+
237241
docker-run-to-docker-compose-converter:
238242
title: Docker Run 到 docker-compose 转换器
239243
description: 将 docker run 命令行转换为 docker-compose 文件!

src/tools/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { tool as base64FileConverter } from './base64-file-converter';
22
import { tool as base64StringConverter } from './base64-string-converter';
33
import { tool as basicAuthGenerator } from './basic-auth-generator';
4+
import { tool as jsonSortMaster } from './json-sort-master';
45
import { tool as jsonStringConverter } from './json-string-converter';
56
import { tool as dnsQueries } from './dns-queries';
67
import { tool as icoConverter } from './ico-converter';
@@ -298,6 +299,7 @@ export const toolsByCategory: ToolCategory[] = [
298299
jsonToJavascript,
299300
jsonToYaml,
300301
jsonToToml,
302+
jsonSortMaster,
301303
jsonToTS,
302304
listConverter,
303305
listComparer,

src/tools/json-sort-master/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { ArrowsSort } from '@vicons/tabler';
2+
import { defineTool } from '../tool';
3+
import { translate } from '@/plugins/i18n.plugin';
4+
5+
export const tool = defineTool({
6+
name: translate('tools.json-sort-master.title'),
7+
path: '/json-sort-master',
8+
description: translate('tools.json-sort-master.description'),
9+
keywords: ['json', 'sort'],
10+
component: () => import('./json-sort-master.vue'),
11+
icon: ArrowsSort,
12+
createdAt: new Date('2024-03-27'),
13+
});
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<script setup lang="ts">
2+
import JSON5 from 'json5';
3+
import { useStorage } from '@vueuse/core';
4+
import { formatJson } from './json.models';
5+
import { withDefaultOnError } from '@/utils/defaults';
6+
import { useValidation } from '@/composable/validation';
7+
import TextareaCopyable from '@/components/TextareaCopyable.vue';
8+
9+
const inputElement = ref<HTMLElement>();
10+
11+
const rawJson = useStorage('json-prettify:raw-json', '{"hello": "world", "foo": "bar"}');
12+
const sortMethod = useStorage('json-prettify:sort-method', 'key_name');
13+
const indentSize = useStorage('json-prettify:indent-size', 3);
14+
const keyName = ref('');
15+
const cleanJson = computed(() => withDefaultOnError(() => formatJson({ rawJson, sortMethod, keyName, indentSize }), ''));
16+
17+
const rawJsonValidation = useValidation({
18+
source: rawJson,
19+
rules: [
20+
{
21+
validator: v => v === '' || JSON5.parse(v),
22+
message: 'Provided JSON is not valid.',
23+
},
24+
],
25+
});
26+
</script>
27+
28+
<template>
29+
<div style="flex: 0 0 100%">
30+
<div style="margin: 0 auto; max-width: 400px" flex justify-center gap-3>
31+
<c-select
32+
v-model:value="sortMethod" mb-4 style="width: 200px" label="Sort Method" :options="[
33+
{
34+
label: 'Key Name',
35+
value: 'key_name',
36+
},
37+
{
38+
label: 'Key Value',
39+
value: 'key_val',
40+
},
41+
{
42+
label: 'Key Name (Descending)',
43+
value: 'key_name_desc',
44+
},
45+
{
46+
label: 'Key Value (Descending)',
47+
value: 'key_val_desc',
48+
},
49+
]"
50+
/>
51+
52+
<c-input-text v-if="!['key_name', 'key_name_desc'].includes(sortMethod)" v-model:value="keyName" label="Key Name:" style="width: 200px" clearable raw-text />
53+
</div>
54+
</div>
55+
56+
<n-form-item
57+
label="Your raw JSON" :feedback="rawJsonValidation.message"
58+
:validation-status="rawJsonValidation.status"
59+
>
60+
<c-input-text
61+
ref="inputElement" v-model:value="rawJson" placeholder="Paste your raw JSON here..." rows="20"
62+
multiline autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" monospace
63+
/>
64+
</n-form-item>
65+
<n-form-item label="Sorted version of your JSON">
66+
<TextareaCopyable :value="cleanJson" language="json" :follow-height-of="inputElement" />
67+
</n-form-item>
68+
</template>
69+
70+
<style lang="less" scoped>
71+
.result-card {
72+
position: relative;
73+
74+
.copy-button {
75+
position: absolute;
76+
top: 10px;
77+
right: 10px;
78+
}
79+
}
80+
</style>

0 commit comments

Comments
 (0)