5 Commits
Author SHA1 Message Date
yugasun 9fa47676df 0.3.3 2022-11-23 11:56:17 +08:00
dyoshikawaandGitHub 0b7edb39df fix:type def of decodeFromImage() param (#23) 2022-11-23 11:53:11 +08:00
yugasun 8afbcdad33 chore: fix test ci 2022-10-11 14:39:25 +08:00
yugasun 0f2e84268c chore: add pnpm version 2022-10-11 14:15:15 +08:00
yugasun 33f115036f chore: update readme & ci 2022-10-11 14:08:21 +08:00
5 changed files with 30 additions and 24 deletions
+4
View File
@@ -9,6 +9,7 @@ on:
push:
branches:
- main
- master
- release/*
- feat/*
- fix/*
@@ -73,6 +74,9 @@ jobs:
- name: Install deps
run: pnpm install
- name: Build
run: pnpm run build
- name: Test
run: pnpm run test
+7 -7
View File
@@ -23,10 +23,10 @@ A tool for decoding qrcode.
## Guide
Use `npm` to install.
Use `pnpm` to install.
```bash
$ npm install --save qrcode-decoder
$ pnpm install --save qrcode-decoder
```
Using in webpack:
@@ -96,31 +96,31 @@ Stops the current `qr` from searching for a QRCode.
Install dependencies:
```bash
$ npm install
$ pnpm install
```
Build code:
```bash
$ npm run build
$ pnpm run build
```
Run unit test:
```bash
$ npm test
$ pnpm test
```
Modify version in `package.json`, run `release` script:
```bash
$ npm run release
$ pnpm run release
```
Publish
```bash
$ npm publish
$ pnpm publish
```
## License
+8 -8
View File
@@ -23,10 +23,10 @@
## 使用者指南
通过 npm 下载安装代码
通过 pnpm 下载安装代码
```bash
$ npm install --save qrcode-decoder
$ pnpm install --save qrcode-decoder
```
如果你是 webpack 等环境
@@ -96,31 +96,31 @@ qr.decodeFromCamera(videoElem).then((res) => {
首次运行需要先安装依赖
```bash
$ npm install
$ pnpm install
```
一键打包生成生产代码
```bash
$ npm run build
$ pnpm run build
```
运行单元测试,浏览器环境需要手动测试,位于`test/browser`
```bash
$ npm test
$ pnpm test
```
修改 package.json 中的版本号,修改 README.md 中的版本号,修改 CHANGELOG.md,然后发布新版
```bash
$ npm run release
$ pnpm run release
```
将新版本发布到 npm
将新版本发布到 pnpm
```bash
$ npm publish
$ pnpm publish
```
## License
+3 -2
View File
@@ -1,6 +1,6 @@
{
"name": "qrcode-decoder",
"version": "0.3.2",
"version": "0.3.3",
"description": "Tool for decoding qrcode",
"main": "dist/index.js",
"browser": "dist/index.min.js",
@@ -8,6 +8,7 @@
"module": "dist/index.esm.js",
"types": "dist/index.d.ts",
"sideEffects": false,
"packageManager": "pnpm@7.11.0",
"scripts": {
"build": "ts-node -P scripts/tsconfig.json scripts/bundle.ts commonjs,esm,aio && pnpm run dts && pnpm run copy-file",
"dts": "tsc src/index.ts --declaration --emitDeclarationOnly --outDir './dist'",
@@ -27,7 +28,7 @@
},
"lint-staged": {
"*.{ts,tsx,md}": [
"npm run prettier:fix",
"pnpm run prettier:fix",
"git add ."
]
},
+8 -7
View File
@@ -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;