Merge pull request #72 from runk/export-result-types
patch: Export AnalyseResult and DetectResult types
This commit is contained in:
commit
dfa504f4d5
2
LICENSE
2
LICENSE
|
@ -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
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
|
|
@ -42,14 +42,15 @@ const recognisers: Recogniser[] = [
|
|||
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 => {
|
||||
const matches: Match[] = analyse(buffer);
|
||||
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.
|
||||
const byteStats = [];
|
||||
for (let i = 0; i < 256; i++) byteStats[i] = 0;
|
||||
|
|
Loading…
Reference in New Issue