2022-07-25 23:21:42 +02:00
|
|
|
<template>
|
2023-04-20 20:49:28 +02:00
|
|
|
<c-card title="String to base64">
|
2022-07-25 23:21:42 +02:00
|
|
|
<n-form-item label="String to encode">
|
|
|
|
<n-input v-model:value="textInput" type="textarea" placeholder="Put your string here..." rows="5" />
|
|
|
|
</n-form-item>
|
|
|
|
|
|
|
|
<n-form-item label="Base64 of string">
|
|
|
|
<n-input
|
|
|
|
:value="base64Output"
|
|
|
|
type="textarea"
|
|
|
|
readonly
|
|
|
|
placeholder="The base64 encoding of your string will be here"
|
|
|
|
rows="5"
|
|
|
|
/>
|
|
|
|
</n-form-item>
|
|
|
|
|
|
|
|
<n-space justify="center">
|
2023-04-19 21:38:59 +02:00
|
|
|
<c-button @click="copyTextBase64()"> Copy base64 </c-button>
|
2022-07-25 23:21:42 +02:00
|
|
|
</n-space>
|
2023-04-20 20:49:28 +02:00
|
|
|
</c-card>
|
2022-07-25 23:21:42 +02:00
|
|
|
|
2023-04-20 20:49:28 +02:00
|
|
|
<c-card title="Base64 to string">
|
2022-07-29 15:49:28 +02:00
|
|
|
<n-form-item label="Base64 string to decode" v-bind="b64Validation.attrs">
|
2022-07-25 23:21:42 +02:00
|
|
|
<n-input v-model:value="base64Input" type="textarea" placeholder="Your base64 string..." rows="5" />
|
|
|
|
</n-form-item>
|
|
|
|
|
|
|
|
<n-form-item label="Decoded string">
|
|
|
|
<n-input :value="textOutput" type="textarea" readonly placeholder="The decoded string will be here" rows="5" />
|
|
|
|
</n-form-item>
|
|
|
|
|
|
|
|
<n-space justify="center">
|
2023-04-19 21:38:59 +02:00
|
|
|
<c-button @click="copyText()"> Copy decoded string </c-button>
|
2022-07-25 23:21:42 +02:00
|
|
|
</n-space>
|
2023-04-20 20:49:28 +02:00
|
|
|
</c-card>
|
2022-07-25 23:21:42 +02:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
|
import { useCopy } from '@/composable/copy';
|
|
|
|
import { useValidation } from '@/composable/validation';
|
2022-08-04 12:09:32 +02:00
|
|
|
import { base64ToText, isValidBase64, textToBase64 } from '@/utils/base64';
|
|
|
|
import { withDefaultOnError } from '@/utils/defaults';
|
2022-07-25 23:21:42 +02:00
|
|
|
import { computed, ref } from 'vue';
|
|
|
|
|
|
|
|
const textInput = ref('');
|
2022-08-04 12:09:32 +02:00
|
|
|
const base64Output = computed(() => textToBase64(textInput.value));
|
2022-07-25 23:21:42 +02:00
|
|
|
const { copy: copyTextBase64 } = useCopy({ source: base64Output, text: 'Base64 string copied to the clipboard' });
|
|
|
|
|
|
|
|
const base64Input = ref('');
|
2022-08-04 12:09:32 +02:00
|
|
|
const textOutput = computed(() => withDefaultOnError(() => base64ToText(base64Input.value.trim()), ''));
|
2022-07-25 23:21:42 +02:00
|
|
|
const { copy: copyText } = useCopy({ source: textOutput, text: 'String copied to the clipboard' });
|
|
|
|
const b64Validation = useValidation({
|
|
|
|
source: base64Input,
|
2022-08-04 12:09:32 +02:00
|
|
|
rules: [{ message: 'Invalid base64 string', validator: (value) => isValidBase64(value.trim()) }],
|
2022-07-25 23:21:42 +02:00
|
|
|
});
|
|
|
|
</script>
|