mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-20 21:23:08 +03:00
feat(new tool): Charset Detector/Decoder
This commit is contained in:
1 parent
d450f3b38c
commit
2b06b5b64c
4 files changed
+174
-5
No files matched your search
@@ -101,6 +101,7 @@
|
||||
"bwip-js": "^4.5.1",
|
||||
"byte-data": "^19.0.1",
|
||||
"change-case": "^5.4.4",
|
||||
"chardet": "^2.1.0",
|
||||
"chatgpt-prompt-splitter": "^1.0.5",
|
||||
"chinesegen": "^0.3.3",
|
||||
"cidr-tools": "^11.0.3",
|
||||
|
||||
Generated
+12
-5
@@ -191,6 +191,9 @@ dependencies:
|
||||
change-case:
|
||||
specifier: ^5.4.4
|
||||
version: 5.4.4
|
||||
chardet:
|
||||
specifier: ^2.1.0
|
||||
version: 2.1.0
|
||||
chatgpt-prompt-splitter:
|
||||
specifier: ^1.0.5
|
||||
version: 1.0.5
|
||||
@@ -7214,7 +7217,7 @@ packages:
|
||||
debug: 4.4.0
|
||||
globby: 11.1.0
|
||||
is-glob: 4.0.3
|
||||
semver: 7.7.1
|
||||
semver: 7.7.2
|
||||
ts-api-utils: 1.0.1(typescript@5.2.2)
|
||||
typescript: 5.2.2
|
||||
transitivePeerDependencies:
|
||||
@@ -7296,7 +7299,7 @@ packages:
|
||||
'@typescript-eslint/types': 6.4.1
|
||||
'@typescript-eslint/typescript-estree': 6.4.1(typescript@5.2.2)
|
||||
eslint: 8.47.0
|
||||
semver: 7.7.1
|
||||
semver: 7.7.2
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
- typescript
|
||||
@@ -7315,7 +7318,7 @@ packages:
|
||||
'@typescript-eslint/types': 6.9.1
|
||||
'@typescript-eslint/typescript-estree': 6.9.1(typescript@5.2.2)
|
||||
eslint: 8.47.0
|
||||
semver: 7.7.1
|
||||
semver: 7.7.2
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
- typescript
|
||||
@@ -8768,7 +8771,7 @@ packages:
|
||||
/builtins@5.0.1:
|
||||
resolution: {integrity: sha512-qwVpFEHNfhYJIzNRBvd2C1kyo6jz3ZSMPyyuR47OPdiKWlbYnZNyDWuyR175qDnAJLiCo5fBBqPb3RiXgWlkOQ==}
|
||||
dependencies:
|
||||
semver: 7.7.1
|
||||
semver: 7.7.2
|
||||
dev: true
|
||||
|
||||
/bwip-js@4.5.1:
|
||||
@@ -8961,6 +8964,10 @@ packages:
|
||||
resolution: {integrity: sha512-mKKUkUbhPpQlCOfIuZkvSEgktjPFIsZKRRbC6KWVEMvlzblj3i3asQv5ODsrwt0N3pHAEvjP8KTQPHkp0+6jOg==}
|
||||
dev: true
|
||||
|
||||
/chardet@2.1.0:
|
||||
resolution: {integrity: sha512-bNFETTG/pM5ryzQ9Ad0lJOTa6HWD/YsScAR3EnCPZRPlQh77JocYktSHOUHelyhm8IARL+o4c4F1bP5KVOjiRA==}
|
||||
dev: false
|
||||
|
||||
/chatgpt-prompt-splitter@1.0.5:
|
||||
resolution: {integrity: sha512-8buXXnxZ5Y5BloPTMEhGTVld9vrVB8WVrUFrjgOpIJ4/VsT+rTnLszbaS1L1KAB0SDSCqj8GU472S2gMyhH8EA==}
|
||||
dev: false
|
||||
@@ -19248,7 +19255,7 @@ packages:
|
||||
espree: 9.6.1
|
||||
esquery: 1.5.0
|
||||
lodash: 4.17.21
|
||||
semver: 7.7.1
|
||||
semver: 7.7.2
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
dev: true
|
||||
|
||||
@@ -0,0 +1,148 @@
|
||||
<script setup lang="ts">
|
||||
import { Buffer } from 'node:buffer';
|
||||
import chardet from 'chardet';
|
||||
import iconv from 'iconv-lite';
|
||||
|
||||
const inputType = ref<'file' | 'content'>('file');
|
||||
const fileContent = ref('');
|
||||
const fileInput = ref() as Ref<File | null>;
|
||||
const error = ref('');
|
||||
const contentDecoded = ref('');
|
||||
|
||||
async function getUInt8ArrayFromInputs() {
|
||||
const fileContentValue = fileContent.value;
|
||||
const file = fileInput.value;
|
||||
if (inputType.value === 'file' && file) {
|
||||
return new Uint8Array(await file.arrayBuffer());
|
||||
}
|
||||
else if (inputType.value === 'content' && fileContentValue) {
|
||||
const uint8Array = new Uint8Array(fileContentValue.length);
|
||||
for (let i = 0; i < fileContentValue.length; i++) {
|
||||
uint8Array[i] = fileContentValue.charCodeAt(i);
|
||||
}
|
||||
return uint8Array;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
const encodings = computedAsync(async () => {
|
||||
error.value = '';
|
||||
try {
|
||||
const buffer = await getUInt8ArrayFromInputs();
|
||||
if (buffer === null) {
|
||||
return null;
|
||||
}
|
||||
return chardet.analyse(buffer);
|
||||
}
|
||||
catch (e: any) {
|
||||
error.value = e.toString();
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
async function generateEncodedOutput(encoding: string) {
|
||||
error.value = '';
|
||||
contentDecoded.value = '';
|
||||
try {
|
||||
const buffer = await getUInt8ArrayFromInputs();
|
||||
if (buffer === null) {
|
||||
return;
|
||||
}
|
||||
contentDecoded.value = iconv.decode(Buffer.from(buffer), encoding);
|
||||
}
|
||||
catch (e: any) {
|
||||
return e.toString();
|
||||
}
|
||||
}
|
||||
|
||||
function onUpload(file: File) {
|
||||
if (file) {
|
||||
fileInput.value = file;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div style="max-width: 600px;">
|
||||
<c-card title="Input" mb-2>
|
||||
<n-radio-group v-model:value="inputType" name="radiogroup" mb-2 flex justify-center>
|
||||
<n-space>
|
||||
<n-radio
|
||||
value="file"
|
||||
label="File"
|
||||
/>
|
||||
<n-radio
|
||||
value="content"
|
||||
label="Content"
|
||||
/>
|
||||
</n-space>
|
||||
</n-radio-group>
|
||||
|
||||
<c-file-upload
|
||||
v-if="inputType === 'file'"
|
||||
title="Drag and drop TXT file here, or click to select a file"
|
||||
@file-upload="onUpload"
|
||||
/>
|
||||
|
||||
<c-input-text
|
||||
v-if="inputType === 'content'"
|
||||
v-model:value="fileContent"
|
||||
label="File Content"
|
||||
multiline
|
||||
placeholder="Put your text content here..."
|
||||
rows="15"
|
||||
mb-2
|
||||
/>
|
||||
</c-card>
|
||||
|
||||
<c-alert v-if="error">
|
||||
{{ error }}
|
||||
</c-alert>
|
||||
|
||||
<c-card v-if="!error && encodings" title="Possible encodings">
|
||||
<n-table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">
|
||||
Confidence
|
||||
</th>
|
||||
<th scope="col">
|
||||
Name
|
||||
</th>
|
||||
<th scope="col">
|
||||
Lang
|
||||
</th>
|
||||
<th />
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr
|
||||
v-for="(enc, index) in encodings || []"
|
||||
:key="index"
|
||||
>
|
||||
<td>
|
||||
{{ enc.confidence }}
|
||||
</td>
|
||||
<td>
|
||||
{{ enc.name }}
|
||||
</td>
|
||||
<td>
|
||||
{{ enc.lang }}
|
||||
</td>
|
||||
<td>
|
||||
<n-button @click="generateEncodedOutput(enc.name.toLocaleLowerCase())">
|
||||
Decode
|
||||
</n-button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</n-table>
|
||||
|
||||
<n-card v-if="contentDecoded" title="Decoded text" mb-1>
|
||||
<textarea-copyable :value="contentDecoded" />
|
||||
</n-card>
|
||||
</c-card>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,13 @@
|
||||
import { FileText } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'Text Charset Detector/Decoder',
|
||||
path: '/charset-detector',
|
||||
description: 'Detect text possible charsets and allow to decode using each detected encoding',
|
||||
keywords: ['charset', 'ascii', 'iso', 'utf8', 'unicode', 'encoding', 'decode', 'text', 'detector'],
|
||||
component: () => import('./charset-detector.vue'),
|
||||
icon: FileText,
|
||||
createdAt: new Date('2025-03-09'),
|
||||
category: 'Forensic',
|
||||
});
|
||||
Reference in new issue
Block a user