Skip to content

Commit

Permalink
feat: Make type definitions compatible with browser
Browse files Browse the repository at this point in the history
feat: Make type definitions compatible with browser
  • Loading branch information
Dmitry Shirokov authored Jul 2, 2020
2 parents 28db006 + f55ad61 commit 79457df
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/encoding/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
8 changes: 4 additions & 4 deletions src/encoding/unicode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ 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 {
name() {
return 'UTF-32';
}

getChar(input: Buffer, index: number): number {
getChar(input: Uint8Array, index: number): number {
return -1;
}

Expand Down Expand Up @@ -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) |
Expand All @@ -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) |
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 79457df

Please sign in to comment.