From fb50dcbcdbf1e07b67dd5f0aaa3a736027b6decc Mon Sep 17 00:00:00 2001 From: Dmitry Shirokov Date: Tue, 19 Oct 2021 20:27:41 +1100 Subject: [PATCH] Maintenance --- .github/workflows/build.yml | 2 +- src/encoding/index.ts | 12 ++++++------ src/encoding/iso2022.ts | 4 ++-- src/encoding/mbcs.ts | 4 ++-- src/encoding/sbcs.ts | 16 ++++++++-------- src/encoding/unicode.ts | 8 ++++---- src/encoding/utf8.ts | 8 ++++---- src/index.ts | 24 ++++++++++++------------ 8 files changed, 39 insertions(+), 39 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8d91862..f10024f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,7 +12,7 @@ jobs: strategy: matrix: - node-version: [10.x, 12.x, 14.x] + node-version: [12.x, 14.x, 16x] steps: - uses: actions/checkout@v2 diff --git a/src/encoding/index.ts b/src/encoding/index.ts index 5cc6c81..01686f1 100644 --- a/src/encoding/index.ts +++ b/src/encoding/index.ts @@ -7,10 +7,10 @@ export interface Recogniser { } export interface Context { - fByteStats: number[]; - fC1Bytes: boolean; - fRawInput: Uint8Array; - fRawLength: number; - fInputBytes: Uint8Array; - fInputLen: number; + byteStats: number[]; + c1Bytes: boolean; + rawInput: Uint8Array; + rawLen: number; + inputBytes: Uint8Array; + inputLen: number; } diff --git a/src/encoding/iso2022.ts b/src/encoding/iso2022.ts index c9de55c..46aa974 100644 --- a/src/encoding/iso2022.ts +++ b/src/encoding/iso2022.ts @@ -36,8 +36,8 @@ class ISO_2022 implements Recogniser { let quality; // TODO: refactor me - const text = det.fInputBytes; - const textLen = det.fInputLen; + const text = det.inputBytes; + const textLen = det.inputLen; scanInput: for (i = 0; i < textLen; i++) { if (text[i] == 0x1b) { diff --git a/src/encoding/mbcs.ts b/src/encoding/mbcs.ts index 300d328..507f3f4 100644 --- a/src/encoding/mbcs.ts +++ b/src/encoding/mbcs.ts @@ -64,11 +64,11 @@ class IteratedChar { } nextByte(det: Context) { - if (this.nextIndex >= det.fRawLength) { + if (this.nextIndex >= det.rawLen) { this.done = true; return -1; } - const byteValue = det.fRawInput[this.nextIndex++] & 0x00ff; + const byteValue = det.rawInput[this.nextIndex++] & 0x00ff; return byteValue; } } diff --git a/src/encoding/sbcs.ts b/src/encoding/sbcs.ts index cda6ebe..1484413 100644 --- a/src/encoding/sbcs.ts +++ b/src/encoding/sbcs.ts @@ -58,9 +58,9 @@ class NGramParser { } nextByte(det: Context) { - if (this.byteIndex >= det.fInputLen) return -1; + if (this.byteIndex >= det.inputLen) return -1; - return det.fInputBytes[this.byteIndex++] & 0xff; + return det.inputBytes[this.byteIndex++] & 0xff; } parse(det: Context, spaceCh: number) { @@ -1080,7 +1080,7 @@ export class ISO_8859_1 extends sbcs { } name(input: Context): string { - return input && input.fC1Bytes ? 'windows-1252' : 'ISO-8859-1'; + return input && input.c1Bytes ? 'windows-1252' : 'ISO-8859-1'; } } @@ -1616,7 +1616,7 @@ export class ISO_8859_2 extends sbcs { } name(det: Context): string { - return det && det.fC1Bytes ? 'windows-1250' : 'ISO-8859-2'; + return det && det.c1Bytes ? 'windows-1250' : 'ISO-8859-2'; } } @@ -2632,7 +2632,7 @@ export class ISO_8859_7 extends sbcs { } name(det: Context): string { - return det && det.fC1Bytes ? 'windows-1253' : 'ISO-8859-7'; + return det && det.c1Bytes ? 'windows-1253' : 'ISO-8859-7'; } language() { @@ -3040,7 +3040,7 @@ export class ISO_8859_8 extends sbcs { } name(det: Context): string { - return det && det.fC1Bytes ? 'windows-1255' : 'ISO-8859-8'; + return det && det.c1Bytes ? 'windows-1255' : 'ISO-8859-8'; } language() { @@ -3380,7 +3380,7 @@ export class ISO_8859_9 extends sbcs { } name(det: Context): string { - return det && det.fC1Bytes ? 'windows-1254' : 'ISO-8859-9'; + return det && det.c1Bytes ? 'windows-1254' : 'ISO-8859-9'; } language() { @@ -4425,7 +4425,7 @@ module.exports.ISO_8859_7 = function() { this.name = function(det) { if (typeof det == 'undefined') return 'ISO-8859-7'; - return det.fC1Bytes ? 'windows-1253' : 'ISO-8859-7'; + return det.c1Bytes ? 'windows-1253' : 'ISO-8859-7'; }; language() { diff --git a/src/encoding/unicode.ts b/src/encoding/unicode.ts index 28be3a5..06ab709 100644 --- a/src/encoding/unicode.ts +++ b/src/encoding/unicode.ts @@ -11,7 +11,7 @@ export class UTF_16BE implements Recogniser { } match(det: Context): Match | null { - const input = det.fRawInput; + const input = det.rawInput; if ( input.length >= 2 && @@ -31,7 +31,7 @@ export class UTF_16LE implements Recogniser { return 'UTF-16LE'; } match(det: Context): Match | null { - const input = det.fRawInput; + const input = det.rawInput; if ( input.length >= 2 && @@ -69,8 +69,8 @@ class UTF_32 implements Recogniser, WithGetChar { numInvalid = 0, hasBOM = false, confidence = 0; - const limit = (det.fRawLength / 4) * 4; - const input = det.fRawInput; + const limit = (det.rawLen / 4) * 4; + const input = det.rawInput; if (limit == 0) { return null; diff --git a/src/encoding/utf8.ts b/src/encoding/utf8.ts index cc8cce4..6d3c0e4 100644 --- a/src/encoding/utf8.ts +++ b/src/encoding/utf8.ts @@ -12,10 +12,10 @@ export default class Utf8 implements Recogniser { numInvalid = 0, trailBytes = 0, confidence; - const input = det.fRawInput; + const input = det.rawInput; if ( - det.fRawLength >= 3 && + det.rawLen >= 3 && (input[0] & 0xff) == 0xef && (input[1] & 0xff) == 0xbb && (input[2] & 0xff) == 0xbf @@ -24,7 +24,7 @@ export default class Utf8 implements Recogniser { } // Scan for multi-byte sequences - for (let i = 0; i < det.fRawLength; i++) { + for (let i = 0; i < det.rawLen; i++) { const b = input[i]; if ((b & 0x80) == 0) continue; // ASCII @@ -44,7 +44,7 @@ export default class Utf8 implements Recogniser { // Verify that we've got the right number of trail bytes in the sequence for (;;) { i++; - if (i >= det.fRawLength) break; + if (i >= det.rawLen) break; if ((input[i] & 0xc0) != 0x080) { numInvalid++; diff --git a/src/index.ts b/src/index.ts index 6f94c9c..2030222 100644 --- a/src/index.ts +++ b/src/index.ts @@ -50,26 +50,26 @@ export const detect = (buffer: Uint8Array): string | null => { export const analyse = (buffer: Uint8Array): Match[] => { // Tally up the byte occurrence statistics. - const fByteStats = []; - for (let i = 0; i < 256; i++) fByteStats[i] = 0; + const byteStats = []; + for (let i = 0; i < 256; i++) byteStats[i] = 0; - for (let i = buffer.length - 1; i >= 0; i--) fByteStats[buffer[i] & 0x00ff]++; + for (let i = buffer.length - 1; i >= 0; i--) byteStats[buffer[i] & 0x00ff]++; - let fC1Bytes = false; + let c1Bytes = false; for (let i = 0x80; i <= 0x9f; i += 1) { - if (fByteStats[i] !== 0) { - fC1Bytes = true; + if (byteStats[i] !== 0) { + c1Bytes = true; break; } } const context: Context = { - fByteStats, - fC1Bytes, - fRawInput: buffer, - fRawLength: buffer.length, - fInputBytes: buffer, - fInputLen: buffer.length, + byteStats, + c1Bytes, + rawInput: buffer, + rawLen: buffer.length, + inputBytes: buffer, + inputLen: buffer.length, }; const matches = recognisers