Skip to content

Commit 0b7edb3

Browse files
authored
fix:type def of decodeFromImage() param (#23)
1 parent 8afbcda commit 0b7edb3

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/index.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -229,20 +229,16 @@ class QrcodeDecoder {
229229
* refer to jsqr options: https://github.com/cozmo/jsQR
230230
*/
231231
async decodeFromImage(
232-
img: HTMLImageElement,
232+
img: HTMLImageElement | string,
233233
options: { crossOrigin?: string } = {},
234234
) {
235235
let imgDom: HTMLImageElement | null = null;
236236
const opts = {
237237
...this.defaultOption,
238238
...options,
239239
};
240-
if (+img.nodeType > 0) {
241-
if (!img.src) {
242-
throw new Error('The ImageElement must contain a src');
243-
}
244-
imgDom = img;
245-
} else if (typeof img === 'string') {
240+
241+
if (typeof img === 'string') {
246242
imgDom = document.createElement('img');
247243
if (options.crossOrigin) {
248244
imgDom.crossOrigin = options.crossOrigin;
@@ -253,6 +249,11 @@ class QrcodeDecoder {
253249
imgDom!.onload = () => resolve(true);
254250
});
255251
await proms();
252+
} else if (+img.nodeType > 0) {
253+
if (!img.src) {
254+
throw new Error('The ImageElement must contain a src');
255+
}
256+
imgDom = img;
256257
}
257258

258259
let code = null;

0 commit comments

Comments
 (0)