From 0b7edb39df81d4496d2688b4385139d17c4ca073 Mon Sep 17 00:00:00 2001 From: dyoshikawa <34151621+dyoshikawa@users.noreply.github.com> Date: Wed, 23 Nov 2022 12:53:11 +0900 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9Atype=20def=20of=20decodeFromImage()?= =?UTF-8?q?=20param=20(#23)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/index.ts b/src/index.ts index 5103962..f4c6023 100644 --- a/src/index.ts +++ b/src/index.ts @@ -229,7 +229,7 @@ class QrcodeDecoder { * refer to jsqr options: https://github.com/cozmo/jsQR */ async decodeFromImage( - img: HTMLImageElement, + img: HTMLImageElement | string, options: { crossOrigin?: string } = {}, ) { let imgDom: HTMLImageElement | null = null; @@ -237,12 +237,8 @@ class QrcodeDecoder { ...this.defaultOption, ...options, }; - if (+img.nodeType > 0) { - if (!img.src) { - throw new Error('The ImageElement must contain a src'); - } - imgDom = img; - } else if (typeof img === 'string') { + + if (typeof img === 'string') { imgDom = document.createElement('img'); if (options.crossOrigin) { imgDom.crossOrigin = options.crossOrigin; @@ -253,6 +249,11 @@ class QrcodeDecoder { imgDom!.onload = () => resolve(true); }); await proms(); + } else if (+img.nodeType > 0) { + if (!img.src) { + throw new Error('The ImageElement must contain a src'); + } + imgDom = img; } let code = null;