@@ -21,14 +21,14 @@ export function encode(value: any) {
2121
2222 function prepareWrite ( length : number ) {
2323 let newByteLength = data . byteLength ;
24- let requiredLength = offset + length ;
24+ const requiredLength = offset + length ;
2525 while ( newByteLength < requiredLength )
2626 newByteLength <<= 1 ;
2727 if ( newByteLength !== data . byteLength ) {
28- let oldDataView = dataView ;
28+ const oldDataView = dataView ;
2929 data = new ArrayBuffer ( newByteLength ) ;
3030 dataView = new DataView ( data ) ;
31- let uint32count = ( offset + 3 ) >> 2 ;
31+ const uint32count = ( offset + 3 ) >> 2 ;
3232 for ( let i = 0 ; i < uint32count ; ++ i )
3333 dataView . setUint32 ( i << 2 , oldDataView . getUint32 ( i << 2 ) ) ;
3434 }
@@ -46,7 +46,7 @@ export function encode(value: any) {
4646 commitWrite ( prepareWrite ( 1 ) . setUint8 ( offset , value ) ) ;
4747 }
4848 function writeUint8Array ( value ) {
49- let dataView = prepareWrite ( value . length ) ;
49+ const dataView = prepareWrite ( value . length ) ;
5050 for ( let i = 0 ; i < value . length ; ++ i )
5151 dataView . setUint8 ( offset + i , value [ i ] ) ;
5252 commitWrite ( ) ;
@@ -58,9 +58,9 @@ export function encode(value: any) {
5858 commitWrite ( prepareWrite ( 4 ) . setUint32 ( offset , value ) ) ;
5959 }
6060 function writeUint64 ( value ) {
61- let low = value % POW_2_32 ;
62- let high = ( value - low ) / POW_2_32 ;
63- let dataView = prepareWrite ( 8 ) ;
61+ const low = value % POW_2_32 ;
62+ const high = ( value - low ) / POW_2_32 ;
63+ const dataView = prepareWrite ( 8 ) ;
6464 dataView . setUint32 ( offset , high ) ;
6565 dataView . setUint32 ( offset + 4 , low ) ;
6666 commitWrite ( ) ;
@@ -107,7 +107,7 @@ export function encode(value: any) {
107107 return writeFloat64 ( value ) ;
108108
109109 case "string" :
110- let utf8data = [ ] ;
110+ const utf8data = [ ] ;
111111 for ( i = 0 ; i < value . length ; ++ i ) {
112112 let charCode = value . charCodeAt ( i ) ;
113113 if ( charCode < 0x80 ) {
@@ -145,11 +145,11 @@ export function encode(value: any) {
145145 writeTypeAndLength ( 2 , value . length ) ;
146146 writeUint8Array ( value ) ;
147147 } else {
148- let keys = Object . keys ( value ) ;
148+ const keys = Object . keys ( value ) ;
149149 length = keys . length ;
150150 writeTypeAndLength ( 5 , length ) ;
151151 for ( i = 0 ; i < length ; ++ i ) {
152- let key = keys [ i ] ;
152+ const key = keys [ i ] ;
153153 encodeItem ( key ) ;
154154 encodeItem ( value [ key ] ) ;
155155 }
@@ -162,15 +162,15 @@ export function encode(value: any) {
162162 if ( "slice" in data )
163163 return data . slice ( 0 , offset ) ;
164164
165- let ret = new ArrayBuffer ( offset ) ;
166- let retView = new DataView ( ret ) ;
165+ const ret = new ArrayBuffer ( offset ) ;
166+ const retView = new DataView ( ret ) ;
167167 for ( let i = 0 ; i < offset ; ++ i )
168168 retView . setUint8 ( i , dataView . getUint8 ( i ) ) ;
169169 return ret ;
170170}
171171
172172export function decode ( data : any , tagger ?: Function , simpleValue ?: Function ) {
173- let dataView = new DataView ( data ) ;
173+ const dataView = new DataView ( data ) ;
174174 let offset = 0 ;
175175
176176 if ( typeof tagger !== "function" )
@@ -186,13 +186,13 @@ export function decode(data: any, tagger?: Function, simpleValue?: Function) {
186186 return commitRead ( length , new Uint8Array ( data , offset , length ) ) ;
187187 }
188188 function readFloat16 ( ) {
189- let tempArrayBuffer = new ArrayBuffer ( 4 ) ;
190- let tempDataView = new DataView ( tempArrayBuffer ) ;
191- let value = readUint16 ( ) ;
189+ const tempArrayBuffer = new ArrayBuffer ( 4 ) ;
190+ const tempDataView = new DataView ( tempArrayBuffer ) ;
191+ const value = readUint16 ( ) ;
192192
193- let sign = value & 0x8000 ;
193+ const sign = value & 0x8000 ;
194194 let exponent = value & 0x7c00 ;
195- let fraction = value & 0x03ff ;
195+ const fraction = value & 0x03ff ;
196196
197197 if ( exponent === 0x7c00 )
198198 exponent = 0xff << 10 ;
@@ -244,10 +244,10 @@ export function decode(data: any, tagger?: Function, simpleValue?: Function) {
244244 throw "Invalid length encoding" ;
245245 }
246246 function readIndefiniteStringLength ( majorType ) {
247- let initialByte = readUint8 ( ) ;
247+ const initialByte = readUint8 ( ) ;
248248 if ( initialByte === 0xff )
249249 return - 1 ;
250- let length = readLength ( initialByte & 0x1f ) ;
250+ const length = readLength ( initialByte & 0x1f ) ;
251251 if ( length < 0 || ( initialByte >> 5 ) !== majorType )
252252 throw "Invalid indefinite length element" ;
253253 return length ;
@@ -286,9 +286,9 @@ export function decode(data: any, tagger?: Function, simpleValue?: Function) {
286286 }
287287
288288 function decodeItem ( ) {
289- let initialByte = readUint8 ( ) ;
290- let majorType = initialByte >> 5 ;
291- let additionalInformation = initialByte & 0x1f ;
289+ const initialByte = readUint8 ( ) ;
290+ const majorType = initialByte >> 5 ;
291+ const additionalInformation = initialByte & 0x1f ;
292292 let i ;
293293 let length ;
294294
@@ -314,13 +314,13 @@ export function decode(data: any, tagger?: Function, simpleValue?: Function) {
314314 return - 1 - length ;
315315 case 2 :
316316 if ( length < 0 ) {
317- let elements = [ ] ;
317+ const elements = [ ] ;
318318 let fullArrayLength = 0 ;
319319 while ( ( length = readIndefiniteStringLength ( majorType ) ) >= 0 ) {
320320 fullArrayLength += length ;
321321 elements . push ( readArrayBuffer ( length ) ) ;
322322 }
323- let fullArray = new Uint8Array ( fullArrayLength ) ;
323+ const fullArray = new Uint8Array ( fullArrayLength ) ;
324324 let fullArrayOffset = 0 ;
325325 for ( i = 0 ; i < elements . length ; ++ i ) {
326326 fullArray . set ( elements [ i ] , fullArrayOffset ) ;
@@ -330,7 +330,7 @@ export function decode(data: any, tagger?: Function, simpleValue?: Function) {
330330 }
331331 return readArrayBuffer ( length ) ;
332332 case 3 :
333- let utf16data = [ ] ;
333+ const utf16data = [ ] ;
334334 if ( length < 0 ) {
335335 while ( ( length = readIndefiniteStringLength ( majorType ) ) >= 0 )
336336 appendUtf16Data ( utf16data , length ) ;
@@ -350,9 +350,9 @@ export function decode(data: any, tagger?: Function, simpleValue?: Function) {
350350 }
351351 return retArray ;
352352 case 5 :
353- let retObject = { } ;
353+ const retObject = { } ;
354354 for ( i = 0 ; i < length || length < 0 && ! readBreak ( ) ; ++ i ) {
355- let key = decodeItem ( ) ;
355+ const key = decodeItem ( ) ;
356356 retObject [ key ] = decodeItem ( ) ;
357357 }
358358 return retObject ;
@@ -374,7 +374,7 @@ export function decode(data: any, tagger?: Function, simpleValue?: Function) {
374374 }
375375 }
376376
377- let ret = decodeItem ( ) ;
377+ const ret = decodeItem ( ) ;
378378 if ( offset !== data . byteLength )
379379 throw "Remaining bytes" ;
380380 return ret ;
0 commit comments