mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-20 21:23:08 +03:00
feat(new tools): YAML/JSON Merger
This commit is contained in:
1 parent
d28f275168
commit
1d02e32486
7 files changed
+118
-1
No files matched your search
@@ -213,6 +213,7 @@
|
||||
"mathjs": "^14.2.1",
|
||||
"md-editor-v3": "^4.21.3",
|
||||
"memorystream": "^0.3.1",
|
||||
"merge-anything": "^6.0.6",
|
||||
"mermaid": "^11.6.0",
|
||||
"mime-types": "^2.1.35",
|
||||
"mitex-wasm": "^0.2.5",
|
||||
|
||||
Generated
+4
-1
@@ -527,6 +527,9 @@ dependencies:
|
||||
memorystream:
|
||||
specifier: ^0.3.1
|
||||
version: 0.3.1
|
||||
merge-anything:
|
||||
specifier: ^6.0.6
|
||||
version: 6.0.6
|
||||
mermaid:
|
||||
specifier: ^11.6.0
|
||||
version: 11.6.0
|
||||
@@ -11312,7 +11315,7 @@ packages:
|
||||
resolution: {integrity: sha512-tNBpTytI180+uGpKu4dFupbkA7rmEl+ZFo27mSeR8Ov80rpMDBbmLORGTsCkCN8s50aOS79P0sg3YUKz3Tr/4Q==}
|
||||
engines: {node: '>=18'}
|
||||
dependencies:
|
||||
is-what: 5.0.2
|
||||
is-what: 5.2.1
|
||||
ts-toolbelt: 9.6.0
|
||||
dev: false
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import { Braces } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'JSON Merger',
|
||||
path: '/json-merger',
|
||||
description: 'Merge deeply two JSON content',
|
||||
keywords: ['json', 'merger'],
|
||||
component: () => import('./json-merger.vue'),
|
||||
icon: Braces,
|
||||
createdAt: new Date('2025-07-19'),
|
||||
category: 'JSON',
|
||||
});
|
||||
@@ -0,0 +1,41 @@
|
||||
<script setup lang="ts">
|
||||
import JSON5 from 'json5';
|
||||
import { merge } from 'merge-anything';
|
||||
import type { UseValidationRule } from '@/composable/validation';
|
||||
|
||||
const json1 = ref('{a:{b:5}}');
|
||||
const json2 = ref('{a:{c:6}}');
|
||||
const merged = computed(() => {
|
||||
try {
|
||||
return JSON.stringify(
|
||||
merge(
|
||||
JSON.parseBigInt(json1.value),
|
||||
JSON.parseBigInt(json2.value),
|
||||
),
|
||||
null, 2,
|
||||
);
|
||||
}
|
||||
catch (e: any) {
|
||||
return e.toString();
|
||||
}
|
||||
});
|
||||
|
||||
const rules: UseValidationRule<string>[] = [
|
||||
{
|
||||
validator: (v: string) => v === '' || JSON5.parse(v),
|
||||
message: 'Provided JSON is not valid',
|
||||
},
|
||||
];
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<c-card title="Your first JSON Content:">
|
||||
<c-input-text v-model:value="json1" multiline mb-1 rows="10" placeholder="Put your JSON content" :validation-rules="rules" />
|
||||
</c-card>
|
||||
<c-card title="Your second JSON Content:">
|
||||
<c-input-text v-model:value="json2" multiline mb-1 rows="10" placeholder="Put your JSON content" :validation-rules="rules" />
|
||||
</c-card>
|
||||
<c-card title="Merged JSON:">
|
||||
<textarea-copyable v-model:value="merged" language="json" placeholder="Your merged JSON will be here" download-file-name="merge.json" />
|
||||
</c-card>
|
||||
</template>
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
declare module 'merge-anything' {
|
||||
export function merge(obj1: any, obj2: any): any;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import { AlignJustified } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'YAML Merger',
|
||||
path: '/yaml-merger',
|
||||
description: 'Merge deeply two YAML content',
|
||||
keywords: ['yaml', 'merger'],
|
||||
component: () => import('./yaml-merger.vue'),
|
||||
icon: AlignJustified,
|
||||
createdAt: new Date('2025-07-19'),
|
||||
npmPackages: ['yaml'],
|
||||
category: 'YAML',
|
||||
});
|
||||
@@ -0,0 +1,42 @@
|
||||
<script setup lang="ts">
|
||||
import YAML from 'yaml';
|
||||
import { merge } from 'merge-anything';
|
||||
import type { UseValidationRule } from '@/composable/validation';
|
||||
|
||||
const yaml1 = ref(`a:
|
||||
b: 5`);
|
||||
const yaml2 = ref(`a:
|
||||
c: 5`);
|
||||
const merged = computed(() => {
|
||||
try {
|
||||
return YAML.stringify(
|
||||
merge(
|
||||
YAML.parse(yaml1.value, { intAsBigInt: true }),
|
||||
YAML.parse(yaml2.value, { intAsBigInt: true }),
|
||||
),
|
||||
);
|
||||
}
|
||||
catch (e: any) {
|
||||
return e.toString();
|
||||
}
|
||||
});
|
||||
|
||||
const rules: UseValidationRule<string>[] = [
|
||||
{
|
||||
validator: (v: string) => v === '' || YAML.parse(v),
|
||||
message: 'Provided YAML is not valid',
|
||||
},
|
||||
];
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<c-card title="Your first YAML Content:">
|
||||
<c-input-text v-model:value="yaml1" multiline mb-1 rows="10" placeholder="Put your YAML content" :validation-rules="rules" />
|
||||
</c-card>
|
||||
<c-card title="Your second YAML Content:">
|
||||
<c-input-text v-model:value="yaml2" multiline mb-1 rows="10" placeholder="Put your YAML content" :validation-rules="rules" />
|
||||
</c-card>
|
||||
<c-card title="Merged YAML:">
|
||||
<textarea-copyable v-model:value="merged" language="yaml" placeholder="Your merged YAML will be here" download-file-name="merge.yaml" />
|
||||
</c-card>
|
||||
</template>
|
||||
Reference in new issue
Block a user