1 Commits
Author SHA1 Message Date
yugasun dae11ab1bb 0.3.1 2022-10-11 14:00:04 +08:00
5 changed files with 25 additions and 31 deletions
-4
View File
@@ -9,7 +9,6 @@ on:
push: push:
branches: branches:
- main - main
- master
- release/* - release/*
- feat/* - feat/*
- fix/* - fix/*
@@ -74,9 +73,6 @@ jobs:
- name: Install deps - name: Install deps
run: pnpm install run: pnpm install
- name: Build
run: pnpm run build
- name: Test - name: Test
run: pnpm run test run: pnpm run test
+7 -7
View File
@@ -23,10 +23,10 @@ A tool for decoding qrcode.
## Guide ## Guide
Use `pnpm` to install. Use `npm` to install.
```bash ```bash
$ pnpm install --save qrcode-decoder $ npm install --save qrcode-decoder
``` ```
Using in webpack: Using in webpack:
@@ -96,31 +96,31 @@ Stops the current `qr` from searching for a QRCode.
Install dependencies: Install dependencies:
```bash ```bash
$ pnpm install $ npm install
``` ```
Build code: Build code:
```bash ```bash
$ pnpm run build $ npm run build
``` ```
Run unit test: Run unit test:
```bash ```bash
$ pnpm test $ npm test
``` ```
Modify version in `package.json`, run `release` script: Modify version in `package.json`, run `release` script:
```bash ```bash
$ pnpm run release $ npm run release
``` ```
Publish Publish
```bash ```bash
$ pnpm publish $ npm publish
``` ```
## License ## License
+8 -8
View File
@@ -23,10 +23,10 @@
## 使用者指南 ## 使用者指南
通过 pnpm 下载安装代码 通过 npm 下载安装代码
```bash ```bash
$ pnpm install --save qrcode-decoder $ npm install --save qrcode-decoder
``` ```
如果你是 webpack 等环境 如果你是 webpack 等环境
@@ -96,31 +96,31 @@ qr.decodeFromCamera(videoElem).then((res) => {
首次运行需要先安装依赖 首次运行需要先安装依赖
```bash ```bash
$ pnpm install $ npm install
``` ```
一键打包生成生产代码 一键打包生成生产代码
```bash ```bash
$ pnpm run build $ npm run build
``` ```
运行单元测试,浏览器环境需要手动测试,位于`test/browser` 运行单元测试,浏览器环境需要手动测试,位于`test/browser`
```bash ```bash
$ pnpm test $ npm test
``` ```
修改 package.json 中的版本号,修改 README.md 中的版本号,修改 CHANGELOG.md,然后发布新版 修改 package.json 中的版本号,修改 README.md 中的版本号,修改 CHANGELOG.md,然后发布新版
```bash ```bash
$ pnpm run release $ npm run release
``` ```
将新版本发布到 pnpm 将新版本发布到 npm
```bash ```bash
$ pnpm publish $ npm publish
``` ```
## License ## License
+3 -4
View File
@@ -1,6 +1,6 @@
{ {
"name": "qrcode-decoder", "name": "qrcode-decoder",
"version": "0.3.3", "version": "0.3.1",
"description": "Tool for decoding qrcode", "description": "Tool for decoding qrcode",
"main": "dist/index.js", "main": "dist/index.js",
"browser": "dist/index.min.js", "browser": "dist/index.min.js",
@@ -8,9 +8,8 @@
"module": "dist/index.esm.js", "module": "dist/index.esm.js",
"types": "dist/index.d.ts", "types": "dist/index.d.ts",
"sideEffects": false, "sideEffects": false,
"packageManager": "pnpm@7.11.0",
"scripts": { "scripts": {
"build": "ts-node -P scripts/tsconfig.json scripts/bundle.ts commonjs,esm,aio && pnpm run dts && pnpm run copy-file", "build": "ts-node -P scripts/tsconfig.json scripts/bundle.ts commonjs,esm,aio && npm run copy-file",
"dts": "tsc src/index.ts --declaration --emitDeclarationOnly --outDir './dist'", "dts": "tsc src/index.ts --declaration --emitDeclarationOnly --outDir './dist'",
"prettier": "prettier --check '**/*.{ts,tsx,md}' --config .prettierrc", "prettier": "prettier --check '**/*.{ts,tsx,md}' --config .prettierrc",
"prettier:fix": "prettier --write '**/*.{ts,tsx,md}' --config .prettierrc", "prettier:fix": "prettier --write '**/*.{ts,tsx,md}' --config .prettierrc",
@@ -28,7 +27,7 @@
}, },
"lint-staged": { "lint-staged": {
"*.{ts,tsx,md}": [ "*.{ts,tsx,md}": [
"pnpm run prettier:fix", "npm run prettier:fix",
"git add ." "git add ."
] ]
}, },
+7 -8
View File
@@ -229,7 +229,7 @@ class QrcodeDecoder {
* refer to jsqr options: https://github.com/cozmo/jsQR * refer to jsqr options: https://github.com/cozmo/jsQR
*/ */
async decodeFromImage( async decodeFromImage(
img: HTMLImageElement | string, img: HTMLImageElement,
options: { crossOrigin?: string } = {}, options: { crossOrigin?: string } = {},
) { ) {
let imgDom: HTMLImageElement | null = null; let imgDom: HTMLImageElement | null = null;
@@ -237,8 +237,12 @@ class QrcodeDecoder {
...this.defaultOption, ...this.defaultOption,
...options, ...options,
}; };
if (+img.nodeType > 0) {
if (typeof img === 'string') { if (!img.src) {
throw new Error('The ImageElement must contain a src');
}
imgDom = img;
} else if (typeof img === 'string') {
imgDom = document.createElement('img'); imgDom = document.createElement('img');
if (options.crossOrigin) { if (options.crossOrigin) {
imgDom.crossOrigin = options.crossOrigin; imgDom.crossOrigin = options.crossOrigin;
@@ -249,11 +253,6 @@ class QrcodeDecoder {
imgDom!.onload = () => resolve(true); imgDom!.onload = () => resolve(true);
}); });
await proms(); await proms();
} else if (+img.nodeType > 0) {
if (!img.src) {
throw new Error('The ImageElement must contain a src');
}
imgDom = img;
} }
let code = null; let code = null;