Skip to content

Commit b176134

Browse files
author
Dmitry Shirokov
authored
Merge pull request #37 from runk/major-dev-deps
Major dev deps
2 parents bbb4fed + edcfec1 commit b176134

File tree

17 files changed

+6081
-3725
lines changed

17 files changed

+6081
-3725
lines changed

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
lib
2+
jest.config.js

.eslintrc.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"root": true,
3+
"parser": "@typescript-eslint/parser",
4+
"plugins": ["@typescript-eslint"],
5+
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
6+
"rules": {
7+
"@typescript-eslint/no-unused-vars": ["warn", { "varsIgnorePattern": "_" }],
8+
"@typescript-eslint/no-inferrable-types": ["off"]
9+
}
10+
}

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
language: node_js
22
node_js:
3-
- "8"
43
- "10"
54
- "12"
5+
- "14"
66

77
jobs:
88
include:

package-lock.json

Lines changed: 5982 additions & 3609 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
},
1515
"scripts": {
1616
"build": "rm -rf lib/* && tsc",
17-
"lint": "tslint -p tsconfig.json -c tslint.json",
17+
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
1818
"lint:types": "tsc --noEmit",
1919
"format": "prettier --write ./src/**/*.ts",
2020
"format:check": "prettier --list-different ./src/**/*.ts",
@@ -33,14 +33,16 @@
3333
"test": "test"
3434
},
3535
"devDependencies": {
36-
"@types/jest": "^25.1.4",
37-
"@types/node": "^13.9.5",
38-
"jest": "^25.2.4",
39-
"prettier": "^2.0.2",
40-
"semantic-release": "^15.14.0",
41-
"ts-jest": "^25.2.1",
42-
"tslint": "^6.1.0",
43-
"typescript": "^3.8.3"
36+
"@types/jest": "^26.0.14",
37+
"@types/node": "^14.11.2",
38+
"@typescript-eslint/eslint-plugin": "^4.2.0",
39+
"@typescript-eslint/parser": "^4.2.0",
40+
"eslint": "^7.9.0",
41+
"jest": "^26.4.2",
42+
"prettier": "^2.1.2",
43+
"semantic-release": "^17.1.2",
44+
"ts-jest": "^26.4.0",
45+
"typescript": "^4.0.3"
4446
},
4547
"keywords": [
4648
"encoding",

src/encoding/iso2022.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as chardet from '..';
22

33
describe('ISO-2022', () => {
4-
var base = __dirname + '/../test/data/encodings';
4+
const base = __dirname + '/../test/data/encodings';
55

66
it('should return ISO-2022-JP', () => {
77
expect(chardet.detectFileSync(base + '/iso2022jp')).toBe('ISO-2022-JP');

src/encoding/iso2022.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Context, Recogniser } from '.';
2-
3-
var match = require('../match').default;
2+
import match, { Match } from '../match';
43

54
/**
65
* This is a superclass for the individual detectors for
@@ -15,7 +14,7 @@ class ISO_2022 implements Recogniser {
1514
return 'ISO_2022';
1615
}
1716

18-
match(det: Context) {
17+
match(det: Context): Match | null {
1918
/**
2019
* Matching function shared among the 2022 detectors JP, CN and KR
2120
* Counts up the number of legal an unrecognized escape sequences in
@@ -29,16 +28,16 @@ class ISO_2022 implements Recogniser {
2928
* @return match quality, in the range of 0-100.
3029
*/
3130

32-
var i, j;
33-
var escN;
34-
var hits = 0;
35-
var misses = 0;
36-
var shifts = 0;
37-
var quality;
31+
let i, j;
32+
let escN;
33+
let hits = 0;
34+
let misses = 0;
35+
let shifts = 0;
36+
let quality;
3837

3938
// TODO: refactor me
40-
var text = det.fInputBytes;
41-
var textLen = det.fInputLen;
39+
const text = det.fInputBytes;
40+
const textLen = det.fInputLen;
4241

4342
scanInput: for (i = 0; i < textLen; i++) {
4443
if (text[i] == 0x1b) {
@@ -47,7 +46,7 @@ class ISO_2022 implements Recogniser {
4746
escN < this.escapeSequences.length;
4847
escN++
4948
) {
50-
var seq = this.escapeSequences[escN];
49+
const seq = this.escapeSequences[escN];
5150

5251
if (textLen - i < seq.length) continue checkEscapes;
5352

src/encoding/mbcs.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as chardet from '..';
22

33
describe('Multibyte Character Sets', () => {
4-
var base = __dirname + '/../test/data/encodings';
4+
const base = __dirname + '/../test/data/encodings';
55

66
it('should return Shift_JIS', () => {
77
expect(chardet.detectFileSync(base + '/shiftjis')).toBe('Shift_JIS');

src/encoding/mbcs.ts

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Context, Recogniser } from '.';
2-
var match = require('../match').default;
2+
import match, { Match } from '../match';
33

44
/**
55
* Binary search implementation (recursive)
@@ -18,7 +18,7 @@ function binarySearch(arr: number[], searchValue: number) {
1818
There is a bug in the above line;
1919
Joshua Bloch suggests the following replacement:
2020
*/
21-
var mid = Math.floor((left + right) >>> 1);
21+
const mid = Math.floor((left + right) >>> 1);
2222
if (searchValue > arr[mid]) return find(arr, searchValue, mid + 1, right);
2323

2424
if (searchValue < arr[mid]) return find(arr, searchValue, left, mid - 1);
@@ -68,7 +68,7 @@ class IteratedChar {
6868
this.done = true;
6969
return -1;
7070
}
71-
var byteValue = det.fRawInput[this.nextIndex++] & 0x00ff;
71+
const byteValue = det.fRawInput[this.nextIndex++] & 0x00ff;
7272
return byteValue;
7373
}
7474
}
@@ -97,23 +97,23 @@ class mbcs implements Recogniser {
9797
* bits 0-7: the match confidence, ranging from 0-100
9898
* bits 8-15: The match reason, an enum-like value.
9999
*/
100-
match(det: Context) {
101-
var singleByteCharCount = 0, //TODO Do we really need this?
100+
match(det: Context): Match | null {
101+
let singleByteCharCount = 0, //TODO Do we really need this?
102102
doubleByteCharCount = 0,
103103
commonCharCount = 0,
104104
badCharCount = 0,
105105
totalCharCount = 0,
106106
confidence = 0;
107107

108-
var iter = new IteratedChar();
108+
const iter = new IteratedChar();
109109

110110
detectBlock: {
111111
for (iter.reset(); this.nextChar(iter, det); ) {
112112
totalCharCount++;
113113
if (iter.error) {
114114
badCharCount++;
115115
} else {
116-
var cv = iter.charValue & 0xffffffff;
116+
const cv = iter.charValue & 0xffffffff;
117117

118118
if (cv <= 0xff) {
119119
singleByteCharCount++;
@@ -159,20 +159,17 @@ class mbcs implements Recogniser {
159159
}
160160

161161
if (this.commonChars == null) {
162-
// We have no statistics on frequently occuring characters.
162+
// We have no statistics on frequently occurring characters.
163163
// Assess confidence purely on having a reasonable number of
164164
// multi-byte characters (the more the better
165165
confidence = 30 + doubleByteCharCount - 20 * badCharCount;
166166
if (confidence > 100) {
167167
confidence = 100;
168168
}
169169
} else {
170-
//
171170
// Frequency of occurrence statistics exist.
172-
//
173-
// @ts-ignore
174-
var maxVal = Math.log(parseFloat(doubleByteCharCount) / 4);
175-
var scaleFactor = 90.0 / maxVal;
171+
const maxVal = Math.log(doubleByteCharCount / 4);
172+
const scaleFactor = 90.0 / maxVal;
176173
confidence = Math.floor(
177174
Math.log(commonCharCount + 1) * scaleFactor + 10
178175
);
@@ -278,14 +275,13 @@ export class sjis extends mbcs {
278275
iter.index = iter.nextIndex;
279276
iter.error = false;
280277

281-
var firstByte;
282-
firstByte = iter.charValue = iter.nextByte(det);
278+
const firstByte = (iter.charValue = iter.nextByte(det));
283279
if (firstByte < 0) return false;
284280

285281
if (firstByte <= 0x7f || (firstByte > 0xa0 && firstByte <= 0xdf))
286282
return true;
287283

288-
var secondByte = iter.nextByte(det);
284+
const secondByte = iter.nextByte(det);
289285
if (secondByte < 0) return false;
290286

291287
iter.charValue = (firstByte << 8) | secondByte;
@@ -418,14 +414,14 @@ export class big5 extends mbcs {
418414
iter.index = iter.nextIndex;
419415
iter.error = false;
420416

421-
var firstByte = (iter.charValue = iter.nextByte(det));
417+
const firstByte = (iter.charValue = iter.nextByte(det));
422418

423419
if (firstByte < 0) return false;
424420

425421
// single byte character.
426422
if (firstByte <= 0x7f || firstByte == 0xff) return true;
427423

428-
var secondByte = iter.nextByte(det);
424+
const secondByte = iter.nextByte(det);
429425

430426
if (secondByte < 0) return false;
431427

@@ -450,9 +446,9 @@ export class big5 extends mbcs {
450446
function eucNextChar(iter: IteratedChar, det: Context) {
451447
iter.index = iter.nextIndex;
452448
iter.error = false;
453-
var firstByte = 0;
454-
var secondByte = 0;
455-
var thirdByte = 0;
449+
let firstByte = 0;
450+
let secondByte = 0;
451+
let thirdByte = 0;
456452
//int fourthByte = 0;
457453
buildChar: {
458454
firstByte = iter.charValue = iter.nextByte(det);
@@ -763,10 +759,10 @@ export class gb_18030 extends mbcs {
763759
nextChar(iter: IteratedChar, det: Context) {
764760
iter.index = iter.nextIndex;
765761
iter.error = false;
766-
var firstByte = 0;
767-
var secondByte = 0;
768-
var thirdByte = 0;
769-
var fourthByte = 0;
762+
let firstByte = 0;
763+
let secondByte = 0;
764+
let thirdByte = 0;
765+
let fourthByte = 0;
770766
buildChar: {
771767
firstByte = iter.charValue = iter.nextByte(det);
772768
if (firstByte < 0) {

src/encoding/sbcs.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as chardet from '..';
22

33
describe('Singlebyte Character Sets', () => {
4-
var base = __dirname + '/../test/data/encodings';
4+
const base = __dirname + '/../test/data/encodings';
55

66
it('should return ISO-8859-1 (English)', () => {
77
expect(chardet.detectFileSync(base + '/iso88591_en')).toBe('ISO-8859-1');

0 commit comments

Comments
 (0)