Skip to content

Commit 9df99e4

Browse files
committed
feat(new tool): Base64 Hex Converter
Fix CorentinTh#1505
1 parent 08d977b commit 9df99e4

File tree

3 files changed

+122
-0
lines changed

3 files changed

+122
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
<script setup lang="ts">
2+
import Base64 from 'js-base64';
3+
import hexArray from 'hex-array';
4+
import { useCopy } from '@/composable/copy';
5+
import { isValidBase64 } from '@/utils/base64';
6+
7+
const textInput = ref('');
8+
const base64Output = computed(() => {
9+
try {
10+
return Base64.fromUint8Array(hexArray.fromString(textInput.value));
11+
}
12+
catch (e: any) {
13+
return e.toString();
14+
}
15+
});
16+
const { copy: copyTextBase64 } = useCopy({ source: base64Output, text: 'Base64 Hex Array copied to the clipboard' });
17+
18+
const uppercase = ref(false);
19+
const grouping = ref(0);
20+
const rowlength = ref(0);
21+
22+
const base64Input = ref('');
23+
const textOutput = computed(() => {
24+
try {
25+
return hexArray.toString(Base64.toUint8Array(base64Input.value), {
26+
27+
});
28+
}
29+
catch (e: any) {
30+
return e.toString();
31+
}
32+
},
33+
);
34+
const { copy: copyText } = useCopy({ source: textOutput, text: 'Hex Array copied to the clipboard' });
35+
const b64ValidationRules = [
36+
{
37+
message: 'Invalid base64 string',
38+
validator: (value: string) => isValidBase64(value.trim()),
39+
},
40+
];
41+
</script>
42+
43+
<template>
44+
<c-card title="Hex Array to Base64">
45+
<c-input-text
46+
v-model:value="textInput"
47+
multiline
48+
placeholder="Put your Hex Array here..."
49+
rows="5"
50+
label="Hex Array to encode"
51+
raw-text
52+
mb-5
53+
/>
54+
55+
<c-input-text
56+
label="Base64 of Hex Array"
57+
:value="base64Output"
58+
multiline
59+
readonly
60+
placeholder="The base64 encoding of your Hex Array will be here"
61+
rows="5"
62+
mb-5
63+
/>
64+
65+
<div flex justify-center>
66+
<c-button @click="copyTextBase64()">
67+
Copy base64
68+
</c-button>
69+
</div>
70+
</c-card>
71+
72+
<c-card title="Base64 to Hex Array">
73+
<n-form-item label="Uppercase" label-placement="left">
74+
<n-switch v-model:value="uppercase" />
75+
</n-form-item>
76+
<n-form-item label="Group by" label-placement="left">
77+
<n-input-number v-model:value="grouping" :min="0" /> digits (0 = no grouping)
78+
</n-form-item>
79+
<n-form-item label="Split as rows by" label-placement="left">
80+
<n-input-number v-model:value="rowlength" :min="0" /> group of digits (0 = no rows)
81+
</n-form-item>
82+
<c-input-text
83+
v-model:value="base64Input"
84+
multiline
85+
placeholder="Your base64 Hex Array..."
86+
rows="5"
87+
:validation-rules="b64ValidationRules"
88+
label="Base64 Hex Array to decode"
89+
mb-5
90+
/>
91+
92+
<c-input-text
93+
v-model:value="textOutput"
94+
label="Decoded Hex Array"
95+
placeholder="The decoded Hex Array will be here"
96+
multiline
97+
rows="5"
98+
readonly
99+
mb-5
100+
/>
101+
102+
<div flex justify-center>
103+
<c-button @click="copyText()">
104+
Copy decoded Hex Array
105+
</c-button>
106+
</div>
107+
</c-card>
108+
</template>
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { FileDigit } from '@vicons/tabler';
2+
import { defineTool } from '../tool';
3+
4+
export const tool = defineTool({
5+
name: 'Base64 Hex array encoder/decoder',
6+
path: '/base64-hex-converter',
7+
description: 'Simply encode and decode Hex array into a their base64 representation.',
8+
keywords: ['base64', 'converter', 'conversion', 'web', 'data', 'format', 'atob', 'btoa', 'hex'],
9+
component: () => import('./base64-hex-converter.vue'),
10+
icon: FileDigit,
11+
createdAt: new Date('2025-02-09'),
12+
});

src/tools/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ 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';
44
import { tool as emailNormalizer } from './email-normalizer';
5+
import { tool as base64HexConverter } from './base64-hex-converter';
56

67
import { tool as asciiTextDrawer } from './ascii-text-drawer';
78

@@ -101,6 +102,7 @@ export const toolsByCategory: ToolCategory[] = [
101102
romanNumeralConverter,
102103
base64StringConverter,
103104
base64FileConverter,
105+
base64HexConverter,
104106
colorConverter,
105107
caseConverter,
106108
textToNatoAlphabet,

0 commit comments

Comments
 (0)