Compare commits

..
Author SHA1 Message Date
ShareVB 28472157e9 fix: update queryParams 2024-07-14 23:29:42 +02:00
ShareVB 6285453f6d Merge remote-tracking branch 'origin/main' into feat/crc-calculator 2024-07-14 23:29:27 +02:00
sharevb 76a19d218d fix(emoji-picker): debounced search input (#1181)
* fix(Emoji picker): fix lags

Fix #1176 using debounced ref

* chore: fix strange corepack message

Fix corepack claiming strange thing : UsageError: This project is configured to use yarn because /home/runner/work/it-tools/it-tools/package.json has a "packageManager" field
2024-07-11 17:06:17 +02:00
ShareVB fd6db9e305 chore: fix strange corepack message
Fix corepack claiming strange thing : UsageError: This project is configured to use yarn because /home/runner/work/it-tools/it-tools/package.json has a "packageManager" field
2024-06-09 14:10:34 +02:00
ShareVB b4f41994db chore: fix pnpm lock 2024-06-09 14:10:12 +02:00
sharevb a69e159986 Merge branch 'main' into feat/crc-calculator 2024-06-09 14:07:36 +02:00
ShareVB 3d91a295b9 Merge branch 'main' into feat/crc-calculator 2024-06-09 14:04:26 +02:00
sharevb e419ed38f4 feat(new tool): CRC calculator
Fix #815
2024-06-09 13:57:22 +02:00
12 changed files with 345 additions and 1849 deletions

No files matched your search

+6 -2
View File
@@ -55,6 +55,7 @@ declare module '@vue/runtime-core' {
ColoredCard: typeof import('./src/components/ColoredCard.vue')['default']
CommandPalette: typeof import('./src/modules/command-palette/command-palette.vue')['default']
CommandPaletteOption: typeof import('./src/modules/command-palette/components/command-palette-option.vue')['default']
CrcCalculator: typeof import('./src/tools/crc-calculator/crc-calculator.vue')['default']
CrontabGenerator: typeof import('./src/tools/crontab-generator/crontab-generator.vue')['default']
CSelect: typeof import('./src/ui/c-select/c-select.vue')['default']
'CSelect.demo': typeof import('./src/ui/c-select/c-select.demo.vue')['default']
@@ -127,7 +128,6 @@ declare module '@vue/runtime-core' {
MetaTagGenerator: typeof import('./src/tools/meta-tag-generator/meta-tag-generator.vue')['default']
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']
@@ -145,7 +145,12 @@ declare module '@vue/runtime-core' {
NLayoutSider: typeof import('naive-ui')['NLayoutSider']
NMenu: typeof import('naive-ui')['NMenu']
NScrollbar: typeof import('naive-ui')['NScrollbar']
NSlider: typeof import('naive-ui')['NSlider']
NSpin: typeof import('naive-ui')['NSpin']
NStatistic: typeof import('naive-ui')['NStatistic']
NSwitch: typeof import('naive-ui')['NSwitch']
NTable: typeof import('naive-ui')['NTable']
NTag: typeof import('naive-ui')['NTag']
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']
@@ -153,7 +158,6 @@ declare module '@vue/runtime-core' {
PdfSignatureDetails: typeof import('./src/tools/pdf-signature-checker/components/pdf-signature-details.vue')['default']
PercentageCalculator: typeof import('./src/tools/percentage-calculator/percentage-calculator.vue')['default']
PhoneParserAndFormatter: typeof import('./src/tools/phone-parser-and-formatter/phone-parser-and-formatter.vue')['default']
Potrace: typeof import('./src/tools/potrace/potrace.vue')['default']
QrCodeGenerator: typeof import('./src/tools/qr-code-generator/qr-code-generator.vue')['default']
RandomPortGenerator: typeof import('./src/tools/random-port-generator/random-port-generator.vue')['default']
ResultRow: typeof import('./src/tools/ipv4-range-expander/result-row.vue')['default']
+3 -4
View File
@@ -42,7 +42,6 @@
"@tiptap/starter-kit": "2.1.6",
"@tiptap/vue-3": "2.0.3",
"@types/figlet": "^1.5.8",
"@types/potrace": "^2.1.5",
"@vicons/material": "^0.12.0",
"@vicons/tabler": "^0.12.0",
"@vueuse/core": "^10.3.0",
@@ -53,6 +52,7 @@
"colord": "^2.9.3",
"composerize-ts": "^0.6.2",
"country-code-lookup": "^0.1.0",
"crc": "^4.3.2",
"cron-validator": "^1.3.1",
"cronstrue": "^2.26.0",
"crypto-js": "^4.1.1",
@@ -81,7 +81,6 @@
"pdf-signature-reader": "^1.4.2",
"pinia": "^2.0.34",
"plausible-tracker": "^0.3.8",
"potrace": "^2.1.8",
"qrcode": "^1.5.1",
"sql-formatter": "^13.0.0",
"ua-parser-js": "^1.0.35",
@@ -134,12 +133,12 @@
"unplugin-icons": "^0.17.0",
"unplugin-vue-components": "^0.25.0",
"vite": "^4.4.9",
"vite-plugin-node-polyfills": "^0.22.0",
"vite-plugin-pwa": "^0.16.0",
"vite-plugin-vue-markdown": "^0.23.5",
"vite-svg-loader": "^4.0.0",
"vitest": "^0.34.0",
"workbox-window": "^7.0.0",
"zx": "^7.2.1"
}
},
"packageManager": "pnpm@8.15.3"
}
+73 -1714
View File
File diff suppressed because it is too large. Load diff
+21
View File
@@ -0,0 +1,21 @@
import _ from 'lodash';
function useDebouncedRef<T>(initialValue: T, delay: number, immediate: boolean = false) {
const state = ref(initialValue);
const debouncedRef = customRef((track, trigger) => ({
get() {
track();
return state.value;
},
set: _.debounce(
(value) => {
state.value = value;
trigger();
},
delay,
{ leading: immediate },
),
}));
return debouncedRef;
}
export default useDebouncedRef;
+32 -1
View File
@@ -1,7 +1,8 @@
import { useRouteQuery } from '@vueuse/router';
import { computed } from 'vue';
import { useStorage } from '@vueuse/core';
export { useQueryParam };
export { useQueryParam, useQueryParamOrStorage };
const transformers = {
number: {
@@ -16,6 +17,12 @@ const transformers = {
fromQuery: (value: string) => value.toLowerCase() === 'true',
toQuery: (value: boolean) => (value ? 'true' : 'false'),
},
object: {
fromQuery: (value: string) => {
return JSON.parse(value);
},
toQuery: (value: object) => JSON.stringify(value),
},
};
function useQueryParam<T>({ name, defaultValue }: { name: string; defaultValue: T }) {
@@ -33,3 +40,27 @@ function useQueryParam<T>({ name, defaultValue }: { name: string; defaultValue:
},
});
}
function useQueryParamOrStorage<T>({ name, storageName, defaultValue }: { name: string; storageName: string; defaultValue: T }) {
const type = typeof defaultValue;
const transformer = transformers[type as keyof typeof transformers] ?? transformers.string;
const storageRef = useStorage(storageName, defaultValue);
const proxyDefaultValue = transformer.toQuery(defaultValue as never);
const proxy = useRouteQuery(name, proxyDefaultValue);
const r = ref(defaultValue);
watch(r,
(value) => {
proxy.value = transformer.toQuery(value as never);
storageRef.value = value as never;
},
{ deep: true });
r.value = (proxy.value && proxy.value !== proxyDefaultValue
? transformer.fromQuery(proxy.value) as unknown as T
: storageRef.value as T) as never;
return r;
}
+168
View File
@@ -0,0 +1,168 @@
<script setup lang="ts">
import type { lib } from 'crypto-js';
import { enc } from 'crypto-js';
import crc from 'crc';
import InputCopyable from '../../components/InputCopyable.vue';
import { convertHexToBin } from '../hash-text/hash-text.service';
import { useQueryParamOrStorage } from '@/composable/queryParams';
import { withDefaultOnError } from '@/utils/defaults';
const status = ref<'idle' | 'done' | 'error' | 'processing'>('idle');
const text = ref('');
const file = ref<File | null>(null);
const defaultCRCValues = {
crc1: '',
crc8: '',
crc81wire: '',
crc8dvbs2: '',
crc16: '',
crc16ccitt: '',
crc16modbus: '',
crc16kermit: '',
crc16xmodem: '',
crc24: '',
crc32: '',
crc32mpeg: '',
crcjam: '',
};
type AlgoNames = keyof typeof defaultCRCValues;
function getCRCs(content: Uint8Array | string) {
return {
crc1: crc.crc1(content).toString(16),
crc8: crc.crc8(content).toString(16),
crc81wire: crc.crc81wire(content).toString(16),
crc8dvbs2: crc.crc8dvbs2(content).toString(16),
crc16: crc.crc16(content).toString(16),
crc16ccitt: crc.crc16ccitt(content).toString(16),
crc16modbus: crc.crc16modbus(content).toString(16),
crc16kermit: crc.crc16kermit(content).toString(16),
crc16xmodem: crc.crc16xmodem(content).toString(16),
crc24: crc.crc24(content).toString(16),
crc32: crc.crc32(content).toString(16),
crc32mpeg: crc.crc32mpeg2(content).toString(16),
crcjam: crc.crcjam(content).toString(16),
};
}
const hashes = ref(defaultCRCValues);
async function onUpload(uploadedFile: File) {
status.value = 'processing';
file.value = uploadedFile;
const buffer = await uploadedFile.arrayBuffer();
text.value = '';
try {
hashes.value = getCRCs(new Uint8Array(buffer));
status.value = 'done';
}
catch (e) {
status.value = 'error';
}
}
const algoWasmNames = Object.keys(defaultCRCValues) as AlgoNames[];
type Encoding = keyof typeof enc | 'Bin';
const encoding = useQueryParamOrStorage<Encoding>({ defaultValue: 'Hex', storageName: 'hash-text:encoding', name: 'encoding' });
function formatWithEncoding(words: lib.WordArray, encoding: Encoding) {
if (encoding === 'Bin') {
return convertHexToBin(words.toString(enc.Hex));
}
return words.toString(enc[encoding]);
}
const CRCValues = computed(() => withDefaultOnError(() => {
const encodingValue = encoding.value;
const hashesValue = hashes.value;
const ret = defaultCRCValues;
for (const algo of algoWasmNames) {
ret[algo] = formatWithEncoding(enc.Hex.parse(hashesValue[algo]), encodingValue);
}
return ret;
}, defaultCRCValues));
watch(text,
(_, newValue) => {
if (newValue === '') {
return;
}
file.value = null;
hashes.value = getCRCs(newValue);
status.value = 'done';
},
);
</script>
<template>
<div>
<c-card>
<c-file-upload
title="Drag and drop a file here, or click to select a file"
@file-upload="onUpload"
/>
<p>OR</p>
<c-input-text
v-model:value="text"
multiline raw-text
placeholder="Paste string to CRC..." rows="3"
autosize autofocus label="Your text to CRC:"
/>
<n-divider />
<c-select
v-model:value="encoding"
mb-4
label="Digest encoding"
:options="[
{
label: 'Binary (base 2)',
value: 'Bin',
},
{
label: 'Hexadecimal (base 16)',
value: 'Hex',
},
{
label: 'Base64 (base 64)',
value: 'Base64',
},
{
label: 'Base64url (base 64 with url safe chars)',
value: 'Base64url',
},
]"
/>
</c-card>
<div mt-3 flex justify-center>
<c-alert v-if="status === 'error'" type="error">
An error occured hashing file.
</c-alert>
<n-spin
v-if="status === 'processing'"
size="small"
/>
</div>
<c-card v-if="status === 'done'" :title="file === null ? 'CRC of text' : `CRC of ${file?.name}`">
<div v-for="algo in algoWasmNames" :key="algo" style="margin: 5px 0">
<n-input-group>
<n-input-group-label style="flex: 0 0 120px">
{{ algo.toUpperCase() }}
</n-input-group-label>
<InputCopyable :value="CRCValues[algo]" readonly />
</n-input-group>
</div>
</c-card>
</div>
</template>
+24
View File
@@ -0,0 +1,24 @@
import { EyeOff } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'CRC calculator',
path: '/crc-calculator',
description: 'Compute text or file CRC (CRC1, CRC8, CRC8 1-Wire, CRC8 DVB-S2, CRC16, CRC16 CCITT, CRC16 Modbus, CRC16 Kermit, CRC16 XModem, CRC24, CRC32, CRC32 MPEG-2, CRCJAM)',
keywords: ['crc', 'checksum', 'crc1',
'crc8',
'crc8 1-wire',
'crc8 dvb-s2',
'crc16',
'crc16 ccitt',
'crc16 modbus',
'crc16 kermit',
'crc16 xmodem',
'crc24',
'crc32',
'crc32 mpeg-2',
'crcjam'],
component: () => import('./crc-calculator.vue'),
icon: EyeOff,
createdAt: new Date('2024-05-11'),
});
+2 -1
View File
@@ -4,6 +4,7 @@ import emojiKeywords from 'emojilib';
import _ from 'lodash';
import type { EmojiInfo } from './emoji.types';
import { useFuzzySearch } from '@/composable/fuzzySearch';
import useDebouncedRef from '@/composable/debouncedref';
const escapeUnicode = ({ emoji }: { emoji: string }) => emoji.split('').map(unit => `\\u${unit.charCodeAt(0).toString(16).padStart(4, '0')}`).join('');
const getEmojiCodePoints = ({ emoji }: { emoji: string }) => emoji.codePointAt(0) ? `0x${emoji.codePointAt(0)?.toString(16)}` : undefined;
@@ -23,7 +24,7 @@ const emojisGroups: { emojiInfos: EmojiInfo[]; group: string }[] = _
.map((emojiInfos, group) => ({ group, emojiInfos }))
.value();
const searchQuery = ref('');
const searchQuery = useDebouncedRef('', 500);
const { searchResult } = useFuzzySearch({
search: searchQuery,
+16 -9
View File
@@ -5,8 +5,8 @@ import { tool as basicAuthGenerator } from './basic-auth-generator';
import { tool as asciiTextDrawer } from './ascii-text-drawer';
import { tool as textToUnicode } from './text-to-unicode';
import { tool as crcCalculator } from './crc-calculator';
import { tool as safelinkDecoder } from './safelink-decoder';
import { tool as potrace } from './potrace';
import { tool as pdfSignatureChecker } from './pdf-signature-checker';
import { tool as numeronymGenerator } from './numeronym-generator';
import { tool as macAddressGenerator } from './mac-address-generator';
@@ -86,7 +86,20 @@ import { tool as yamlViewer } from './yaml-viewer';
export const toolsByCategory: ToolCategory[] = [
{
name: 'Crypto',
components: [tokenGenerator, hashText, bcrypt, uuidGenerator, ulidGenerator, cypher, bip39, hmacGenerator, rsaKeyPairGenerator, passwordStrengthAnalyser, pdfSignatureChecker],
components: [
tokenGenerator,
hashText,
crcCalculator,
bcrypt,
uuidGenerator,
ulidGenerator,
cypher,
bip39,
hmacGenerator,
rsaKeyPairGenerator,
passwordStrengthAnalyser,
pdfSignatureChecker,
],
},
{
name: 'Converter',
@@ -133,13 +146,7 @@ export const toolsByCategory: ToolCategory[] = [
},
{
name: 'Images and videos',
components: [
qrCodeGenerator,
wifiQrCodeGenerator,
svgPlaceholderGenerator,
cameraRecorder,
potrace,
],
components: [qrCodeGenerator, wifiQrCodeGenerator, svgPlaceholderGenerator, cameraRecorder],
},
{
name: 'Development',
-12
View File
@@ -1,12 +0,0 @@
import { ArrowsShuffle } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'Image to SVG (potrace)',
path: '/potrace',
description: 'Convert an raster image to vectorial SVG',
keywords: ['potrace', 'image', 'svg', 'raster', 'vectorial'],
component: () => import('./potrace.vue'),
icon: ArrowsShuffle,
createdAt: new Date('2024-05-11'),
});
-104
View File
@@ -1,104 +0,0 @@
<script setup lang="ts">
import { Buffer } from 'node:buffer';
import type { Ref } from 'vue';
import potrace from 'potrace';
import { Base64 } from 'js-base64';
import TextareaCopyable from '@/components/TextareaCopyable.vue';
async function traceAsync(input: Buffer) {
return new Promise<string>((resolve, reject) => {
potrace.trace(input, (err: Error | null, svg: string) => {
if (err) {
reject(err);
}
resolve(svg);
});
});
}
async function posterizeAsync(input: Buffer) {
return new Promise<string>((resolve, reject) => {
potrace.posterize(input,
(err: Error | null, svg: string) => {
if (err) {
reject(err);
}
resolve(svg);
});
});
}
function file2Buffer(file: File) {
return new Promise<Buffer>((resolve, _reject) => {
const reader = new FileReader();
reader.addEventListener('load', () => {
const buffer = Buffer.from(reader.result as ArrayBuffer);
resolve(buffer);
});
reader.readAsArrayBuffer(file);
});
}
const posterize = ref(true);
const fileInput = ref() as Ref<File>;
const svg = computedAsync(async () => {
const trace = !posterize.value;
const file = fileInput.value;
if (!file) {
return '';
}
try {
const buffer = await file2Buffer(file);
return (trace ? await traceAsync(buffer) : await posterizeAsync(buffer));
}
catch (e: any) {
return e.toString();
}
});
const svgBase64 = computed(() => svg.value ? `data:image/svg+xml;base64,${Base64.encode(svg.value)}` : '');
async function onUpload(file: File) {
if (file) {
fileInput.value = file;
}
}
</script>
<template>
<div style="max-width: 600px;">
<c-file-upload
title="Drag and drop an image here, or click to select a file"
:paste-image="true"
@file-upload="onUpload"
/>
<div style="text-align: center;">
<n-checkbox v-model:checked="posterize" mt-2>
Posterize?
</n-checkbox>
</div>
<n-divider />
<div>
<h3>Potrace result</h3>
<TextareaCopyable
:value="svg"
word-wrap
/>
<n-divider />
<div style="text-align: center;">
<img width="150" :src="svgBase64" style="background-color: white">
</div>
</div>
</div>
</template>
<style lang="less" scoped>
::v-deep(.n-upload-trigger) {
width: 100%;
}
</style>
-2
View File
@@ -15,7 +15,6 @@ import { VitePWA } from 'vite-plugin-pwa';
import markdown from 'vite-plugin-vue-markdown';
import svgLoader from 'vite-svg-loader';
import { configDefaults } from 'vitest/config';
import { nodePolyfills } from 'vite-plugin-node-polyfills'
const baseUrl = process.env.BASE_URL ?? '/';
@@ -98,7 +97,6 @@ export default defineConfig({
resolvers: [NaiveUiResolver(), IconsResolver({ prefix: 'icon' })],
}),
Unocss(),
nodePolyfills(),
],
base: baseUrl,
resolve: {