Gathering detailed insights and metrics for zxing-library-with-attempts
Gathering detailed insights and metrics for zxing-library-with-attempts
Gathering detailed insights and metrics for zxing-library-with-attempts
Gathering detailed insights and metrics for zxing-library-with-attempts
npm install zxing-library-with-attempts
Typescript
Module System
Min. Node Version
Node Version
NPM Version
78.5
Supply Chain
98.8
Quality
74.7
Maintenance
100
Vulnerability
99.6
License
TypeScript (94.15%)
Java (5.69%)
JavaScript (0.16%)
Total Downloads
4,549
Last Day
1
Last Week
3
Last Month
15
Last Year
2,766
2,536 Stars
1,211 Commits
548 Forks
46 Watching
14 Branches
56 Contributors
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
Cumulative downloads
Total Downloads
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
2
41
1
If it doesn't, we gonna make it.
ZXing ("zebra crossing") is an open-source, multi-format 1D/2D barcode image processing library implemented in Java, with ports to other languages.
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.
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.
npm i @zxing/library --save
or
yarn add @zxing/library
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>
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>
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>
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>
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);
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.
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));
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));
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));
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);
See Contributing Guide for information regarding porting approach and reasoning behind some of the approaches taken.
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
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
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
18 existing vulnerabilities detected
Details
Score
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