Compare commits

..
Author SHA1 Message Date
sharevb 1fe196ff13 feat(new tool): Base64 Hex Converter
Fix #1505
2025-03-16 22:08:23 +01:00
8 changed files with 1132 additions and 1487 deletions

No files matched your search

+3 -4
View File
@@ -15,6 +15,7 @@ declare module '@vue/runtime-core' {
AsciiTextDrawer: typeof import('./src/tools/ascii-text-drawer/ascii-text-drawer.vue')['default']
'Base.layout': typeof import('./src/layouts/base.layout.vue')['default']
Base64FileConverter: typeof import('./src/tools/base64-file-converter/base64-file-converter.vue')['default']
Base64HexConverter: typeof import('./src/tools/base64-hex-converter/base64-hex-converter.vue')['default']
Base64StringConverter: typeof import('./src/tools/base64-string-converter/base64-string-converter.vue')['default']
BasicAuthGenerator: typeof import('./src/tools/basic-auth-generator/basic-auth-generator.vue')['default']
Bcrypt: typeof import('./src/tools/bcrypt/bcrypt.vue')['default']
@@ -82,7 +83,6 @@ declare module '@vue/runtime-core' {
FormatTransformer: typeof import('./src/components/FormatTransformer.vue')['default']
GitMemo: typeof import('./src/tools/git-memo/git-memo.vue')['default']
'GitMemo.content': typeof import('./src/tools/git-memo/git-memo.content.md')['default']
GptTokenEstimator: typeof import('./src/tools/gpt-token-estimator/gpt-token-estimator.vue')['default']
HashText: typeof import('./src/tools/hash-text/hash-text.vue')['default']
HmacGenerator: typeof import('./src/tools/hmac-generator/hmac-generator.vue')['default']
'Home.page': typeof import('./src/pages/Home.page.vue')['default']
@@ -132,19 +132,18 @@ declare module '@vue/runtime-core' {
MimeTypes: typeof import('./src/tools/mime-types/mime-types.vue')['default']
NavbarButtons: typeof import('./src/components/NavbarButtons.vue')['default']
NCheckbox: typeof import('naive-ui')['NCheckbox']
NCode: typeof import('naive-ui')['NCode']
NCollapseTransition: typeof import('naive-ui')['NCollapseTransition']
NConfigProvider: typeof import('naive-ui')['NConfigProvider']
NDivider: typeof import('naive-ui')['NDivider']
NEllipsis: typeof import('naive-ui')['NEllipsis']
NFormItem: typeof import('naive-ui')['NFormItem']
NH1: typeof import('naive-ui')['NH1']
NH3: typeof import('naive-ui')['NH3']
NIcon: typeof import('naive-ui')['NIcon']
NLayout: typeof import('naive-ui')['NLayout']
NLayoutSider: typeof import('naive-ui')['NLayoutSider']
NMenu: typeof import('naive-ui')['NMenu']
NScrollbar: typeof import('naive-ui')['NScrollbar']
NSpace: typeof import('naive-ui')['NSpace']
NTable: typeof import('naive-ui')['NTable']
NumeronymGenerator: typeof import('./src/tools/numeronym-generator/numeronym-generator.vue')['default']
OtpCodeGeneratorAndValidator: typeof import('./src/tools/otp-code-generator-and-validator/otp-code-generator-and-validator.vue')['default']
PasswordStrengthAnalyser: typeof import('./src/tools/password-strength-analyser/password-strength-analyser.vue')['default']
+2 -1
View File
@@ -46,6 +46,7 @@
"@tiptap/starter-kit": "2.1.6",
"@tiptap/vue-3": "2.0.3",
"@types/figlet": "^1.5.8",
"@types/hex-array": "^1.0.2",
"@types/markdown-it": "^13.0.7",
"@vicons/material": "^0.12.0",
"@vicons/tabler": "^0.12.0",
@@ -67,7 +68,7 @@
"figlet": "^1.7.0",
"figue": "^1.2.0",
"fuse.js": "^6.6.2",
"gpt-tokens": "^1.3.13",
"hex-array": "^1.0.0",
"highlight.js": "^11.7.0",
"iarna-toml-esm": "^3.0.5",
"ibantools": "^4.3.3",
+1001 -1298
View File
File diff suppressed because it is too large. Load diff
@@ -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>
+12
View File
@@ -0,0 +1,12 @@
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'),
});
@@ -1,170 +0,0 @@
<script setup lang="ts">
import { GPTTokens } from 'gpt-tokens';
import JSON5 from 'json5';
import type { supportModelType } from 'gpt-tokens';
import TextareaCopyable from '@/components/TextareaCopyable.vue';
import { useValidation } from '@/composable/validation';
import { useQueryParamOrStorage } from '@/composable/queryParams';
const models = GPTTokens.supportModels;
const model = useQueryParamOrStorage({ name: 'model', storageName: 'gpt-counter:model', defaultValue: 'gpt-3.5-turbo-1106' });
const systemPrompt = ref('');
const userPrompt = ref('');
const isAdvancedMode = ref(false);
const messagesJsonArray = ref('');
const toolsJsonArray = ref('');
const messagesValidation = useValidation({
source: messagesJsonArray,
rules: [
{
message: 'Invalid "messages" array',
validator: value => value && JSON5.parse(value.trim()),
},
],
});
const toolsValidation = useValidation({
source: toolsJsonArray,
rules: [
{
message: 'Invalid "tools" array',
validator: value => value && JSON5.parse(value.trim()),
},
],
});
const outputTokenCosts = computed(() => {
try {
let messagesArray = [];
let toolsArray = [];
if (isAdvancedMode.value) {
messagesArray = messagesJsonArray.value ? JSON5.parse(messagesJsonArray.value.trim()) : [];
toolsArray = toolsJsonArray.value ? JSON5.parse(toolsJsonArray.value.trim()) : [];
}
else {
if (systemPrompt.value) {
messagesArray.push({ role: 'system', content: systemPrompt.value });
}
if (userPrompt.value) {
messagesArray.push({ role: 'user', content: userPrompt.value });
}
}
if (!messagesArray.length) {
return {
error: '',
usedTokens: '0',
usedUSD: '0',
promptUsedTokens: '0',
completionUsedTokens: '0',
};
}
const tokens = new GPTTokens({
model: model.value as supportModelType,
messages: messagesArray,
tools: toolsArray,
});
return {
error: '',
usedTokens: tokens.usedTokens.toString(),
usedUSD: tokens.usedUSD.toString(),
promptUsedTokens: tokens.promptUsedTokens.toString(),
completionUsedTokens: tokens.completionUsedTokens.toString(),
};
}
catch (e: any) {
return {
error: e.toString(),
usedTokens: '',
usedUSD: '',
promptUsedTokens: '',
completionUsedTokens: '',
};
}
});
</script>
<template>
<div>
<c-select
v-model:value="model"
label-position="left"
label="Model:"
:options="models"
placeholder="Select GPT model"
mb-2
/>
<div flex justify-center>
<n-form-item label="Advanded JSON Mode" label-placement="left">
<n-checkbox v-model:checked="isAdvancedMode" mr-2 />
</n-form-item>
</div>
<c-card v-if="isAdvancedMode" title="Prompts">
<c-input-text
v-model:value="messagesJsonArray"
multiline raw-text
placeholder="Your 'messages' JSON array..."
rows="5"
autofocus
label="Your 'messages' JSON array:"
:validation="messagesValidation"
/>
<c-input-text
v-model:value="toolsJsonArray"
multiline raw-text
placeholder="Your 'tools' JSON array..."
rows="5"
autofocus
label="Your 'tools' JSON array:"
:validation="toolsValidation"
/>
</c-card>
<c-card v-else title="Input JSON(s)">
<c-input-text
v-model:value="systemPrompt"
multiline raw-text
placeholder="Your System Prompt content..."
rows="2"
autofocus
label="Your System Prompt content:"
/>
<c-input-text
v-model:value="userPrompt"
multiline raw-text
placeholder="Your User Prompt content..."
rows="6"
autofocus
label="Your User Prompt content:"
/>
</c-card>
<n-divider />
<c-alert v-if="outputTokenCosts.error">
{{ outputTokenCosts.error }}
</c-alert>
<div v-if="!outputTokenCosts.error">
<n-form-item label="Used Tokens:">
<TextareaCopyable :value="outputTokenCosts.usedTokens" />
</n-form-item>
<n-form-item label="Prompt Tokens:">
<TextareaCopyable :value="outputTokenCosts.promptUsedTokens" />
</n-form-item>
<n-form-item label="Completion Tokens:">
<TextareaCopyable :value="outputTokenCosts.completionUsedTokens" />
</n-form-item>
<n-form-item label="Used USD:">
<TextareaCopyable :value="outputTokenCosts.usedUSD" />
</n-form-item>
</div>
</div>
</template>
-12
View File
@@ -1,12 +0,0 @@
import { CurrencyDollar } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'GPT Token Estimator',
path: '/gpt-token-estimator',
description: 'OpenAI GPT Token Estimator',
keywords: ['gpt', 'token', 'estimator'],
component: () => import('./gpt-token-estimator.vue'),
icon: CurrencyDollar,
createdAt: new Date('2024-08-15'),
});
+2 -2
View File
@@ -2,7 +2,7 @@ import { tool as base64FileConverter } from './base64-file-converter';
import { tool as base64StringConverter } from './base64-string-converter';
import { tool as basicAuthGenerator } from './basic-auth-generator';
import { tool as emailNormalizer } from './email-normalizer';
import { tool as gptTokenEstimator } from './gpt-token-estimator';
import { tool as base64HexConverter } from './base64-hex-converter';
import { tool as asciiTextDrawer } from './ascii-text-drawer';
@@ -102,6 +102,7 @@ export const toolsByCategory: ToolCategory[] = [
romanNumeralConverter,
base64StringConverter,
base64FileConverter,
base64HexConverter,
colorConverter,
caseConverter,
textToNatoAlphabet,
@@ -161,7 +162,6 @@ export const toolsByCategory: ToolCategory[] = [
emailNormalizer,
regexTester,
regexMemo,
gptTokenEstimator,
],
},
{