make type definitions compatible with browser
This commit is contained in:
parent
28db00677d
commit
f55ad61176
|
@ -9,8 +9,8 @@ export interface Recogniser {
|
|||
export interface Context {
|
||||
fByteStats: number[];
|
||||
fC1Bytes: boolean;
|
||||
fRawInput: Buffer;
|
||||
fRawInput: Uint8Array;
|
||||
fRawLength: number;
|
||||
fInputBytes: Buffer;
|
||||
fInputBytes: Uint8Array;
|
||||
fInputLen: number;
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ export class UTF_16LE implements Recogniser {
|
|||
}
|
||||
|
||||
interface WithGetChar {
|
||||
getChar(input: Buffer, index: number): number;
|
||||
getChar(input: Uint8Array, index: number): number;
|
||||
}
|
||||
|
||||
class UTF_32 implements Recogniser, WithGetChar {
|
||||
|
@ -60,7 +60,7 @@ class UTF_32 implements Recogniser, WithGetChar {
|
|||
return 'UTF-32';
|
||||
}
|
||||
|
||||
getChar(input: Buffer, index: number): number {
|
||||
getChar(input: Uint8Array, index: number): number {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -114,7 +114,7 @@ export class UTF_32BE extends UTF_32 {
|
|||
name() {
|
||||
return 'UTF-32BE';
|
||||
}
|
||||
getChar(input: Buffer, index: number) {
|
||||
getChar(input: Uint8Array, index: number) {
|
||||
return (
|
||||
((input[index + 0] & 0xff) << 24) |
|
||||
((input[index + 1] & 0xff) << 16) |
|
||||
|
@ -129,7 +129,7 @@ export class UTF_32LE extends UTF_32 {
|
|||
return 'UTF-32LE';
|
||||
}
|
||||
|
||||
getChar(input: Buffer, index: number) {
|
||||
getChar(input: Uint8Array, index: number) {
|
||||
return (
|
||||
((input[index + 3] & 0xff) << 24) |
|
||||
((input[index + 2] & 0xff) << 16) |
|
||||
|
|
|
@ -50,12 +50,12 @@ const recognisers: Recogniser[] = [
|
|||
|
||||
type DetectResult = Match[] | string | null;
|
||||
|
||||
export const detect = (buffer: Buffer): 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: Buffer): Match[] => {
|
||||
export const analyse = (buffer: Uint8Array): Match[] => {
|
||||
// Tally up the byte occurrence statistics.
|
||||
const fByteStats = [];
|
||||
for (let i = 0; i < 256; i++) fByteStats[i] = 0;
|
||||
|
|
Loading…
Reference in New Issue