feat(new tool): Base64 to Hex

Fix #1505
This commit is contained in:
ShareVB committed 2025-04-21 23:25:28 +02:00
1 parent 50581c2a36
commit 70194069b5
2 files changed
+125

No files matched your search

@@ -0,0 +1,112 @@
<script setup lang="ts">
import { Base64 } from 'js-base64';
import hexArray from 'hex-array';
import { useCopy } from '@/composable/copy';
import { isValidBase64 } from '@/utils/base64';
const textInput = ref('');
const base64Output = computed(() => {
try {
return Base64.fromUint8Array(hexArray.fromString(textInput.value));
}
catch (e: any) {
return e.toString();
}
});
const { copy: copyTextBase64 } = useCopy({ source: base64Output, text: 'Base64 Hex Array copied to the clipboard' });
const uppercase = ref(false);
const grouping = ref(0);
const rowlength = ref(0);
const base64Input = ref('');
const textOutput = computed(() => {
try {
return hexArray.toString(Base64.toUint8Array(base64Input.value), {
uppercase: uppercase.value,
grouping: grouping.value,
rowlength: rowlength.value,
});
}
catch (e: any) {
return e.toString();
}
},
);
const { copy: copyText } = useCopy({ source: textOutput, text: 'Hex Array copied to the clipboard' });
const b64ValidationRules = [
{
message: 'Invalid base64 string',
validator: (value: string) => isValidBase64(value.trim()),
},
];
</script>
<template>
<c-card title="Hex Array to Base64">
<c-input-text
v-model:value="textInput"
multiline
placeholder="Put your Hex Array here..."
rows="5"
label="Hex Array to encode"
raw-text
mb-5
/>
<c-input-text
label="Base64 of Hex Array"
:value="base64Output"
multiline
readonly
placeholder="The Base64 encoding of your Hex Array will be here"
rows="5"
mb-5
/>
<div flex justify-center>
<c-button @click="copyTextBase64()">
Copy Base64
</c-button>
</div>
</c-card>
<c-card title="Base64 to Hex Array">
<n-space align="baseline" justify="center" mb-1>
<n-form-item label="Uppercase" label-placement="left">
<n-switch v-model:value="uppercase" />
</n-form-item>
<n-form-item label="Group by" label-placement="left">
<n-input-number v-model:value="grouping" :min="0" style="width: 6em" mr-1 /> digits (0 = no grouping)
</n-form-item>
<n-form-item label="Split as rows by" label-placement="left">
<n-input-number v-model:value="rowlength" :min="0" style="width: 6em" mr-1 /> group of digits (0 = no rows)
</n-form-item>
</n-space>
<c-input-text
v-model:value="base64Input"
multiline
placeholder="Your Base64 Hex Array..."
rows="5"
:validation-rules="b64ValidationRules"
label="Base64 Hex Array to decode"
mb-5
/>
<c-input-text
v-model:value="textOutput"
label="Decoded Hex Array"
placeholder="The decoded Hex Array will be here"
multiline
rows="5"
readonly
mb-5
/>
<div flex justify-center>
<c-button @click="copyText()">
Copy Decoded Hex Array
</c-button>
</div>
</c-card>
</template>
+13
View File
@@ -0,0 +1,13 @@
import { FileDigit } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'Base64 Hex array encoder/decoder',
path: '/base64-hex-converter',
description: 'Simply encode and decode Hex array into a their base64 representation.',
keywords: ['base64', 'converter', 'conversion', 'web', 'data', 'format', 'atob', 'btoa', 'hex'],
component: () => import('./base64-hex-converter.vue'),
icon: FileDigit,
createdAt: new Date('2025-02-09'),
category: 'Converters',
});