patch: Export AnalyseResult and DetectResult types

This commit is contained in:
Dmitry Shirokov 2023-01-06 07:57:59 +11:00
parent 4ad395614c
commit 927d5c637b
2 changed files with 4 additions and 3 deletions

View File

@ -1,4 +1,4 @@
Copyright (C) 2022 Dmitry Shirokov Copyright (C) 2023 Dmitry Shirokov
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View File

@ -42,14 +42,15 @@ const recognisers: Recogniser[] = [
new sbcs.KOI8_R(), new sbcs.KOI8_R(),
]; ];
type DetectResult = Match[] | string | null; export type AnalyseResult = Match[];
export type DetectResult = string | null;
export const detect = (buffer: Uint8Array): string | null => { export const detect = (buffer: Uint8Array): string | null => {
const matches: Match[] = analyse(buffer); const matches: Match[] = analyse(buffer);
return matches.length > 0 ? matches[0].name : null; return matches.length > 0 ? matches[0].name : null;
}; };
export const analyse = (buffer: Uint8Array): Match[] => { export const analyse = (buffer: Uint8Array): AnalyseResult => {
// Tally up the byte occurrence statistics. // Tally up the byte occurrence statistics.
const byteStats = []; const byteStats = [];
for (let i = 0; i < 256; i++) byteStats[i] = 0; for (let i = 0; i < 256; i++) byteStats[i] = 0;