Installations
npm install zxing-library-with-attempts
Developer Guide
Typescript
No
Module System
CommonJS
Min. Node Version
>= 8.9.0
Node Version
10.15.3
NPM Version
6.13.1
Score
78.5
Supply Chain
98.8
Quality
74.7
Maintenance
100
Vulnerability
99.6
License
Releases
Contributors
Languages
TypeScript (94.15%)
Java (5.69%)
JavaScript (0.16%)
Developer
Download Statistics
Total Downloads
4,549
Last Day
1
Last Week
3
Last Month
15
Last Year
2,766
GitHub Statistics
2,536 Stars
1,211 Commits
548 Forks
46 Watching
14 Branches
56 Contributors
Package Meta Information
Latest Version
0.16.0
Package Id
zxing-library-with-attempts@0.16.0
Unpacked Size
3.86 MB
Size
650.00 kB
File Count
763
NPM Version
6.13.1
Node Version
10.15.3
Total Downloads
Cumulative downloads
Total Downloads
4,549
Last day
0%
1
Compared to previous day
Last week
200%
3
Compared to previous week
Last month
-96.1%
15
Compared to previous month
Last year
844%
2,766
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
2
Dev Dependencies
41
Optional Dependencies
1
ZXing
Runs on your favorite ECMAScript ecosystem
If it doesn't, we gonna make it.
What is ZXing?
ZXing ("zebra crossing") is an open-source, multi-format 1D/2D barcode image processing library implemented in Java, with ports to other languages.
Supported Formats
See Projects and Milestones for what is currently done and what's planned next. 👀
1D product | 1D industrial | 2D |
---|---|---|
Code 39 | QR Code | |
Data Matrix | ||
EAN-8 | Code 128 | |
EAN-13 | ||
ITF | ||
RSS-14 | ||
* In progress, may have open PR.
Status
Demo
See Live Preview in browser.
Note: All the examples are using ES6, be sure is supported in your browser or modify as needed, Chrome recommended.
Installation
npm i @zxing/library --save
or
yarn add @zxing/library
Usage
Use on browser with ES6 modules:
1<script type="module"> 2 import { BrowserQRCodeReader } from '@zxing/library'; 3 4 const codeReader = new BrowserQRCodeReader(); 5 const img = document.getElementById('img'); 6 7 try { 8 const result = await codeReader.decodeFromImage(img); 9 } catch (err) { 10 console.error(err); 11 } 12 13 console.log(result); 14</script>
Or asynchronously:
1<script type="module"> 2 import('@zxing/library').then({ BrowserQRCodeReader } => { 3 4 const codeReader = new BrowserQRCodeReader(); 5 const img = document.getElementById('img'); 6 7 try { 8 const result = await codeReader.decodeFromImage(img); 9 } catch (err) { 10 console.error(err); 11 } 12 13 console.log(result); 14 15 }); 16</script>
Use on browser with AMD:
1<script type="text/javascript" src="https://unpkg.com/requirejs"></script> 2<script type="text/javascript"> 3 require(['@zxing/library'], ZXing => { 4 const codeReader = new ZXing.BrowserQRCodeReader(); 5 const img = document.getElementById('img'); 6 7 try { 8 const result = await codeReader.decodeFromImage(img); 9 } catch (err) { 10 console.error(err); 11 } 12 13 console.log(result); 14 }); 15</script>
Use on browser with UMD:
1<script type="text/javascript" src="https://unpkg.com/@zxing/library@latest"></script> 2<script type="text/javascript"> 3 window.addEventListener('load', () => { 4 const codeReader = new ZXing.BrowserQRCodeReader(); 5 const img = document.getElementById('img'); 6 7 try { 8 const result = await codeReader.decodeFromImage(img); 9 } catch (err) { 10 console.error(err); 11 } 12 13 console.log(result); 14 }); 15</script>
Use outside the browser with CommonJS:
1const { MultiFormatReader, BarcodeFormat } = require('@zxing/library/esm5'); // use this path since v0.5.1 2 3const hints = new Map(); 4const formats = [BarcodeFormat.QR_CODE, BarcodeFormat.DATA_MATRIX/*, ...*/]; 5 6hints.set(DecodeHintType.POSSIBLE_FORMATS, formats); 7 8const reader = new MultiFormatReader(); 9 10reader.setHints(hints); 11 12const luminanceSource = new RGBLuminanceSource(imgWidth, imgHeight, imgByteArray); 13const binaryBitmap = new BinaryBitmap(new HybridBinarizer(luminanceSource)); 14 15reader.decode(binaryBitmap);
Browser Support
The browser layer is using the MediaDevices web API which is not supported by older browsers.
You can use external polyfills like WebRTC adapter to increase browser compatibility.
Also, note that the library is using the TypedArray
(Int32Array
, Uint8ClampedArray
, etc.) which are not available in older browsers (e.g. Android 4 default browser).
You can use core-js to add support to these browsers.
Scanning from Video Camera
To display the input from the video camera you will need to add a video element in the HTML page:
1<video 2 id="video" 3 width="300" 4 height="200" 5 style="border: 1px solid gray" 6></video>
To start decoding, first obtain a list of video input devices with:
1const codeReader = new ZXing.BrowserQRCodeReader(); 2 3codeReader 4 .listVideoInputDevices() 5 .then(videoInputDevices => { 6 videoInputDevices.forEach(device => 7 console.log(`${device.label}, ${device.deviceId}`) 8 ); 9 }) 10 .catch(err => console.error(err));
If there is just one input device you can use the first deviceId
and the video element id (in the example below is also 'video') to decode:
1const firstDeviceId = videoInputDevices[0].deviceId; 2 3codeReader 4 .decodeFromInputVideoDevice(firstDeviceId, 'video') 5 .then(result => console.log(result.text)) 6 .catch(err => console.error(err));
If there are more input devices then you will need to chose one for codeReader.decodeFromInputVideoDevice
device id parameter.
You can also provide undefined
for the device id parameter in which case the library will automatically choose the camera, preferring the main (environment facing) camera if more are available:
1codeReader 2 .decodeFromInputVideoDevice(undefined, 'video') 3 .then(result => console.log(result.text)) 4 .catch(err => console.error(err));
Scanning from Video File
Similar as above you can use a video element in the HTML page:
1<video 2 id="video" 3 width="300" 4 height="200" 5 style="border: 1px solid gray" 6></video>
And to decode the video from an url:
1const codeReader = new ZXing.BrowserQRCodeReader(); 2const videoSrc = 'your url to a video'; 3 4codeReader 5 .decodeFromVideo('video', videoSrc) 6 .then(result => console.log(result.text)) 7 .catch(err => console.error(err));
You can also decode the video url without showing it in the page, in this case no video
element is needed in HTML.
1codeReader 2 .decodeFromVideoUrl(videoUrl) 3 .then(result => console.log(result.text)) 4 .catch(err => console.error(err)); 5 6// or alternatively 7 8codeReader 9 .decodeFromVideo(null, videoUrl) 10 .then(result => console.log(result.text)) 11 .catch(err => console.error(err));
Scanning from Image
Similar as above you can use a img element in the HTML page (with src attribute set):
1<img 2 id="img" 3 src="qrcode-image.png" 4 width="200" 5 height="300" 6 style="border: 1px solid gray" 7/>
And to decode the image:
1const codeReader = new ZXing.BrowserQRCodeReader(); 2const img = document.getElementById('img'); 3 4codeReader 5 .decodeFromImage(img) 6 .then(result => console.log(result.text)) 7 .catch(err => console.error(err));
You can also decode the image url without showing it in the page, in this case no img
element is needed in HTML:
1const imgSrc = 'url to image'; 2 3codeReader 4 .decodeFromImage(undefined, imgSrc) 5 .then(result => console.log(result.text)) 6 .catch(err => console.error(err));
Or decode the image url directly from an url, with an img
element in page (notice no src
attribute is set for img
element):
1<img 2 id="img-to-decode" 3 width="200" 4 height="300" 5 style="border: 1px solid gray" 6/>
1const imgSrc = 'url to image'; 2const imgDomId = 'img-to-decode'; 3 4codeReader 5 .decodeFromImage(imgDomId, imgSrc) 6 .then(result => console.log(result.text)) 7 .catch(err => console.error(err));
Barcode generation
To generate a QR Code SVG image include 'zxing.qrcodewriter.min.js' from build/vanillajs
. You will need to include an element where the SVG element will be appended:
1<div id="result"></div>
And then:
1const codeWriter = new ZXing.BrowserQRCodeSvgWriter(); 2// you can get a SVG element. 3const svgElement = codeWriter.write(input, 300, 300); 4// or render it directly to DOM. 5codeWriter.writeToDom('#result', input, 300, 300);
Contributing
See Contributing Guide for information regarding porting approach and reasoning behind some of the approaches taken.
Contributors
Special thanks to all the contributors who have contributed for this project. We heartly thankful to you all.
And a special thanks to @aleris who created the project itself and made the initial QR code port.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: Apache License 2.0: LICENSE:0
Reason
10 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 8
Reason
Found 5/11 approved changesets -- score normalized to 4
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/ci.yml:1
- Warn: no topLevel permission defined: .github/workflows/npmpublish.yml:1
- Warn: no topLevel permission defined: .github/workflows/stale.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:20: update your workflow using https://app.stepsecurity.io/secureworkflow/zxing-js/library/ci.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:21: update your workflow using https://app.stepsecurity.io/secureworkflow/zxing-js/library/ci.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:29: update your workflow using https://app.stepsecurity.io/secureworkflow/zxing-js/library/ci.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/npmpublish.yml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/zxing-js/library/npmpublish.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/npmpublish.yml:15: update your workflow using https://app.stepsecurity.io/secureworkflow/zxing-js/library/npmpublish.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/npmpublish.yml:23: update your workflow using https://app.stepsecurity.io/secureworkflow/zxing-js/library/npmpublish.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/npmpublish.yml:46: update your workflow using https://app.stepsecurity.io/secureworkflow/zxing-js/library/npmpublish.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/npmpublish.yml:57: update your workflow using https://app.stepsecurity.io/secureworkflow/zxing-js/library/npmpublish.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/npmpublish.yml:61: update your workflow using https://app.stepsecurity.io/secureworkflow/zxing-js/library/npmpublish.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/stale.yml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/zxing-js/library/stale.yml/master?enable=pin
- Info: 0 out of 10 GitHub-owned GitHubAction dependencies pinned
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 25 are checked with a SAST tool
Reason
18 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-qwcr-r2fm-qrc7
- Warn: Project is vulnerable to: GHSA-pxg6-pf52-xh8x
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-9vvw-cc9w-f27h
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-fc9h-whq2-v747
- Warn: Project is vulnerable to: GHSA-2j2x-2gpw-g8fm
- Warn: Project is vulnerable to: GHSA-c429-5p7v-vgjp
- Warn: Project is vulnerable to: GHSA-82v2-mx6x-wq7q
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m / GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-9wv6-86v2-598j
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-gcx4-mw62-g8wm
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-7p7h-4mm5-852v
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
- Warn: Project is vulnerable to: GHSA-776f-qx25-q3cc
Score
4
/10
Last Scanned on 2024-12-16
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More