mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-24 14:50:17 +03:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
71faa2bb0c |
No files matched your search
@@ -286,9 +286,6 @@
|
||||
"watchTriggerable": true,
|
||||
"watchWithFilter": true,
|
||||
"whenever": true,
|
||||
"toValue": true,
|
||||
"injectLocal": true,
|
||||
"provideLocal": true,
|
||||
"useClipboardItems": true
|
||||
"toValue": true
|
||||
}
|
||||
}
|
||||
Vendored
-9
@@ -36,7 +36,6 @@ declare global {
|
||||
const h: typeof import('vue')['h']
|
||||
const ignorableWatch: typeof import('@vueuse/core')['ignorableWatch']
|
||||
const inject: typeof import('vue')['inject']
|
||||
const injectLocal: typeof import('@vueuse/core')['injectLocal']
|
||||
const isDefined: typeof import('@vueuse/core')['isDefined']
|
||||
const isProxy: typeof import('vue')['isProxy']
|
||||
const isReactive: typeof import('vue')['isReactive']
|
||||
@@ -66,7 +65,6 @@ declare global {
|
||||
const onUpdated: typeof import('vue')['onUpdated']
|
||||
const pausableWatch: typeof import('@vueuse/core')['pausableWatch']
|
||||
const provide: typeof import('vue')['provide']
|
||||
const provideLocal: typeof import('@vueuse/core')['provideLocal']
|
||||
const reactify: typeof import('@vueuse/core')['reactify']
|
||||
const reactifyObject: typeof import('@vueuse/core')['reactifyObject']
|
||||
const reactive: typeof import('vue')['reactive']
|
||||
@@ -130,7 +128,6 @@ declare global {
|
||||
const useBrowserLocation: typeof import('@vueuse/core')['useBrowserLocation']
|
||||
const useCached: typeof import('@vueuse/core')['useCached']
|
||||
const useClipboard: typeof import('@vueuse/core')['useClipboard']
|
||||
const useClipboardItems: typeof import('@vueuse/core')['useClipboardItems']
|
||||
const useCloned: typeof import('@vueuse/core')['useCloned']
|
||||
const useColorMode: typeof import('@vueuse/core')['useColorMode']
|
||||
const useConfirmDialog: typeof import('@vueuse/core')['useConfirmDialog']
|
||||
@@ -329,7 +326,6 @@ declare module 'vue' {
|
||||
readonly h: UnwrapRef<typeof import('vue')['h']>
|
||||
readonly ignorableWatch: UnwrapRef<typeof import('@vueuse/core')['ignorableWatch']>
|
||||
readonly inject: UnwrapRef<typeof import('vue')['inject']>
|
||||
readonly injectLocal: UnwrapRef<typeof import('@vueuse/core')['injectLocal']>
|
||||
readonly isDefined: UnwrapRef<typeof import('@vueuse/core')['isDefined']>
|
||||
readonly isProxy: UnwrapRef<typeof import('vue')['isProxy']>
|
||||
readonly isReactive: UnwrapRef<typeof import('vue')['isReactive']>
|
||||
@@ -359,7 +355,6 @@ declare module 'vue' {
|
||||
readonly onUpdated: UnwrapRef<typeof import('vue')['onUpdated']>
|
||||
readonly pausableWatch: UnwrapRef<typeof import('@vueuse/core')['pausableWatch']>
|
||||
readonly provide: UnwrapRef<typeof import('vue')['provide']>
|
||||
readonly provideLocal: UnwrapRef<typeof import('@vueuse/core')['provideLocal']>
|
||||
readonly reactify: UnwrapRef<typeof import('@vueuse/core')['reactify']>
|
||||
readonly reactifyObject: UnwrapRef<typeof import('@vueuse/core')['reactifyObject']>
|
||||
readonly reactive: UnwrapRef<typeof import('vue')['reactive']>
|
||||
@@ -423,7 +418,6 @@ declare module 'vue' {
|
||||
readonly useBrowserLocation: UnwrapRef<typeof import('@vueuse/core')['useBrowserLocation']>
|
||||
readonly useCached: UnwrapRef<typeof import('@vueuse/core')['useCached']>
|
||||
readonly useClipboard: UnwrapRef<typeof import('@vueuse/core')['useClipboard']>
|
||||
readonly useClipboardItems: UnwrapRef<typeof import('@vueuse/core')['useClipboardItems']>
|
||||
readonly useCloned: UnwrapRef<typeof import('@vueuse/core')['useCloned']>
|
||||
readonly useColorMode: UnwrapRef<typeof import('@vueuse/core')['useColorMode']>
|
||||
readonly useConfirmDialog: UnwrapRef<typeof import('@vueuse/core')['useConfirmDialog']>
|
||||
@@ -616,7 +610,6 @@ declare module '@vue/runtime-core' {
|
||||
readonly h: UnwrapRef<typeof import('vue')['h']>
|
||||
readonly ignorableWatch: UnwrapRef<typeof import('@vueuse/core')['ignorableWatch']>
|
||||
readonly inject: UnwrapRef<typeof import('vue')['inject']>
|
||||
readonly injectLocal: UnwrapRef<typeof import('@vueuse/core')['injectLocal']>
|
||||
readonly isDefined: UnwrapRef<typeof import('@vueuse/core')['isDefined']>
|
||||
readonly isProxy: UnwrapRef<typeof import('vue')['isProxy']>
|
||||
readonly isReactive: UnwrapRef<typeof import('vue')['isReactive']>
|
||||
@@ -646,7 +639,6 @@ declare module '@vue/runtime-core' {
|
||||
readonly onUpdated: UnwrapRef<typeof import('vue')['onUpdated']>
|
||||
readonly pausableWatch: UnwrapRef<typeof import('@vueuse/core')['pausableWatch']>
|
||||
readonly provide: UnwrapRef<typeof import('vue')['provide']>
|
||||
readonly provideLocal: UnwrapRef<typeof import('@vueuse/core')['provideLocal']>
|
||||
readonly reactify: UnwrapRef<typeof import('@vueuse/core')['reactify']>
|
||||
readonly reactifyObject: UnwrapRef<typeof import('@vueuse/core')['reactifyObject']>
|
||||
readonly reactive: UnwrapRef<typeof import('vue')['reactive']>
|
||||
@@ -710,7 +702,6 @@ declare module '@vue/runtime-core' {
|
||||
readonly useBrowserLocation: UnwrapRef<typeof import('@vueuse/core')['useBrowserLocation']>
|
||||
readonly useCached: UnwrapRef<typeof import('@vueuse/core')['useCached']>
|
||||
readonly useClipboard: UnwrapRef<typeof import('@vueuse/core')['useClipboard']>
|
||||
readonly useClipboardItems: UnwrapRef<typeof import('@vueuse/core')['useClipboardItems']>
|
||||
readonly useCloned: UnwrapRef<typeof import('@vueuse/core')['useCloned']>
|
||||
readonly useColorMode: UnwrapRef<typeof import('@vueuse/core')['useColorMode']>
|
||||
readonly useConfirmDialog: UnwrapRef<typeof import('@vueuse/core')['useConfirmDialog']>
|
||||
|
||||
Vendored
+4
-7
@@ -23,7 +23,6 @@ declare module '@vue/runtime-core' {
|
||||
CAlert: typeof import('./src/ui/c-alert/c-alert.vue')['default']
|
||||
'CAlert.demo': typeof import('./src/ui/c-alert/c-alert.demo.vue')['default']
|
||||
CameraRecorder: typeof import('./src/tools/camera-recorder/camera-recorder.vue')['default']
|
||||
CardPicker: typeof import('./src/tools/card-picker/card-picker.vue')['default']
|
||||
CaseConverter: typeof import('./src/tools/case-converter/case-converter.vue')['default']
|
||||
CButton: typeof import('./src/ui/c-button/c-button.vue')['default']
|
||||
'CButton.demo': typeof import('./src/ui/c-button/c-button.demo.vue')['default']
|
||||
@@ -51,7 +50,6 @@ declare module '@vue/runtime-core' {
|
||||
'CModal.demo': typeof import('./src/ui/c-modal/c-modal.demo.vue')['default']
|
||||
CModalValue: typeof import('./src/ui/c-modal-value/c-modal-value.vue')['default']
|
||||
'CModalValue.demo': typeof import('./src/ui/c-modal-value/c-modal-value.demo.vue')['default']
|
||||
CoinFlipper: typeof import('./src/tools/coin-flipper/coin-flipper.vue')['default']
|
||||
CollapsibleToolMenu: typeof import('./src/components/CollapsibleToolMenu.vue')['default']
|
||||
ColorConverter: typeof import('./src/tools/color-converter/color-converter.vue')['default']
|
||||
ColoredCard: typeof import('./src/components/ColoredCard.vue')['default']
|
||||
@@ -70,7 +68,6 @@ declare module '@vue/runtime-core' {
|
||||
'DemoHome.page': typeof import('./src/ui/demo/demo-home.page.vue')['default']
|
||||
DemoWrapper: typeof import('./src/ui/demo/demo-wrapper.vue')['default']
|
||||
DeviceInformation: typeof import('./src/tools/device-information/device-information.vue')['default']
|
||||
DiceRoller: typeof import('./src/tools/dice-roller/dice-roller.vue')['default']
|
||||
DiffViewer: typeof import('./src/tools/json-diff/diff-viewer/diff-viewer.vue')['default']
|
||||
DockerRunToDockerComposeConverter: typeof import('./src/tools/docker-run-to-docker-compose-converter/docker-run-to-docker-compose-converter.vue')['default']
|
||||
DynamicValues: typeof import('./src/tools/benchmark-builder/dynamic-values.vue')['default']
|
||||
@@ -83,10 +80,10 @@ declare module '@vue/runtime-core' {
|
||||
EtaCalculator: typeof import('./src/tools/eta-calculator/eta-calculator.vue')['default']
|
||||
FavoriteButton: typeof import('./src/components/FavoriteButton.vue')['default']
|
||||
FormatTransformer: typeof import('./src/components/FormatTransformer.vue')['default']
|
||||
FortuneWheel: typeof import('./src/tools/fortune-wheel/fortune-wheel.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']
|
||||
HashText: typeof import('./src/tools/hash-text/hash-text.vue')['default']
|
||||
HexConverter: typeof import('./src/tools/hex-converter/hex-converter.vue')['default']
|
||||
HmacGenerator: typeof import('./src/tools/hmac-generator/hmac-generator.vue')['default']
|
||||
'Home.page': typeof import('./src/pages/Home.page.vue')['default']
|
||||
HtmlEntities: typeof import('./src/tools/html-entities/html-entities.vue')['default']
|
||||
@@ -133,13 +130,11 @@ declare module '@vue/runtime-core' {
|
||||
MenuLayout: typeof import('./src/components/MenuLayout.vue')['default']
|
||||
MetaTagGenerator: typeof import('./src/tools/meta-tag-generator/meta-tag-generator.vue')['default']
|
||||
MimeTypes: typeof import('./src/tools/mime-types/mime-types.vue')['default']
|
||||
NA: typeof import('naive-ui')['NA']
|
||||
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']
|
||||
@@ -150,9 +145,11 @@ declare module '@vue/runtime-core' {
|
||||
NLayoutSider: typeof import('naive-ui')['NLayoutSider']
|
||||
NMenu: typeof import('naive-ui')['NMenu']
|
||||
NP: typeof import('naive-ui')['NP']
|
||||
NRadio: typeof import('naive-ui')['NRadio']
|
||||
NRadioGroup: typeof import('naive-ui')['NRadioGroup']
|
||||
NScrollbar: typeof import('naive-ui')['NScrollbar']
|
||||
NSpace: typeof import('naive-ui')['NSpace']
|
||||
NTable: typeof import('naive-ui')['NTable']
|
||||
NSwitch: typeof import('naive-ui')['NSwitch']
|
||||
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']
|
||||
|
||||
+3
-3
@@ -37,7 +37,6 @@
|
||||
"release": "node ./scripts/release.mjs"
|
||||
},
|
||||
"dependencies": {
|
||||
"@dice-roller/rpg-dice-roller": "^5.5.1",
|
||||
"@it-tools/bip39": "^0.0.4",
|
||||
"@it-tools/oggen": "^1.3.0",
|
||||
"@regexper/render": "^1.0.0",
|
||||
@@ -53,8 +52,8 @@
|
||||
"@vueuse/core": "^10.3.0",
|
||||
"@vueuse/head": "^1.0.0",
|
||||
"@vueuse/router": "^10.0.0",
|
||||
"@younestouati/playing-cards-standard-deck": "^6.0.1",
|
||||
"bcryptjs": "^2.4.3",
|
||||
"byte-data": "^19.0.1",
|
||||
"change-case": "^4.1.2",
|
||||
"colord": "^2.9.3",
|
||||
"composerize-ts": "^0.6.2",
|
||||
@@ -69,6 +68,7 @@
|
||||
"figlet": "^1.7.0",
|
||||
"figue": "^1.2.0",
|
||||
"fuse.js": "^6.6.2",
|
||||
"hex-array": "^1.0.0",
|
||||
"highlight.js": "^11.7.0",
|
||||
"iarna-toml-esm": "^3.0.5",
|
||||
"ibantools": "^4.3.3",
|
||||
@@ -102,7 +102,6 @@
|
||||
"vue-router": "^4.1.6",
|
||||
"vue-shadow-dom": "^4.2.0",
|
||||
"vue-tsc": "^1.8.1",
|
||||
"vue3-fortune-wheel": "^2.0.5",
|
||||
"vuedraggable": "^4.1.0",
|
||||
"xml-formatter": "^3.3.2",
|
||||
"xml-js": "^1.6.11",
|
||||
@@ -118,6 +117,7 @@
|
||||
"@types/bcryptjs": "^2.4.2",
|
||||
"@types/crypto-js": "^4.1.1",
|
||||
"@types/dompurify": "^3.0.5",
|
||||
"@types/hex-array": "^1.0.2",
|
||||
"@types/jsdom": "^21.0.0",
|
||||
"@types/lodash": "^4.14.192",
|
||||
"@types/mime-types": "^2.1.1",
|
||||
|
||||
Generated
+2214
-2782
File diff suppressed because it is too large.
Load diff
Binary file not shown.
|
Before Width: | Height: | Size: 26 KiB |
@@ -1,63 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import cards from '@younestouati/playing-cards-standard-deck';
|
||||
import { computedRefreshable } from '@/composable/computedRefreshable';
|
||||
import { useCopy } from '@/composable/copy';
|
||||
import { useQueryParamOrStorage } from '@/composable/queryParams';
|
||||
import { randIntFromInterval } from '@/utils/random';
|
||||
|
||||
const cardKeys = Object.keys(cards);
|
||||
type CardNames = keyof typeof cards;
|
||||
|
||||
const numberOfCards = useQueryParamOrStorage({ name: 'cards', storageName: 'card-picker:n', defaultValue: 5 });
|
||||
const [cardPicked, refreshCardPicked] = computedRefreshable(() =>
|
||||
Array.from({ length: numberOfCards.value },
|
||||
() => cardKeys[randIntFromInterval(0, 51)]));
|
||||
|
||||
const suitNames = {
|
||||
c: 'clubs (♣)',
|
||||
d: 'diamonds (♦)',
|
||||
h: 'hearts (♥)',
|
||||
s: 'spades (♠)',
|
||||
};
|
||||
const numberNames = {
|
||||
1: 'Ace',
|
||||
11: 'Jack',
|
||||
12: 'Queen',
|
||||
13: 'King',
|
||||
};
|
||||
function translateName(cardId: string) {
|
||||
const [, number, suit] = /(\d+)([cdhs])/.exec(cardId) || [];
|
||||
if (!number && !suit) {
|
||||
return cardId;
|
||||
}
|
||||
return `${numberNames[number as never] || number} of ${suitNames[suit as never] || suit}`;
|
||||
}
|
||||
|
||||
const cardPickedString = computed(() => cardPicked.value.map(translateName).join(', '));
|
||||
|
||||
const { copy } = useCopy({ source: cardPickedString, text: 'Cards Picked copied to the clipboard' });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<c-card>
|
||||
<div mb-2 flex justify-center>
|
||||
<img v-for="(card, index) in cardPicked" :key="index" style="width:90px" mr-1 :src="`data:image/svg+xml;base64,${cards[card as CardNames]}`">
|
||||
</div>
|
||||
<div mb-2>
|
||||
<textarea-copyable :value="cardPickedString" readonly mb-1 />
|
||||
</div>
|
||||
<div flex justify-center gap-3>
|
||||
<n-form-item label="Number of cards:" label-placement="left">
|
||||
<n-input-number v-model:value="numberOfCards" min="1" placeholder="Width of the text" />
|
||||
</n-form-item>
|
||||
</div>
|
||||
<div flex justify-center gap-3>
|
||||
<c-button @click="copy()">
|
||||
Copy deck
|
||||
</c-button>
|
||||
<c-button @click="refreshCardPicked">
|
||||
Refresh deck
|
||||
</c-button>
|
||||
</div>
|
||||
</c-card>
|
||||
</template>
|
||||
@@ -1,12 +0,0 @@
|
||||
import { PlayCard } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'Card Picker',
|
||||
path: '/card-picker',
|
||||
description: 'Generate a deck of playing cards',
|
||||
keywords: ['card', 'deck', 'picker'],
|
||||
component: () => import('./card-picker.vue'),
|
||||
icon: PlayCard,
|
||||
createdAt: new Date('2025-02-09'),
|
||||
});
|
||||
@@ -1,46 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import { computedRefreshable } from '@/composable/computedRefreshable';
|
||||
import { randIntFromInterval } from '@/utils/random';
|
||||
|
||||
const [coinFlip, refreshCoinFlip] = computedRefreshable(() => ({
|
||||
coin: randIntFromInterval(0, 10) % 2 === 0 ? 'Heads' : 'Tails',
|
||||
dt: Date.now(),
|
||||
}));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<Transition name="bounce" mode="out-in">
|
||||
<div :key="coinFlip.dt" flex items-center justify-center>
|
||||
<div flex items-center justify-center rounded-full outline style="width: 5em; height: 5em">
|
||||
{{ coinFlip.coin }}
|
||||
</div>
|
||||
</div>
|
||||
</Transition>
|
||||
<div mt-4 flex justify-center>
|
||||
<c-button @click="refreshCoinFlip">
|
||||
Re flip
|
||||
</c-button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.bounce-enter-active {
|
||||
animation: bounce-in 0.5s;
|
||||
}
|
||||
.bounce-leave-active {
|
||||
animation: bounce-in 0.5s reverse;
|
||||
}
|
||||
@keyframes bounce-in {
|
||||
0% {
|
||||
transform: scale(0);
|
||||
}
|
||||
50% {
|
||||
transform: scale(1.25);
|
||||
}
|
||||
100% {
|
||||
transform: scale(1);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,12 +0,0 @@
|
||||
import { Coin } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'Coin Flipper',
|
||||
path: '/coin-flipper',
|
||||
description: 'Flip a coin',
|
||||
keywords: ['coin', 'flipper'],
|
||||
component: () => import('./coin-flipper.vue'),
|
||||
icon: Coin,
|
||||
createdAt: new Date('2025-02-09'),
|
||||
});
|
||||
@@ -1,66 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import { DiceRoll } from '@dice-roller/rpg-dice-roller';
|
||||
import { computedRefreshable } from '@/composable/computedRefreshable';
|
||||
import { useCopy } from '@/composable/copy';
|
||||
import { useQueryParamOrStorage } from '@/composable/queryParams';
|
||||
|
||||
const dicesNotations = useQueryParamOrStorage({ name: 'dices', storageName: 'dice-roll:dices', defaultValue: '3d6' });
|
||||
const [diceRollResult, refreshDiceRollResult] = computedRefreshable(() => {
|
||||
try {
|
||||
return {
|
||||
error: '',
|
||||
roll: new DiceRoll(dicesNotations.value),
|
||||
};
|
||||
}
|
||||
catch (e: any) {
|
||||
return {
|
||||
error: e.toString(),
|
||||
roll: null,
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
const diceRollString = computed(() => diceRollResult.value.roll?.output || '');
|
||||
|
||||
const { copy } = useCopy({ source: diceRollString, text: 'Dice Roll copied to the clipboard' });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<c-card>
|
||||
<c-input-text
|
||||
v-model:value="dicesNotations"
|
||||
label="Dice Roll Notations:" label-position="left"
|
||||
placeholder="Dice configuration"
|
||||
mb-2
|
||||
/>
|
||||
<n-p mb-2>
|
||||
For more information about Dice Notation, see <n-a href="https://dice-roller.github.io/documentation/guide/notation/" target="_blank">
|
||||
here
|
||||
</n-a>
|
||||
</n-p>
|
||||
|
||||
<c-alert v-if="diceRollResult.error" mb-2>
|
||||
{{ diceRollResult.error }}
|
||||
</c-alert>
|
||||
|
||||
<c-card v-if="!diceRollResult.error" title="Roll Result" mb-2>
|
||||
<input-copyable :value="diceRollResult.roll?.output" readonly mb-1 />
|
||||
<input-copyable :value="diceRollResult.roll?.total" label="Total" readonly placeholder="Dice Roll total:" label-position="left" mb-1 />
|
||||
</c-card>
|
||||
|
||||
<div mb-2 flex justify-center gap-3>
|
||||
<c-button @click="copy()">
|
||||
Copy roll result
|
||||
</c-button>
|
||||
<c-button @click="refreshDiceRollResult">
|
||||
Refresh roll
|
||||
</c-button>
|
||||
</div>
|
||||
|
||||
<c-card v-if="!diceRollResult.error" title="Dice Notation Stats" mb-2>
|
||||
<input-copyable :value="diceRollResult.roll?.minTotal" readonly label="Min Total:" label-position="left" mb-1 />
|
||||
<input-copyable :value="diceRollResult.roll?.maxTotal" readonly label="Max Total:" label-position="left" mb-1 />
|
||||
<input-copyable :value="diceRollResult.roll?.averageTotal" readonly label="Avg Total:" label-position="left" mb-1 />
|
||||
</c-card>
|
||||
</c-card>
|
||||
</template>
|
||||
@@ -1,12 +0,0 @@
|
||||
import { Dice } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'Dice Roller',
|
||||
path: '/dice-roller',
|
||||
description: 'RPG Dice Roller using Dice Notation',
|
||||
keywords: ['dice', 'rng', 'rpg', 'roller'],
|
||||
component: () => import('./dice-roller.vue'),
|
||||
icon: Dice,
|
||||
createdAt: new Date('2025-02-09'),
|
||||
});
|
||||
@@ -1,11 +0,0 @@
|
||||
import { expect, test } from '@playwright/test';
|
||||
|
||||
test.describe('Tool - Fortune wheel', () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await page.goto('/fortune-wheel');
|
||||
});
|
||||
|
||||
test('Has correct title', async ({ page }) => {
|
||||
await expect(page).toHaveTitle('Fortune wheel - IT Tools');
|
||||
});
|
||||
});
|
||||
@@ -1,85 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import { FortuneWheel } from 'vue3-fortune-wheel';
|
||||
import type { Data, ImgParams } from 'vue3-fortune-wheel';
|
||||
import { useQueryParamOrStorage } from '@/composable/queryParams';
|
||||
import { computedRefreshable } from '@/composable/computedRefreshable';
|
||||
|
||||
const base = import.meta.env.BASE_URL;
|
||||
|
||||
const choices = useQueryParamOrStorage({ name: 'choices', storageName: 'fortune-wheel:chs', defaultValue: '' });
|
||||
const spinDuration = useQueryParamOrStorage({ name: 'duration', storageName: 'fortune-wheel:dur', defaultValue: 5 });
|
||||
|
||||
const colors = [
|
||||
{ bgColor: '#FF5733', color: '#FFFFFF' },
|
||||
{ bgColor: '#2E86C1', color: '#FFFFFF' },
|
||||
{ bgColor: '#28B463', color: '#FFFFFF' },
|
||||
{ bgColor: '#F1C40F', color: '#000000' },
|
||||
{ bgColor: '#8E44AD', color: '#FFFFFF' },
|
||||
{ bgColor: '#E74C3C', color: '#FFFFFF' },
|
||||
{ bgColor: '#1ABC9C', color: '#000000' },
|
||||
{ bgColor: '#34495E', color: '#FFFFFF' },
|
||||
{ bgColor: '#D35400', color: '#FFFFFF' },
|
||||
{ bgColor: '#2C3E50', color: '#FFFFFF' },
|
||||
];
|
||||
|
||||
const wheel = ref<InstanceType<typeof FortuneWheel> | null>(null);
|
||||
const data = computed(() => {
|
||||
return (choices.value || '').split('\n')
|
||||
.filter(s => s && s !== '')
|
||||
.map((choice, index) => ({ id: index + 1, value: choice, ...colors[index % colors.length] }));
|
||||
});
|
||||
|
||||
const logo: ImgParams = {
|
||||
src: `${base}logo.png`,
|
||||
width: 100,
|
||||
height: 100,
|
||||
};
|
||||
|
||||
const [randomGift, refreshGift] = computedRefreshable(() => {
|
||||
return Math.floor(Math.random() * data.value.length) + 1;
|
||||
});
|
||||
|
||||
const result = ref<Data>();
|
||||
function done(wheelResult: Data) {
|
||||
result.value = wheelResult;
|
||||
}
|
||||
|
||||
function restart() {
|
||||
refreshGift();
|
||||
wheel.value?.spin();
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<n-form-item label="Spin Duration (seconds):" label-placement="left">
|
||||
<n-input-number v-model:value="spinDuration" :min="1" />
|
||||
</n-form-item>
|
||||
|
||||
<c-input-text
|
||||
v-model:value="choices"
|
||||
label="Wheel choices (one per line):"
|
||||
placeholder="Wheel choices (one per line)"
|
||||
multiline
|
||||
rows="5"
|
||||
/>
|
||||
|
||||
<n-divider />
|
||||
|
||||
<FortuneWheel
|
||||
ref="wheel"
|
||||
v-model="randomGift"
|
||||
middle-circle
|
||||
:img-params="logo"
|
||||
:anim-duration="spinDuration * 1000"
|
||||
:data="data"
|
||||
@done="done"
|
||||
/>
|
||||
|
||||
<div flex justify-center>
|
||||
<c-button @click="restart()">
|
||||
Restart
|
||||
</c-button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -1,12 +0,0 @@
|
||||
import { ArrowsShuffle } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'Fortune wheel',
|
||||
path: '/fortune-wheel',
|
||||
description: '',
|
||||
keywords: ['fortune', 'wheel'],
|
||||
component: () => import('./fortune-wheel.vue'),
|
||||
icon: ArrowsShuffle,
|
||||
createdAt: new Date('2025-02-24'),
|
||||
});
|
||||
@@ -0,0 +1,250 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { cleanHex, decodeNumber, decodeStruct, encodeStruct, getCoderFromTypeName, parseNumber } from './hex-converter.service';
|
||||
|
||||
describe('cleanHex', () => {
|
||||
it('should remove 0x and \\x prefixes from a hex string', () => {
|
||||
expect(cleanHex('0x1234')).toBe('1234');
|
||||
expect(cleanHex('\\x1234')).toBe('1234');
|
||||
expect(cleanHex('1234')).toBe('1234');
|
||||
});
|
||||
});
|
||||
|
||||
describe('decodeNumber', () => {
|
||||
it('should convert a number to binary', () => {
|
||||
expect(decodeNumber(10, 8, 'bin')).toBe('00001010');
|
||||
});
|
||||
|
||||
it('should convert a number to hex', () => {
|
||||
expect(decodeNumber(10, 8, 'hex')).toBe('0a');
|
||||
});
|
||||
|
||||
it('should convert a number to character', () => {
|
||||
expect(decodeNumber(65, 8, 'char')).toBe('A');
|
||||
});
|
||||
|
||||
it('should return the number itself for decimal conversion', () => {
|
||||
expect(decodeNumber(10, 8, 'dec')).toBe(10);
|
||||
});
|
||||
});
|
||||
|
||||
describe('parseNumber', () => {
|
||||
it('should parse hexadecimal input correctly', () => {
|
||||
expect(parseNumber('0x1F')).toBe(31);
|
||||
});
|
||||
|
||||
it('should parse binary input correctly', () => {
|
||||
expect(parseNumber('0b1101')).toBe(13);
|
||||
});
|
||||
|
||||
it('should parse string input correctly into code points', () => {
|
||||
expect(parseNumber('abc')).toEqual([97, 98, 99]);
|
||||
});
|
||||
|
||||
it('should return number when input is already a number', () => {
|
||||
expect(parseNumber(42)).toBe(42);
|
||||
});
|
||||
|
||||
it('should return 0 for falsy input', () => {
|
||||
expect(parseNumber('')).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getCoderFromTypeName', () => {
|
||||
it('should return correct coder options for a basic integer type', () => {
|
||||
const result = getCoderFromTypeName('uint16');
|
||||
expect(result.type.bits).toBe(16);
|
||||
expect(result.type.signed).toBe(false);
|
||||
expect(result.size).toBe(1);
|
||||
});
|
||||
|
||||
it('should handle big-endian types correctly', () => {
|
||||
const result = getCoderFromTypeName('int32be');
|
||||
expect(result.type.bits).toBe(32);
|
||||
expect(result.type.be).toBe(true);
|
||||
});
|
||||
|
||||
it('should return correct coder options for a float type', () => {
|
||||
const result = getCoderFromTypeName('float');
|
||||
expect(result.type.bits).toBe(32);
|
||||
expect(result.type.fp).toBe(true);
|
||||
});
|
||||
|
||||
it('should return correct coder options for a character type', () => {
|
||||
const result = getCoderFromTypeName('char[4]');
|
||||
expect(result.type.bits).toBe(8);
|
||||
expect(result.size).toBe(4);
|
||||
expect(result.formatter(65, 8)).toBe('A');
|
||||
});
|
||||
});
|
||||
|
||||
describe('decodeStruct', () => {
|
||||
it('should decode a flat struct correctly from a hex array', () => {
|
||||
const struct = {
|
||||
field1: 'uint16',
|
||||
field2: 'char[3]',
|
||||
};
|
||||
const hexArray = new Uint8Array([0x01, 0x0, 0x61, 0x62, 0x63]);
|
||||
|
||||
const result = decodeStruct({ struct, hexArray });
|
||||
expect(result.field1).toBe(1);
|
||||
expect(result.field2).toBe('abc');
|
||||
});
|
||||
|
||||
it('should decode a nested struct correctly', () => {
|
||||
const struct = {
|
||||
type: 'int8',
|
||||
header: {
|
||||
version: 'uint8',
|
||||
type: 'uint16be',
|
||||
},
|
||||
payload: {
|
||||
value: 'floatbe',
|
||||
},
|
||||
};
|
||||
const hexArray = new Uint8Array([0xFF, 0x01, 0x00, 0x02, 0x3F, 0x80, 0x0, 0x0]); // float 1.0
|
||||
|
||||
const result = decodeStruct({ struct, hexArray });
|
||||
expect(result).toEqual({
|
||||
type: -1,
|
||||
header: { version: 1, type: 2 },
|
||||
payload: { value: 1.0 },
|
||||
});
|
||||
});
|
||||
|
||||
it('should throw on bad buffer length', () => {
|
||||
const struct = {
|
||||
type: 'int8',
|
||||
header: {
|
||||
version: 'uint8',
|
||||
type: 'uint16be',
|
||||
},
|
||||
payload: {
|
||||
value: 'floatbe',
|
||||
},
|
||||
};
|
||||
const hexArray = new Uint8Array([0xFF, 0x01, 0x00, 0x02, 0x3F, 0x80]); // missing last two bytes
|
||||
|
||||
expect(() => decodeStruct({ struct, hexArray })).toThrowError(
|
||||
'Bad buffer length reading value(floatbe) at offset 4',
|
||||
);
|
||||
});
|
||||
|
||||
it('should throw an error when decoding an unsupported array type', () => {
|
||||
const struct = {
|
||||
list: ['uint8'],
|
||||
};
|
||||
const hexArray = new Uint8Array([0x01, 0x02, 0x03]);
|
||||
|
||||
expect(() => decodeStruct({ struct, hexArray })).toThrowError(
|
||||
'Cannot decode a struct with array',
|
||||
);
|
||||
});
|
||||
it('should throw an error when decoding an unsized array type', () => {
|
||||
const struct = {
|
||||
list: 'uint8[]',
|
||||
};
|
||||
const hexArray = new Uint8Array([0x01, 0x02, 0x03]);
|
||||
|
||||
expect(() => decodeStruct({ struct, hexArray })).toThrowError(
|
||||
'Unsupported unsized array: uint8[]',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('encodeStruct', () => {
|
||||
it('should encode a flat struct correctly', () => {
|
||||
const struct = {
|
||||
field1: 'uint8',
|
||||
field2: 'char[3]',
|
||||
};
|
||||
const jsonObject = {
|
||||
field1: 1,
|
||||
field2: 'abc',
|
||||
};
|
||||
|
||||
const result = encodeStruct({ struct, jsonObject });
|
||||
expect(result).toEqual(new Uint8Array([0x01, 0x61, 0x62, 0x63]));
|
||||
});
|
||||
|
||||
it('should encode a nested struct correctly', () => {
|
||||
const struct = {
|
||||
type: 'int8',
|
||||
header: {
|
||||
version: 'uint8',
|
||||
type: 'uint16be',
|
||||
},
|
||||
payload: {
|
||||
value: 'floatbe',
|
||||
},
|
||||
};
|
||||
const jsonObject = {
|
||||
type: -1,
|
||||
header: { version: 1, type: 2 },
|
||||
payload: { value: 1.0 },
|
||||
};
|
||||
|
||||
const result = encodeStruct({ struct, jsonObject });
|
||||
expect(result).toEqual(new Uint8Array([0xFF, 0x01, 0x00, 0x02, 0x3F, 0x80, 0x0, 0x0]));
|
||||
});
|
||||
|
||||
it('should throw an error if array size is incorrect', () => {
|
||||
const struct = {
|
||||
field1: 'uint8',
|
||||
field2: 'char[3]',
|
||||
};
|
||||
const jsonObject = {
|
||||
field1: 1,
|
||||
field2: 'abcd', // Too long
|
||||
};
|
||||
|
||||
expect(() => encodeStruct({ struct, jsonObject })).toThrowError(
|
||||
'Unexpected array size \'field2\'=\'97,98,99,100\' expected 3 elements',
|
||||
);
|
||||
});
|
||||
|
||||
it('should throw an error if value type is incorrect', () => {
|
||||
const struct = {
|
||||
field1: 'uint8',
|
||||
field2: 'char[3]',
|
||||
};
|
||||
const jsonObject = {
|
||||
field1: 1,
|
||||
field2: 123, // Invalid type
|
||||
};
|
||||
|
||||
expect(() => encodeStruct({ struct, jsonObject })).toThrowError(
|
||||
'Unexpected non array \'field2\'=\'123\'',
|
||||
);
|
||||
});
|
||||
|
||||
it('should throw an error if value type is incorrect', () => {
|
||||
const struct = {
|
||||
field1: 'uint8',
|
||||
field2: 'int16',
|
||||
};
|
||||
const jsonObject = {
|
||||
field1: 1,
|
||||
field2: '123', // Invalid type
|
||||
};
|
||||
|
||||
expect(() => encodeStruct({ struct, jsonObject })).toThrowError(
|
||||
'Unexpected array size \'field2\'=\'49,50,51\' expected 1 elements',
|
||||
);
|
||||
});
|
||||
|
||||
it('should encode multiple integer types correctly', () => {
|
||||
const struct = {
|
||||
a: 'uint8',
|
||||
b: 'uint16',
|
||||
c: 'uint32',
|
||||
};
|
||||
const jsonObject = {
|
||||
a: 1,
|
||||
b: 513,
|
||||
c: 67305985,
|
||||
};
|
||||
|
||||
const result = encodeStruct({ struct, jsonObject });
|
||||
expect(result).toEqual(new Uint8Array([0x01, 0x01, 0x02, 0x01, 0x02, 0x03, 0x04]));
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,193 @@
|
||||
import { pack, unpack } from 'byte-data';
|
||||
|
||||
export type Conversion = 'dec' | 'bin' | 'hex' | 'char';
|
||||
|
||||
export function cleanHex(hex: string): string {
|
||||
return hex.replace(/\\x|0x/g, '');
|
||||
}
|
||||
|
||||
export function decodeNumber(n: number, bits: number, conv: Conversion) {
|
||||
if (conv === 'bin') {
|
||||
return n.toString(2).padStart(bits, '0');
|
||||
}
|
||||
if (conv === 'hex') {
|
||||
return n.toString(16).padStart(bits / 4, '0');
|
||||
}
|
||||
if (conv === 'char') {
|
||||
return String.fromCodePoint(n);
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
export function parseNumber(input: string | number): number | number[] {
|
||||
if (!input) {
|
||||
return 0;
|
||||
}
|
||||
if (typeof input === 'number') {
|
||||
return input;
|
||||
}
|
||||
|
||||
if (/^0x[0-9a-fA-F]+$/.test(input)) {
|
||||
return Number.parseInt(input.substring(2), 16); // Parse as hexadecimal
|
||||
}
|
||||
else if (/^0b[01]+$/.test(input)) {
|
||||
return Number.parseInt(input.substring(2), 2); // Parse as binary
|
||||
}
|
||||
|
||||
return [...input].map(c => c.codePointAt(0) || 0);
|
||||
}
|
||||
|
||||
function mergeModelAndObject(model: Record<string, any>, object: Record<string, any>): Record<string, any> {
|
||||
const merged: Record<string, any> = {};
|
||||
|
||||
for (const key in model) {
|
||||
if (Object.prototype.hasOwnProperty.call(model, key)) {
|
||||
if (Array.isArray(object[key])) {
|
||||
merged[key] = [model[key], object[key].map(parseNumber)];
|
||||
}
|
||||
else if (typeof object[key] === 'object' && !Array.isArray(object[key])) {
|
||||
merged[key] = mergeModelAndObject(model[key], object[key]);
|
||||
}
|
||||
else {
|
||||
merged[key] = [model[key], parseNumber(object[key])];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return merged;
|
||||
}
|
||||
|
||||
interface CoderOption {
|
||||
type: {
|
||||
bits: number
|
||||
fp?: boolean
|
||||
be?: boolean
|
||||
signed?: boolean
|
||||
}
|
||||
size: number
|
||||
formatter: (n: number, bits: number) => string | number
|
||||
join?: boolean
|
||||
};
|
||||
|
||||
export function getCoderFromTypeName(typeName: string): CoderOption {
|
||||
if (typeName.includes('[]')) {
|
||||
throw new Error(`Unsupported unsized array: ${typeName}`);
|
||||
}
|
||||
const [, prefix, baseTypeName, bigEndian, arraySize] = /^((?:0x|0b)?)(u?int\d+|w?char|half|float|double)(be)?(?:\[(\d+)\])?$/.exec(typeName) || [];
|
||||
let conv = 'dec';
|
||||
if (prefix === '0x') {
|
||||
conv = 'hex';
|
||||
}
|
||||
if (prefix === '0b') {
|
||||
conv = 'bin';
|
||||
}
|
||||
|
||||
const arraySizeNumber = Number.isNaN(Number(arraySize)) ? 1 : Number(arraySize);
|
||||
if (baseTypeName === 'char' || baseTypeName === 'wchar') {
|
||||
return {
|
||||
type: {
|
||||
bits: baseTypeName === 'char' ? 8 : 16,
|
||||
be: !!bigEndian,
|
||||
},
|
||||
size: arraySizeNumber,
|
||||
formatter: n => String.fromCodePoint(n),
|
||||
join: true,
|
||||
};
|
||||
}
|
||||
if (baseTypeName === 'float' || baseTypeName === 'double' || baseTypeName === 'half') {
|
||||
return {
|
||||
type: {
|
||||
bits: baseTypeName === 'float' ? 32 : (baseTypeName === 'double' ? 64 : 16),
|
||||
be: !!bigEndian,
|
||||
fp: true,
|
||||
},
|
||||
size: arraySizeNumber,
|
||||
formatter: n => n,
|
||||
};
|
||||
}
|
||||
|
||||
const [, unsigned, bits] = /^(u?)int(\d+)$/.exec(baseTypeName || '') || [];
|
||||
return {
|
||||
type: {
|
||||
bits: Number(bits),
|
||||
be: !!bigEndian,
|
||||
signed: !unsigned,
|
||||
},
|
||||
size: arraySizeNumber,
|
||||
formatter: (n, bits) => decodeNumber(n, bits, conv as Conversion),
|
||||
};
|
||||
}
|
||||
|
||||
export function decodeStruct({ struct, hexArray }: { struct: object; hexArray: Uint8Array }) {
|
||||
let offset = 0;
|
||||
const readMember = (obj: any) => {
|
||||
const result: Record<string, any> = {};
|
||||
|
||||
for (const key in obj) {
|
||||
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
||||
if (Array.isArray(obj[key])) {
|
||||
throw new TypeError(`Cannot decode a struct with array (key=${key}). Must be expressed as string with fixed length`);
|
||||
}
|
||||
else if (typeof obj[key] === 'object' && !Array.isArray(obj[key])) {
|
||||
result[key] = readMember(obj[key]);
|
||||
}
|
||||
else {
|
||||
const coderOption = getCoderFromTypeName(obj[key]);
|
||||
const arr = [];
|
||||
for (let i = 0; i < coderOption.size; i++) {
|
||||
const dataSize = Math.ceil(coderOption.type.bits / 8);
|
||||
if (offset + dataSize > hexArray.length) {
|
||||
throw new Error(`Bad buffer length reading ${key}(${obj[key]}) at offset ${offset}`);
|
||||
}
|
||||
arr.push(coderOption.formatter(unpack(hexArray, coderOption.type, offset), coderOption.type.bits));
|
||||
offset += dataSize;
|
||||
}
|
||||
if (coderOption.join) {
|
||||
result[key] = arr.join('');
|
||||
}
|
||||
else {
|
||||
result[key] = coderOption.size > 1 ? arr : arr[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
return readMember(struct);
|
||||
}
|
||||
|
||||
export function encodeStruct({ struct, jsonObject }: { struct: object; jsonObject: object }): Uint8Array {
|
||||
const mergedObject = mergeModelAndObject(struct, jsonObject);
|
||||
|
||||
let buffer: Array<number> = [];
|
||||
const writeMember = (obj: any) => {
|
||||
for (const key in obj) {
|
||||
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
||||
if (typeof obj[key] === 'object' && !Array.isArray(obj[key])) {
|
||||
writeMember(obj[key]);
|
||||
}
|
||||
else if (Array.isArray(obj[key])) {
|
||||
const [typeName, value] = obj[key];
|
||||
const coderOption = getCoderFromTypeName(typeName);
|
||||
if (coderOption.size > 1 && !Array.isArray(value)) {
|
||||
throw new TypeError(`Unexpected non array '${key}'='${value}'`);
|
||||
}
|
||||
if (Array.isArray(value) && value.length !== coderOption.size) {
|
||||
throw new TypeError(`Unexpected array size '${key}'='${value}' expected ${coderOption.size} elements`);
|
||||
}
|
||||
const valueArr = !Array.isArray(value) ? [value] : value;
|
||||
for (let i = 0; i < coderOption.size; i++) {
|
||||
buffer = [...buffer, ...pack(valueArr[i], coderOption.type)];
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new TypeError(`Unexpected '${key}'='${obj[key]}'`);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
writeMember(mergedObject);
|
||||
|
||||
return new Uint8Array(buffer);
|
||||
}
|
||||
@@ -0,0 +1,303 @@
|
||||
<script setup lang="ts">
|
||||
import hexArray from 'hex-array';
|
||||
import { packArray, packString, unpackArray, unpackString } from 'byte-data';
|
||||
import JSON5 from 'json5';
|
||||
import { type Conversion, cleanHex, decodeNumber, decodeStruct, encodeStruct } from './hex-converter.service';
|
||||
import { useValidation } from '@/composable/validation';
|
||||
|
||||
const mode = ref<'simple' | 'struct'>('simple');
|
||||
|
||||
const bits = ref(32);
|
||||
const floatingPoint = ref(false);
|
||||
const signed = ref(false);
|
||||
const bigEndian = ref(false);
|
||||
const decodeAs = ref<'dec' | 'bin' | 'hexa' | 'char' | 'utf8'>('dec');
|
||||
|
||||
const uppercase = ref(false);
|
||||
const grouping = ref(1);
|
||||
const rowlength = ref(0);
|
||||
|
||||
const hexInput = ref('');
|
||||
const decodedOutput = computed(() => {
|
||||
try {
|
||||
const buffer = hexArray.fromString(cleanHex(hexInput.value));
|
||||
if (decodeAs.value === 'utf8') {
|
||||
return unpackString(buffer);
|
||||
}
|
||||
else {
|
||||
return unpackArray(buffer, {
|
||||
bits: bits.value,
|
||||
fp: floatingPoint.value,
|
||||
signed: signed.value,
|
||||
be: bigEndian.value,
|
||||
}, 0, buffer.length, true).map(n => decodeNumber(n, bits.value, decodeAs.value as Conversion)).join(' ');
|
||||
}
|
||||
}
|
||||
catch (e: any) {
|
||||
return e.toString();
|
||||
}
|
||||
});
|
||||
const numberInput = ref('');
|
||||
const encodedOutput = computed(() => {
|
||||
try {
|
||||
const values = numberInput.value.split(/\s+/).map(Number);
|
||||
return hexArray.toString(
|
||||
new Uint8Array(
|
||||
packArray(values, {
|
||||
bits: bits.value,
|
||||
fp: floatingPoint.value,
|
||||
signed: signed.value,
|
||||
be: bigEndian.value,
|
||||
})),
|
||||
{
|
||||
uppercase: uppercase.value,
|
||||
grouping: grouping.value,
|
||||
rowlength: rowlength.value,
|
||||
},
|
||||
);
|
||||
}
|
||||
catch (e: any) {
|
||||
return e.toString();
|
||||
}
|
||||
});
|
||||
|
||||
const stringInput = ref('');
|
||||
const utf8Output = computed(() => {
|
||||
try {
|
||||
return hexArray.toString(
|
||||
new Uint8Array(packString(stringInput.value)),
|
||||
{
|
||||
uppercase: uppercase.value,
|
||||
grouping: grouping.value,
|
||||
rowlength: rowlength.value,
|
||||
},
|
||||
);
|
||||
}
|
||||
catch (e: any) {
|
||||
return e.toString();
|
||||
}
|
||||
});
|
||||
|
||||
const structDefinition = ref(`{
|
||||
x: "int32",
|
||||
y: "int32",
|
||||
}`);
|
||||
const structDefinitionValidation = useValidation({
|
||||
source: structDefinition,
|
||||
rules: [
|
||||
{
|
||||
message: 'Struct definition is not a valid JSON',
|
||||
validator: value => JSON5.parse(value.trim()),
|
||||
},
|
||||
],
|
||||
});
|
||||
const hexStructInput = ref('');
|
||||
const decodedStructOutput = computed(() => {
|
||||
try {
|
||||
return JSON.stringify(
|
||||
decodeStruct({
|
||||
struct: JSON5.parse(structDefinition.value),
|
||||
hexArray: hexArray.fromString(cleanHex(hexStructInput.value)),
|
||||
}),
|
||||
null, 2);
|
||||
}
|
||||
catch (e: any) {
|
||||
return e.toString();
|
||||
}
|
||||
});
|
||||
|
||||
const jsonStructInput = ref('');
|
||||
const encodedStructOutput = computed(() => {
|
||||
try {
|
||||
return hexArray.toString(
|
||||
encodeStruct({
|
||||
struct: JSON5.parse(structDefinition.value),
|
||||
jsonObject: JSON5.parse(jsonStructInput.value),
|
||||
}), {
|
||||
uppercase: uppercase.value,
|
||||
grouping: grouping.value,
|
||||
rowlength: rowlength.value,
|
||||
});
|
||||
}
|
||||
catch (e: any) {
|
||||
return e.toString();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<n-radio-group v-model:value="mode" name="radiogroup" mb-2 flex justify-center>
|
||||
<n-space>
|
||||
<n-radio
|
||||
value="simple"
|
||||
label="Simple Encoder/Decoder"
|
||||
/>
|
||||
<n-radio
|
||||
value="struct"
|
||||
label="C/C++ typed struct"
|
||||
/>
|
||||
</n-space>
|
||||
</n-radio-group>
|
||||
|
||||
<div v-if="mode === 'simple'">
|
||||
<c-card title="Hex Options" mb-1>
|
||||
<c-select
|
||||
v-model:value="decodeAs"
|
||||
label="Decode/Encode As:"
|
||||
label-position="left" mb-1
|
||||
:options="[{ value: 'dec', label: 'Decimal' }, { value: 'bin', label: 'Binary' }, { value: 'hex', label: 'Hexadecimal' }, { value: 'char', label: 'Char/ASCII' }, { value: 'utf8', label: 'UTF8 string' }]"
|
||||
/>
|
||||
<n-space v-if="decodeAs !== 'utf8'" align="baseline" justify="center">
|
||||
<n-form-item label="Bits:" label-placement="left">
|
||||
<n-input-number v-model:value="bits" :min="1" style="width: 6em" />
|
||||
</n-form-item>
|
||||
<n-form-item>
|
||||
<n-checkbox v-model:checked="floatingPoint">
|
||||
Floating Point
|
||||
</n-checkbox>
|
||||
</n-form-item>
|
||||
<n-form-item>
|
||||
<n-checkbox v-model:checked="signed">
|
||||
Signed
|
||||
</n-checkbox>
|
||||
</n-form-item>
|
||||
<n-form-item>
|
||||
<n-checkbox v-model:checked="bigEndian">
|
||||
Big Endian
|
||||
</n-checkbox>
|
||||
</n-form-item>
|
||||
</n-space>
|
||||
</c-card>
|
||||
<c-card title="Hex Data Decoder" mb-3>
|
||||
<c-input-text
|
||||
v-model:value="hexInput"
|
||||
multiline
|
||||
placeholder="Put your Hex data here..."
|
||||
rows="2"
|
||||
label="Hex Data to decode"
|
||||
raw-text
|
||||
mb-5
|
||||
/>
|
||||
|
||||
<n-form-item label="Your decoded values:">
|
||||
<textarea-copyable :value="decodedOutput" />
|
||||
</n-form-item>
|
||||
</c-card>
|
||||
<c-card v-if="decodeAs !== 'utf8'" title="Hex Data Encoder" mt-3>
|
||||
<c-input-text
|
||||
v-model:value="numberInput"
|
||||
multiline
|
||||
placeholder="Put your Numbers array here..."
|
||||
rows="2"
|
||||
label="Numbers array to encode"
|
||||
raw-text
|
||||
mb-5
|
||||
/>
|
||||
|
||||
<n-form-item label="Your encoded numbers array as Hex:">
|
||||
<textarea-copyable :value="encodedOutput" />
|
||||
</n-form-item>
|
||||
</c-card>
|
||||
<c-card v-if="decodeAs === 'utf8'" title="Hex UTF8 String Encoder" mt-3>
|
||||
<c-input-text
|
||||
v-model:value="stringInput"
|
||||
multiline
|
||||
placeholder="Put your text here..."
|
||||
rows="5"
|
||||
label="String to encode"
|
||||
raw-text
|
||||
mb-5
|
||||
/>
|
||||
|
||||
<n-form-item label="Your encoded string as UTF8 Hex:">
|
||||
<textarea-copyable :value="utf8Output" />
|
||||
</n-form-item>
|
||||
</c-card>
|
||||
<c-card title="Hex Encoding Output" mt-1>
|
||||
<n-space align="baseline" justify="center">
|
||||
<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-card>
|
||||
</div>
|
||||
|
||||
<div v-if="mode === 'struct'">
|
||||
<c-card title="Struct Definition">
|
||||
<c-input-text
|
||||
v-model:value="structDefinition"
|
||||
multiline
|
||||
placeholder="Put your Struct defintion here..."
|
||||
rows="5"
|
||||
label="C/C+ like struct definition"
|
||||
raw-text
|
||||
mb-5
|
||||
:validation="structDefinitionValidation"
|
||||
/>
|
||||
|
||||
<details>
|
||||
<summary>Instructions</summary>
|
||||
<n-p>
|
||||
Define you struct definition in JSON format: keys = struct member names ; value = type
|
||||
<br>
|
||||
Types syntax: u?int{size}(be)? | float(be)? | double(be)? | char | wchar(be)? | <type>[{array size}]
|
||||
<br>
|
||||
where "u" means "unsigned" ; "be" means "Big Endian" ; {size} is number of bits ; {array size} fixed size for arrays
|
||||
<br>
|
||||
can prefix integer with 0x or 0b to display as hex and binary
|
||||
</n-p>
|
||||
</details>
|
||||
</c-card>
|
||||
<c-card title="Hex Struct Decoder" m-t-1>
|
||||
<c-input-text
|
||||
v-model:value="hexStructInput"
|
||||
multiline
|
||||
placeholder="Put your Hex data here..."
|
||||
rows="5"
|
||||
label="Hex Data to decode"
|
||||
raw-text
|
||||
mb-5
|
||||
/>
|
||||
|
||||
<n-form-item label="Your decoded values:">
|
||||
<textarea-copyable :value="decodedStructOutput" />
|
||||
</n-form-item>
|
||||
</c-card>
|
||||
<c-card title="Hex Struct Encoder" m-t-1>
|
||||
<c-input-text
|
||||
v-model:value="jsonStructInput"
|
||||
multiline
|
||||
placeholder="Put your Struct to encode here..."
|
||||
rows="5"
|
||||
label="Struct json to encode"
|
||||
raw-text
|
||||
mb-5
|
||||
/>
|
||||
|
||||
<n-form-item label="Your encoded struct as Hex:">
|
||||
<textarea-copyable :value="encodedStructOutput" />
|
||||
</n-form-item>
|
||||
</c-card>
|
||||
<c-card title="Hex Encoding Output" mt-1>
|
||||
<n-space align="baseline" justify="center">
|
||||
<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-card>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Binary } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'Hex Encoder/Decoder',
|
||||
path: '/hex-converter',
|
||||
description: 'Encode and decode Hex buffers to number (bits, endianess, sign or floating point or chars) and structures',
|
||||
keywords: ['hex', 'encode', 'decode', 'endianess', 'float', 'bits', 'hex', 'struct'],
|
||||
component: () => import('./hex-converter.vue'),
|
||||
icon: Binary,
|
||||
createdAt: new Date('2025-02-09'),
|
||||
});
|
||||
+3
-13
@@ -2,10 +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 fortuneWheel } from './fortune-wheel';
|
||||
import { tool as cardPicker } from './card-picker';
|
||||
import { tool as coinFlipper } from './coin-flipper';
|
||||
import { tool as diceRoller } from './dice-roller';
|
||||
import { tool as hexConverter } from './hex-converter';
|
||||
|
||||
import { tool as asciiTextDrawer } from './ascii-text-drawer';
|
||||
|
||||
@@ -102,6 +99,7 @@ export const toolsByCategory: ToolCategory[] = [
|
||||
components: [
|
||||
dateTimeConverter,
|
||||
baseConverter,
|
||||
hexConverter,
|
||||
romanNumeralConverter,
|
||||
base64StringConverter,
|
||||
base64FileConverter,
|
||||
@@ -172,15 +170,7 @@ export const toolsByCategory: ToolCategory[] = [
|
||||
},
|
||||
{
|
||||
name: 'Math',
|
||||
components: [
|
||||
mathEvaluator,
|
||||
etaCalculator,
|
||||
percentageCalculator,
|
||||
diceRoller,
|
||||
coinFlipper,
|
||||
cardPicker,
|
||||
fortuneWheel,
|
||||
],
|
||||
components: [mathEvaluator, etaCalculator, percentageCalculator],
|
||||
},
|
||||
{
|
||||
name: 'Measurement',
|
||||
|
||||
Reference in new issue
Block a user