11import { 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 {
450446function 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 ) {
0 commit comments