feat(new tool): JSON Escape/Unescape

JSON String Escaper/Unescaper
Fix #659
This commit is contained in:
sharevb 2024-04-03 22:43:09 +02:00 committed by ShareVB
parent d3b32cc14e
commit 9c5b297b30
5 changed files with 106 additions and 6 deletions

View file

@ -6,6 +6,7 @@ import { tool as asciiTextDrawer } from './ascii-text-drawer';
import { tool as textToUnicode } from './text-to-unicode';
import { tool as safelinkDecoder } from './safelink-decoder';
import { tool as jsonEscaper } from './json-escaper';
import { tool as pdfSignatureChecker } from './pdf-signature-checker';
import { tool as numeronymGenerator } from './numeronym-generator';
import { tool as macAddressGenerator } from './mac-address-generator';
@ -128,6 +129,7 @@ export const toolsByCategory: ToolCategory[] = [
httpStatusCodes,
jsonDiff,
safelinkDecoder,
jsonEscaper,
],
},
{

View file

@ -0,0 +1,12 @@
import { Braces } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'Json Escaper/Unescaper',
path: '/json-escaper',
description: 'Escape and unescape JSON string',
keywords: ['json', 'string', 'escape', 'unescape'],
component: () => import('./json-escaper.vue'),
icon: Braces,
createdAt: new Date('2024-03-09'),
});

View file

@ -0,0 +1,78 @@
<script setup lang="ts">
import { addSlashes, removeSlashes } from 'slashes';
import TextareaCopyable from '@/components/TextareaCopyable.vue';
const unescapedInput = ref('');
const escapedOutput = computed(
() => {
try {
return addSlashes(unescapedInput.value);
}
catch (e: any) {
return e.toString();
}
},
);
const escapedInput = ref('');
const unescapedOutput = computed(
() => {
try {
return removeSlashes(escapedInput.value);
}
catch (e: any) {
return e.toString();
}
},
);
</script>
<template>
<div max-w-600>
<c-card title="Escape JSON string">
<c-input-text
v-model:value="unescapedInput"
placeholder="Put your string to escape..."
label="String to escape"
raw-text
multiline
rows="5"
mb-5
/>
<n-divider />
<TextareaCopyable
label="Escaped string"
:value="escapedOutput"
multiline
readonly
rows="5"
mb-5
/>
</c-card>
<c-card title="Unescape JSON string" mt-5>
<c-input-text
v-model:value="escapedInput"
placeholder="Put your string to unescape..."
label="String to unescape"
raw-text
multiline
rows="5"
mb-5
/>
<n-divider />
<TextareaCopyable
label="Unescaped string"
:value="unescapedOutput"
multiline
readonly
rows="5"
mb-5
/>
</c-card>
</div>
</template>