Skip to content

Commit 3be8338

Browse files
author
Andrew Marcuse
committed
Chardet tweaks
1 parent 8e1f268 commit 3be8338

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/chardet.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ document.querySelector<HTMLDivElement>('#app')!.innerHTML = `
4848

4949
type DetectionResult = {
5050
library: string
51+
libraryUrl: string
5152
encoding: string
5253
confidence?: number
5354
}
@@ -116,6 +117,7 @@ const detectWithJschardet = async (bytes: Uint8Array): Promise<DetectionResult[]
116117
.filter((entry) => Boolean(entry.encoding))
117118
.map((entry) => ({
118119
library: 'jschardet',
120+
libraryUrl: 'https://www.npmjs.com/package/jschardet',
119121
encoding: entry.encoding,
120122
confidence: entry.confidence ?? 0,
121123
}))
@@ -151,6 +153,7 @@ const detectWithEncodingJs = async (bytes: Uint8Array): Promise<DetectionResult[
151153
return [
152154
{
153155
library: 'encoding.js',
156+
libraryUrl: 'https://www.npmjs.com/package/encoding-japanese',
154157
encoding: detected,
155158
},
156159
]
@@ -166,6 +169,7 @@ const detectWithChardet = async (bytes: Uint8Array): Promise<DetectionResult[]>
166169
if (analysed.length > 0) {
167170
return analysed.map((entry) => ({
168171
library: 'chardet',
172+
libraryUrl: 'https://www.npmjs.com/package/chardet',
169173
encoding: entry.name,
170174
confidence: entry.confidence,
171175
}))
@@ -179,6 +183,7 @@ const detectWithChardet = async (bytes: Uint8Array): Promise<DetectionResult[]>
179183
return [
180184
{
181185
library: 'chardet',
186+
libraryUrl: 'https://www.npmjs.com/package/chardet',
182187
encoding: primary,
183188
},
184189
]
@@ -194,7 +199,7 @@ const renderResults = (results: DetectionResult[], fileSize: number) => {
194199
.slice(0, 30)
195200
.map(
196201
(result) =>
197-
`<tr><td>${result.library}</td><td>${result.encoding}</td><td class="text-right">${formatConfidence(result.confidence)}</td></tr>`,
202+
`<tr><td><a class="link link-primary" href="${result.libraryUrl}">${result.library}</a></td><td>${result.encoding}</td><td class="text-right">${formatConfidence(result.confidence)}</td></tr>`,
198203
)
199204
.join('')
200205
: '<tr><td colspan="3">No result</td></tr>'
@@ -212,6 +217,10 @@ clearResultsButton?.addEventListener('click', () => {
212217
resultsSummary.textContent = ''
213218
}
214219

220+
if (fileInput) {
221+
fileInput.value = ''
222+
}
223+
215224
resultsSection?.classList.add('hidden')
216225
})
217226

@@ -252,7 +261,6 @@ fileInput?.addEventListener('change', async () => {
252261
} finally {
253262
if (fileInput) {
254263
fileInput.disabled = false
255-
fileInput.value = ''
256264
}
257265
}
258266
})

src/main.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ document.querySelector<HTMLDivElement>('#app')!.innerHTML = `
6060
<a href="https://github.com/FileFormatInfo/fftools/releases/latest" class="btn btn-sm">
6161
Downloads
6262
</a>
63+
<a href="https://github.com/FileFormatInfo/fftools?tab=readme-ov-file#installation" class="btn btn-sm">
64+
Brew
65+
</a>
6366
</div>
6467
</div>
6568
</article>

0 commit comments

Comments
 (0)