feat: Make type definitions compatible with browser

feat: Make type definitions compatible with browser
This commit is contained in:
Dmitry Shirokov 2020-07-02 10:52:46 +10:00 committed by GitHub
commit 79457df59b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 8 deletions

View File

@ -9,8 +9,8 @@ export interface Recogniser {
export interface Context { export interface Context {
fByteStats: number[]; fByteStats: number[];
fC1Bytes: boolean; fC1Bytes: boolean;
fRawInput: Buffer; fRawInput: Uint8Array;
fRawLength: number; fRawLength: number;
fInputBytes: Buffer; fInputBytes: Uint8Array;
fInputLen: number; fInputLen: number;
} }

View File

@ -52,7 +52,7 @@ export class UTF_16LE implements Recogniser {
} }
interface WithGetChar { interface WithGetChar {
getChar(input: Buffer, index: number): number; getChar(input: Uint8Array, index: number): number;
} }
class UTF_32 implements Recogniser, WithGetChar { class UTF_32 implements Recogniser, WithGetChar {
@ -60,7 +60,7 @@ class UTF_32 implements Recogniser, WithGetChar {
return 'UTF-32'; return 'UTF-32';
} }
getChar(input: Buffer, index: number): number { getChar(input: Uint8Array, index: number): number {
return -1; return -1;
} }
@ -114,7 +114,7 @@ export class UTF_32BE extends UTF_32 {
name() { name() {
return 'UTF-32BE'; return 'UTF-32BE';
} }
getChar(input: Buffer, index: number) { getChar(input: Uint8Array, index: number) {
return ( return (
((input[index + 0] & 0xff) << 24) | ((input[index + 0] & 0xff) << 24) |
((input[index + 1] & 0xff) << 16) | ((input[index + 1] & 0xff) << 16) |
@ -129,7 +129,7 @@ export class UTF_32LE extends UTF_32 {
return 'UTF-32LE'; return 'UTF-32LE';
} }
getChar(input: Buffer, index: number) { getChar(input: Uint8Array, index: number) {
return ( return (
((input[index + 3] & 0xff) << 24) | ((input[index + 3] & 0xff) << 24) |
((input[index + 2] & 0xff) << 16) | ((input[index + 2] & 0xff) << 16) |

View File

@ -50,12 +50,12 @@ const recognisers: Recogniser[] = [
type DetectResult = Match[] | string | null; type DetectResult = Match[] | string | null;
export const detect = (buffer: Buffer): 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: Buffer): Match[] => { export const analyse = (buffer: Uint8Array): Match[] => {
// Tally up the byte occurrence statistics. // Tally up the byte occurrence statistics.
const fByteStats = []; const fByteStats = [];
for (let i = 0; i < 256; i++) fByteStats[i] = 0; for (let i = 0; i < 256; i++) fByteStats[i] = 0;