Merge pull request #72 from runk/export-result-types

patch: Export AnalyseResult and DetectResult types
This commit is contained in:
Dmitry Shirokov 2023-01-06 08:00:27 +11:00 committed by GitHub
commit dfa504f4d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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;