@@ -4,8 +4,8 @@ export function getTypedArray(dataview: any, metadata: any) {
44 return new Int8Array ( dataview . buffer ) ;
55 break ;
66 case 'uint8' :
7- return new Uint8Array ( dataview . buffer ) ;
8- break ;
7+ return new Uint8Array ( dataview . buffer ) ;
8+ break ;
99 case 'int16' :
1010 return new Int16Array ( dataview . buffer ) ;
1111 break ;
@@ -34,18 +34,30 @@ export function getTypedArray(dataview: any, metadata: any) {
3434type Scalar = null | boolean | number | string ;
3535
3636namespace Scalar {
37- export
38- function isScalar ( x : any ) : x is Scalar {
39- return x === null || typeof x === "boolean" || typeof x === "number" || typeof x === "string" ;
37+ export function isScalar ( x : any ) : x is Scalar {
38+ return (
39+ x === null ||
40+ typeof x === 'boolean' ||
41+ typeof x === 'number' ||
42+ typeof x === 'string'
43+ ) ;
4044 }
4145}
4246
43- type TypedArray = Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array | Uint8ClampedArray | Float32Array | Float64Array ;
47+ type TypedArray =
48+ | Int8Array
49+ | Uint8Array
50+ | Int16Array
51+ | Uint16Array
52+ | Int32Array
53+ | Uint32Array
54+ | Uint8ClampedArray
55+ | Float32Array
56+ | Float64Array ;
4457
4558// Buffered argument
46- export
47- abstract class Arg {
48- abstract getItem ( idx : number ) : any ;
59+ export abstract class Arg {
60+ abstract getItem ( idx : number ) : any ;
4961
5062 length : number ;
5163}
@@ -58,7 +70,7 @@ class ScalarArg extends Arg {
5870 this . length = Infinity ;
5971 }
6072
61- getItem ( idx : number ) : any {
73+ getItem ( idx : number ) : any {
6274 return this . value ;
6375 }
6476
@@ -73,30 +85,28 @@ class BufferArg extends Arg {
7385 this . length = this . value . length ;
7486 }
7587
76- getItem ( idx : number ) : any {
88+ getItem ( idx : number ) : any {
7789 return this . value [ idx ] ;
7890 }
7991
8092 value : TypedArray ;
8193}
8294
83- export
84- function getArg ( metadata : any , buffers : any ) : Arg {
95+ export function getArg ( metadata : any , buffers : any ) : Arg {
8596 if ( Scalar . isScalar ( metadata ) ) {
8697 return new ScalarArg ( metadata ) ;
8798 }
8899
89100 if ( metadata [ 'idx' ] !== undefined ) {
90- return new BufferArg ( metadata , buffers [ metadata [ 'idx' ] ] )
101+ return new BufferArg ( metadata , buffers [ metadata [ 'idx' ] ] ) ;
91102 }
92103
93104 throw 'Could not process argument ' + metadata ;
94105}
95106
96- export
97- async function toBlob ( canvas : HTMLCanvasElement ) : Promise < Blob > {
107+ export async function toBlob ( canvas : HTMLCanvasElement ) : Promise < Blob > {
98108 return new Promise < Blob > ( ( resolve , reject ) => {
99- canvas . toBlob ( ( blob ) => {
109+ canvas . toBlob ( blob => {
100110 if ( blob == null ) {
101111 return reject ( 'Unable to create blob' ) ;
102112 }
@@ -106,35 +116,37 @@ async function toBlob(canvas: HTMLCanvasElement) : Promise<Blob> {
106116 } ) ;
107117}
108118
109- export
110- async function toBytes ( canvas : HTMLCanvasElement ) : Promise < Uint8ClampedArray > {
119+ export async function toBytes (
120+ canvas : HTMLCanvasElement
121+ ) : Promise < Uint8ClampedArray > {
111122 const blob = await toBlob ( canvas ) ;
112123
113124 return new Promise < Uint8ClampedArray > ( ( resolve , reject ) => {
114125 const reader = new FileReader ( ) ;
115126
116127 reader . onloadend = ( ) => {
117- if ( typeof reader . result == 'string' || reader . result == null ) {
118- return reject ( 'Unable to read blob' ) ;
119- }
128+ if ( typeof reader . result == 'string' || reader . result == null ) {
129+ return reject ( 'Unable to read blob' ) ;
130+ }
120131
121- const bytes = new Uint8ClampedArray ( reader . result ) ;
122- resolve ( bytes ) ;
132+ const bytes = new Uint8ClampedArray ( reader . result ) ;
133+ resolve ( bytes ) ;
123134 } ;
124135 reader . readAsArrayBuffer ( blob ) ;
125136 } ) ;
126137}
127138
128- export
129- async function fromBytes ( array : Uint8ClampedArray ) : Promise < HTMLImageElement > {
139+ export async function fromBytes (
140+ array : Uint8ClampedArray
141+ ) : Promise < HTMLImageElement > {
130142 const blob = new Blob ( [ array ] ) ;
131143
132144 return new Promise < HTMLImageElement > ( ( resolve , reject ) => {
133145 const img = new Image ( ) ;
134146
135147 img . onload = ( ) => {
136148 resolve ( img ) ;
137- }
149+ } ;
138150
139151 img . src = URL . createObjectURL ( blob ) ;
140152 } ) ;
0 commit comments