Skip to content

Commit 0622e17

Browse files
committed
Merge branch 'feat/json-escape' into chore/all-my-stuffs
# Conflicts: # package.json # pnpm-lock.yaml # src/tools/index.ts
2 parents d22e0d6 + bf9e07a commit 0622e17

File tree

5 files changed

+102
-1
lines changed

5 files changed

+102
-1
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@
266266
"potrace": "^2.1.8",
267267
"qrcode": "^1.5.1",
268268
"rtf-stream-parser": "^3.8.0",
269+
"slashes": "^3.0.12",
269270
"sql-formatter": "^13.0.0",
270271
"sshpk": "^1.18.0",
271272
"turndown": "^7.1.2",

pnpm-lock.yaml

Lines changed: 9 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
@@ -118,6 +118,7 @@ import { tool as fileType } from './file-type';
118118
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';
121+
import { tool as jsonEscaper } from './json-escaper';
121122
import { tool as pdfSignatureChecker } from './pdf-signature-checker';
122123
import { tool as numeronymGenerator } from './numeronym-generator';
123124
import { tool as macAddressGenerator } from './mac-address-generator';
@@ -335,6 +336,7 @@ export const toolsByCategory: ToolCategory[] = [
335336
phpArrayToJson,
336337
torrentToMagnet,
337338
unicodeSearch,
339+
jsonEscaper,
338340
],
339341
},
340342
{

src/tools/json-escaper/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 Escaper/Unescaper',
6+
path: '/json-escaper',
7+
description: 'Escape and unescape JSON string',
8+
keywords: ['json', 'string', 'escape', 'unescape'],
9+
component: () => import('./json-escaper.vue'),
10+
icon: Braces,
11+
createdAt: new Date('2024-03-09'),
12+
});
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<script setup lang="ts">
2+
import { addSlashes, removeSlashes } from 'slashes';
3+
import TextareaCopyable from '@/components/TextareaCopyable.vue';
4+
5+
const unescapedInput = ref('');
6+
const escapedOutput = computed(
7+
() => {
8+
try {
9+
return addSlashes(unescapedInput.value);
10+
}
11+
catch (e: any) {
12+
return e.toString();
13+
}
14+
},
15+
);
16+
17+
const escapedInput = ref('');
18+
const unescapedOutput = computed(
19+
() => {
20+
try {
21+
return removeSlashes(escapedInput.value);
22+
}
23+
catch (e: any) {
24+
return e.toString();
25+
}
26+
},
27+
);
28+
</script>
29+
30+
<template>
31+
<div max-w-600>
32+
<c-card title="Escape JSON string">
33+
<c-input-text
34+
v-model:value="unescapedInput"
35+
placeholder="Put your string to escape..."
36+
label="String to escape"
37+
raw-text
38+
multiline
39+
rows="5"
40+
mb-5
41+
/>
42+
43+
<n-divider />
44+
45+
<TextareaCopyable
46+
label="Escaped string"
47+
:value="escapedOutput"
48+
multiline
49+
readonly
50+
rows="5"
51+
mb-5
52+
/>
53+
</c-card>
54+
55+
<c-card title="Unescape JSON string" mt-5>
56+
<c-input-text
57+
v-model:value="escapedInput"
58+
placeholder="Put your string to unescape..."
59+
label="String to unescape"
60+
raw-text
61+
multiline
62+
rows="5"
63+
mb-5
64+
/>
65+
66+
<n-divider />
67+
68+
<TextareaCopyable
69+
label="Unescaped string"
70+
:value="unescapedOutput"
71+
multiline
72+
readonly
73+
rows="5"
74+
mb-5
75+
/>
76+
</c-card>
77+
</div>
78+
</template>

0 commit comments

Comments
 (0)