@@ -19,7 +19,7 @@ export function encode(value: unknown) {
1919 let lastLength : number ;
2020 let offset = 0 ;
2121
22- function prepareWrite ( length : number ) {
22+ function prepareWrite ( length : number ) : DataView {
2323 let newByteLength = data . byteLength ;
2424 const requiredLength = offset + length ;
2525 while ( newByteLength < requiredLength )
@@ -39,33 +39,33 @@ export function encode(value: unknown) {
3939 function commitWrite ( _ ?: unknown ) {
4040 offset += lastLength ;
4141 }
42- function writeFloat64 ( value ) {
42+ function writeFloat64 ( value : number ) : void {
4343 commitWrite ( prepareWrite ( 8 ) . setFloat64 ( offset , value ) ) ;
4444 }
45- function writeUint8 ( value ) {
45+ function writeUint8 ( value : number ) : void {
4646 commitWrite ( prepareWrite ( 1 ) . setUint8 ( offset , value ) ) ;
4747 }
48- function writeUint8Array ( value ) {
48+ function writeUint8Array ( value : number [ ] | Uint8Array ) : void {
4949 const dataView = prepareWrite ( value . length ) ;
5050 for ( let i = 0 ; i < value . length ; ++ i )
5151 dataView . setUint8 ( offset + i , value [ i ] ) ;
5252 commitWrite ( ) ;
5353 }
54- function writeUint16 ( value ) {
54+ function writeUint16 ( value : number ) : void {
5555 commitWrite ( prepareWrite ( 2 ) . setUint16 ( offset , value ) ) ;
5656 }
57- function writeUint32 ( value ) {
57+ function writeUint32 ( value : number ) : void {
5858 commitWrite ( prepareWrite ( 4 ) . setUint32 ( offset , value ) ) ;
5959 }
60- function writeUint64 ( value ) {
60+ function writeUint64 ( value : number ) : void {
6161 const low = value % POW_2_32 ;
6262 const high = ( value - low ) / POW_2_32 ;
6363 const dataView = prepareWrite ( 8 ) ;
6464 dataView . setUint32 ( offset , high ) ;
6565 dataView . setUint32 ( offset + 4 , low ) ;
6666 commitWrite ( ) ;
6767 }
68- function writeTypeAndLength ( type , length ) {
68+ function writeTypeAndLength ( type : number , length : number ) : void {
6969 if ( length < 24 ) {
7070 writeUint8 ( type << 5 | length ) ;
7171 } else if ( length < 0x100 ) {
@@ -83,8 +83,9 @@ export function encode(value: unknown) {
8383 }
8484 }
8585
86- function encodeItem ( value ) {
87- let i ;
86+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
87+ function encodeItem ( value : any ) : void {
88+ let i : number ;
8889
8990 if ( value === false )
9091 return writeUint8 ( 0xf4 ) ;
@@ -108,7 +109,7 @@ export function encode(value: unknown) {
108109 }
109110
110111 case "string" : {
111- const utf8data = [ ] ;
112+ const utf8data : number [ ] = [ ] ;
112113 for ( i = 0 ; i < value . length ; ++ i ) {
113114 let charCode = value . charCodeAt ( i ) ;
114115 if ( charCode < 0x80 ) {
@@ -137,7 +138,7 @@ export function encode(value: unknown) {
137138 }
138139
139140 default : {
140- let length ;
141+ let length : number ;
141142 if ( Array . isArray ( value ) ) {
142143 length = value . length ;
143144 writeTypeAndLength ( 4 , length ) ;
@@ -147,7 +148,7 @@ export function encode(value: unknown) {
147148 writeTypeAndLength ( 2 , value . length ) ;
148149 writeUint8Array ( value ) ;
149150 } else {
150- const keys = Object . keys ( value ) ;
151+ const keys = Object . keys ( value as Record < string , unknown > ) ;
151152 length = keys . length ;
152153 writeTypeAndLength ( 5 , length ) ;
153154 for ( i = 0 ; i < length ; ++ i ) {
@@ -181,11 +182,11 @@ export function decode(data: ArrayBuffer | SharedArrayBuffer, tagger?: Function,
181182 if ( typeof simpleValue !== "function" )
182183 simpleValue = function ( ) { return undefined ; } ;
183184
184- function commitRead ( length , value ) {
185+ function commitRead < T extends number | Uint8Array > ( length : number , value : T ) : T {
185186 offset += length ;
186187 return value ;
187188 }
188- function readArrayBuffer ( length ) {
189+ function readArrayBuffer ( length : number ) : Uint8Array {
189190 return commitRead ( length , new Uint8Array ( data , offset , length ) ) ;
190191 }
191192 function readFloat16 ( ) {
@@ -207,22 +208,22 @@ export function decode(data: ArrayBuffer | SharedArrayBuffer, tagger?: Function,
207208 tempDataView . setUint32 ( 0 , sign << 16 | exponent << 13 | fraction << 13 ) ;
208209 return tempDataView . getFloat32 ( 0 ) ;
209210 }
210- function readFloat32 ( ) {
211+ function readFloat32 ( ) : number {
211212 return commitRead ( 4 , dataView . getFloat32 ( offset ) ) ;
212213 }
213- function readFloat64 ( ) {
214+ function readFloat64 ( ) : number {
214215 return commitRead ( 8 , dataView . getFloat64 ( offset ) ) ;
215216 }
216- function readUint8 ( ) {
217+ function readUint8 ( ) : number {
217218 return commitRead ( 1 , dataView . getUint8 ( offset ) ) ;
218219 }
219- function readUint16 ( ) {
220+ function readUint16 ( ) : number {
220221 return commitRead ( 2 , dataView . getUint16 ( offset ) ) ;
221222 }
222- function readUint32 ( ) {
223+ function readUint32 ( ) : number {
223224 return commitRead ( 4 , dataView . getUint32 ( offset ) ) ;
224225 }
225- function readUint64 ( ) {
226+ function readUint64 ( ) : number {
226227 return readUint32 ( ) * POW_2_32 + readUint32 ( ) ;
227228 }
228229 function readBreak ( ) {
@@ -231,7 +232,7 @@ export function decode(data: ArrayBuffer | SharedArrayBuffer, tagger?: Function,
231232 offset += 1 ;
232233 return true ;
233234 }
234- function readLength ( additionalInformation ) {
235+ function readLength ( additionalInformation : number ) : number {
235236 if ( additionalInformation < 24 )
236237 return additionalInformation ;
237238 if ( additionalInformation === 24 )
@@ -246,7 +247,7 @@ export function decode(data: ArrayBuffer | SharedArrayBuffer, tagger?: Function,
246247 return - 1 ;
247248 throw "Invalid length encoding" ;
248249 }
249- function readIndefiniteStringLength ( majorType ) {
250+ function readIndefiniteStringLength ( majorType : number ) : number {
250251 const initialByte = readUint8 ( ) ;
251252 if ( initialByte === 0xff )
252253 return - 1 ;
@@ -256,7 +257,7 @@ export function decode(data: ArrayBuffer | SharedArrayBuffer, tagger?: Function,
256257 return length ;
257258 }
258259
259- function appendUtf16Data ( utf16data , length ) {
260+ function appendUtf16Data ( utf16data : Array < number > , length : number ) : void {
260261 for ( let i = 0 ; i < length ; ++ i ) {
261262 let value = readUint8 ( ) ;
262263 if ( value & 0x80 ) {
@@ -292,8 +293,8 @@ export function decode(data: ArrayBuffer | SharedArrayBuffer, tagger?: Function,
292293 const initialByte = readUint8 ( ) ;
293294 const majorType = initialByte >> 5 ;
294295 const additionalInformation = initialByte & 0x1f ;
295- let i ;
296- let length ;
296+ let i : number ;
297+ let length : number ;
297298
298299 if ( majorType === 7 ) {
299300 switch ( additionalInformation ) {
@@ -321,7 +322,7 @@ export function decode(data: ArrayBuffer | SharedArrayBuffer, tagger?: Function,
321322
322323 case 2 : {
323324 if ( length < 0 ) {
324- const elements = [ ] ;
325+ const elements : Uint8Array [ ] = [ ] ;
325326 let fullArrayLength = 0 ;
326327 while ( ( length = readIndefiniteStringLength ( majorType ) ) >= 0 ) {
327328 fullArrayLength += length ;
@@ -339,7 +340,7 @@ export function decode(data: ArrayBuffer | SharedArrayBuffer, tagger?: Function,
339340 }
340341
341342 case 3 : {
342- const utf16data = [ ] ;
343+ const utf16data : number [ ] = [ ] ;
343344 if ( length < 0 ) {
344345 while ( ( length = readIndefiniteStringLength ( majorType ) ) >= 0 )
345346 appendUtf16Data ( utf16data , length ) ;
0 commit comments