Javascript-Barcode-Reader
A Barcode scanner capapable of reading Code128 (UCC/EAN-128), Code93, Code39, Standard/Industrial 2 of 5, Interleaved 2 of 5, Codabar and EAN-13 barcodes in javascript for Node.js and Browsers.
Demo
http://mubaidr.js.org/Javascript-Barcode-Reader/
Available decoders
Install
Recommended way to install is by using package manager (npm, yarn etc):
npm install javascript-barcode-reader
or use cdn:
<script src="//unpkg.com/javascript-barcode-reader/dist/javascript-barcode-reader.min.js"></script>
or download manually:
javascript-barcode-reader.js
How to use
Node.js
const javascriptBarcodeReader = require('javascript-barcode-reader')
Using promise
javascriptBarcodeReader(
Image ,
{
barcode: 'code-2of5',
type: 'industrial',
}
)
.then(code => {
console.log(code)
})
.catch(err => {
console.log(err)
})
Using await
try {
const code = await javascriptBarcodeReader(
Image ,
{
barcode: 'code-2of5',
type: 'industrial',
}
)
} catch (err) {
console.log(err)
}
Browser
javascriptBarcodeReader
will be available as global in Browsers.
Using promise
javascriptBarcodeReader(
Image ,
{
barcode: 'code-2of5',
type: 'industrial',
}
)
.then(code => {
console.log(code)
})
.catch(err => {
console.log(err)
})
Using await
try {
const code = await javascriptBarcodeReader(
Image ,
{
barcode: 'code-2of5',
type: 'industrial',
}
)
} catch (err) {
console.log(err)
}
Tips
- Make sure the barcode image is the only thing in the image. Otherwise this script will most probably fail.
Known Issues
This script does not implement logic to locate/rotate barcode in the given image.
Contributing
All the modules are contianed in src
directory. If you implement a new module or update an existing one, then make sure to add/run tests by running:
npm test
Tests are defined in the __tests__
directory using Jest
.
There is no need to run build script before creating pull request.
Licence
MIT License
Copyright (c) 2018 Muhammad Ubaid Raza
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.