diff --git a/locales/en.yml b/locales/en.yml index 4ae5997b..817f69bd 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -593,6 +593,7 @@ tools: placeholder-the-decoded-string-will-be-here: The decoded string will be here tag-copy-base64: Copy base64 tag-copy-decoded-string: Copy decoded string + text-encoding: 'Text Encoding:' toml-to-yaml: title: TOML to YAML description: Parse and convert TOML to YAML. diff --git a/src/tools/base64-string-converter/base64-string-converter.vue b/src/tools/base64-string-converter/base64-string-converter.vue index 250d8fed..e0ee8feb 100644 --- a/src/tools/base64-string-converter/base64-string-converter.vue +++ b/src/tools/base64-string-converter/base64-string-converter.vue @@ -3,22 +3,39 @@ import { useI18n } from 'vue-i18n'; import { useCopy } from '@/composable/copy'; import { base64ToText, isValidBase64, textToBase64 } from '@/utils/base64'; import { withDefaultOnError } from '@/utils/defaults'; -import { useITStorage, useQueryParam } from '@/composable/queryParams'; +import { useITStorage, useQueryParam, useQueryParamOrStorage } from '@/composable/queryParams'; const { t } = useI18n(); const encodeUrlSafe = useITStorage('base64-string-converter:encode-url-safe', false); const decodeUrlSafe = useITStorage('base64-string-converter:decode-url-safe', false); +const encoding = useQueryParamOrStorage({ + storageName: 'base64-string-converter:encoding', + name: 'encoding', + defaultValue: 'utf8', +}); + const textInput = useQueryParam({ tool: 'base64-string-converter', name: 'text', defaultValue: '' }); -const base64Output = computed(() => textToBase64(textInput.value, { makeUrlSafe: encodeUrlSafe.value })); -const { copy: copyTextBase64 } = useCopy({ source: base64Output, text: t('tools.base64-string-converter.texts.text-base64-string-copied-to-the-clipboard') }); +const base64Output = computed(() => + textToBase64(textInput.value, { makeUrlSafe: encodeUrlSafe.value, encoding: encoding.value }), +); +const { copy: copyTextBase64 } = useCopy({ + source: base64Output, + text: t('tools.base64-string-converter.texts.text-base64-string-copied-to-the-clipboard'), +}); const base64Input = useQueryParam({ tool: 'base64-string-converter', name: 'base64', defaultValue: '' }); const textOutput = computed(() => - withDefaultOnError(() => base64ToText(base64Input.value.trim(), { makeUrlSafe: decodeUrlSafe.value }), ''), + withDefaultOnError( + () => base64ToText(base64Input.value.trim(), { makeUrlSafe: decodeUrlSafe.value, encoding: encoding.value }), + '', + ), ); -const { copy: copyText } = useCopy({ source: textOutput, text: t('tools.base64-string-converter.texts.text-string-copied-to-the-clipboard') }); +const { copy: copyText } = useCopy({ + source: textOutput, + text: t('tools.base64-string-converter.texts.text-string-copied-to-the-clipboard'), +}); const b64ValidationRules = [ { message: t('tools.base64-string-converter.texts.message-invalid-base64-string'), @@ -26,13 +43,81 @@ const b64ValidationRules = [ }, ]; const b64ValidationWatch = [decodeUrlSafe]; + +const encodings = [ + { label: 'UTF-8', value: 'utf8' }, + { label: 'UTF-8 (Alias: UTF8)', value: 'utf-8' }, + + { label: 'UTF-16LE', value: 'utf16le' }, + { label: 'UTF-16BE', value: 'utf16be' }, + + { label: 'UTF-7', value: 'utf7' }, + { label: 'UTF-7 (IMAP)', value: 'utf7imap' }, + + { label: 'UTF-32LE', value: 'utf32le' }, + { label: 'UTF-32BE', value: 'utf32be' }, + + { label: 'ISO-8859-1 (Latin-1)', value: 'latin1' }, + { label: 'ISO-8859-2 (Central European)', value: 'iso-8859-2' }, + { label: 'ISO-8859-3 (South European)', value: 'iso-8859-3' }, + { label: 'ISO-8859-4 (North European)', value: 'iso-8859-4' }, + { label: 'ISO-8859-5 (Cyrillic)', value: 'iso-8859-5' }, + { label: 'ISO-8859-6 (Arabic)', value: 'iso-8859-6' }, + { label: 'ISO-8859-7 (Greek)', value: 'iso-8859-7' }, + { label: 'ISO-8859-8 (Hebrew)', value: 'iso-8859-8' }, + { label: 'ISO-8859-9 (Turkish)', value: 'iso-8859-9' }, + { label: 'ISO-8859-10 (Nordic)', value: 'iso-8859-10' }, + { label: 'ISO-8859-13 (Baltic)', value: 'iso-8859-13' }, + { label: 'ISO-8859-14 (Celtic)', value: 'iso-8859-14' }, + { label: 'ISO-8859-15 (Latin-9)', value: 'iso-8859-15' }, + { label: 'ISO-8859-16 (Romanian)', value: 'iso-8859-16' }, + + { label: 'Windows-1250 (Central European)', value: 'win1250' }, + { label: 'Windows-1251 (Cyrillic)', value: 'win1251' }, + { label: 'Windows-1252 (Western European)', value: 'win1252' }, + { label: 'Windows-1253 (Greek)', value: 'win1253' }, + { label: 'Windows-1254 (Turkish)', value: 'win1254' }, + { label: 'Windows-1255 (Hebrew)', value: 'win1255' }, + { label: 'Windows-1256 (Arabic)', value: 'win1256' }, + { label: 'Windows-1257 (Baltic)', value: 'win1257' }, + { label: 'Windows-1258 (Vietnamese)', value: 'win1258' }, + + { label: 'KOI8-R (Russian)', value: 'koi8-r' }, + { label: 'KOI8-U (Ukrainian)', value: 'koi8-u' }, + + { label: 'GBK (Simplified Chinese)', value: 'gbk' }, + { label: 'GB2312 (Simplified Chinese)', value: 'gb2312' }, + { label: 'GB18030 (Simplified Chinese)', value: 'gb18030' }, + + { label: 'Big5 (Traditional Chinese)', value: 'big5' }, + + { label: 'Shift-JIS (Japanese)', value: 'shift_jis' }, + { label: 'EUC-JP (Japanese)', value: 'euc-jp' }, + + { label: 'MacRoman', value: 'macroman' }, + { label: 'MacGreek', value: 'macgreek' }, + { label: 'MacTurkish', value: 'macturkish' }, + { label: 'MacCyrillic', value: 'maccyrillic' }, + { label: 'MacCentralEurope', value: 'maccentraleurope' }, + { label: 'MacIceland', value: 'maciceland' }, +];