react-simple-qr-code-scanner
Advanced tools
Comparing version 1.5.1 to 2.0.0-beta.1
{ | ||
"name": "react-simple-qr-code-scanner", | ||
"version": "1.5.1", | ||
"version": "2.0.0-beta.1", | ||
"description": "A super simple qr code scanner", | ||
"main": "index.js", | ||
"exports": { | ||
".": { | ||
"import": "./dist/index.mjs", | ||
"types": "./dist/index.d.ts" | ||
} | ||
}, | ||
"scripts": { | ||
"clean": "rm -rf dist", | ||
"build": "yarn clean && tsc && cp package.json README.md ./dist", | ||
"publishToNpm": "npm publish ./dist" | ||
"build": "tsup" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/mitchellston/qr-code-scanner" | ||
}, | ||
"files": [ | ||
"dist", | ||
"LICENSE", | ||
"README.md" | ||
], | ||
"keywords": [ | ||
@@ -25,2 +29,6 @@ "react", | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/mitchellston/qr-code-scanner" | ||
}, | ||
"author": { | ||
@@ -34,10 +42,16 @@ "name": "Mitchellston" | ||
"devDependencies": { | ||
"@types/react": "^17.0.52", | ||
"@types/react": "^17.0.62", | ||
"react": "^17.0.2", | ||
"react-dom": "^17.0.2", | ||
"typescript": "^4.8.4" | ||
"tsup": "^7.1.0", | ||
"typescript": "^4.9.5" | ||
}, | ||
"peerDependencies": { | ||
"react": "^17.0.2", | ||
"react-dom": "^17.0.2" | ||
}, | ||
"dependencies": { | ||
"@zxing/library": "^0.19.1" | ||
"@zxing/library": "^0.19.3", | ||
"superjson": "^1.12.4" | ||
} | ||
} |
@@ -17,3 +17,3 @@ # A simple qr-code scanner for react | ||
### Demo | ||
### Basic demo | ||
@@ -25,9 +25,9 @@ ```tsx | ||
<QrCodeScanner | ||
onResult={(result) => { | ||
onResult={(result, rawResult) => { | ||
console.log(result); | ||
}} | ||
Errors={(error) => { | ||
//console.log(error); | ||
console.log(error); | ||
}}, | ||
facingMode={"enviroment"} //or user | ||
facingMode={"environment"} //or user | ||
/> | ||
@@ -38,2 +38,46 @@ ); | ||
### Validating qr code result | ||
```tsx | ||
import { useState } from "react"; | ||
import { Exception, QrCodeScanner } from "react-simple-qr-code-scanner"; | ||
type QrCodeData = { | ||
foo: string; | ||
bar: number; | ||
}; | ||
function App() { | ||
return ( | ||
<> | ||
<QrCodeScanner | ||
validate={(data) => { | ||
if (!data || data == null || typeof data != "object") | ||
throw new Error("data is required"); | ||
if ( | ||
!Object.prototype.hasOwnProperty.call(data, "foo") || | ||
!("foo" in data) || | ||
data.foo == null || | ||
typeof data.foo != "string" | ||
) | ||
throw new Error("foo is required"); | ||
if ( | ||
!Object.prototype.hasOwnProperty.call(data, "bar") || | ||
!("bar" in data) || | ||
data.bar || | ||
typeof data.bar != "number" | ||
) | ||
throw new Error("bar is required"); | ||
return { foo: data.foo, bar: data.bar }; | ||
}} | ||
onResult={(result) => { | ||
console.log(result); // result will be of type IQrCodeData here (since the validation checks for this) | ||
}} | ||
onError={(errorScan) => { | ||
console.log(errorScan.message); // Get the error messages or any other error message | ||
}} | ||
/> | ||
</> | ||
); | ||
} | ||
``` | ||
## License | ||
@@ -40,0 +84,0 @@ |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
6805
53
85
4
5
5
2
+ Addedsuperjson@^1.12.4
+ Addedcopy-anything@3.0.5(transitive)
+ Addedis-what@4.1.16(transitive)
+ Addedjs-tokens@4.0.0(transitive)
+ Addedloose-envify@1.4.0(transitive)
+ Addedobject-assign@4.1.1(transitive)
+ Addedreact@17.0.2(transitive)
+ Addedreact-dom@17.0.2(transitive)
+ Addedscheduler@0.20.2(transitive)
+ Addedsuperjson@1.13.3(transitive)
Updated@zxing/library@^0.19.3