Nonvoluntary Professional Mangling

npm

Need private packages and team management tools?Check out npm Orgs. »

javascript-barcode-reader

0.5.4 • Public • Published

Javascript-Barcode-Reader

Simple & Fast Barcode decoder for Browsers and Node.js capapable of reading Code128 (UCC/EAN-128), Code93, Code39, Standard/Industrial 2 of 5, Interleaved 2 of 5, Codabar and EAN-13 barcodes.

Build Status Codacy Badge codecov All Contributors

NPM

Demo

http://mubaidr.js.org/Javascript-Barcode-Reader/

Available decoders

  • EAN-13
  • EAN-8
  • Code-39
  • Code-93
  • Code-2of5
    • standard
    • Interleaved
  • Codabar
  • Code-128 (UCC/EAN-128)

Install

Recommended way to install is by using package manager (npm, yarn etc):

npm install --save javascript-barcode-reader

or use cdn:

<script src="//unpkg.com/javascript-barcode-reader"></script>

or download manually:

javascript-barcode-reader.js

How to use

Node.js

const javascriptBarcodeReader = require('javascript-barcode-reader')

Using promise

javascriptBarcodeReader(
  Image /* Image file Path || {data: pixelArray, width, height} || HTML5 Canvas ImageData */,
  {
    barcode: 'code-2of5',
    type: 'industrial', //optional type
  }
)
  .then(code => {
    console.log(code)
  })
  .catch(err => {
    console.log(err)
  })

Using await

try {
  const code = await javascriptBarcodeReader(
    Image /* Image file Path || {data: pixelArray, width, height} || HTML5 Canvas ImageData */,
    {
      barcode: 'code-2of5',
      type: 'industrial', //optional type
    }
  )
} catch (err) {
  console.log(err)
}

Browser

javascriptBarcodeReader will be available as global in Browsers.

Using promise

javascriptBarcodeReader(
  Image /* Image ID || HTML5 Image || HTML5 Canvas || HTML5 Canvas ImageData || Image URL */,
  {
    barcode: 'code-2of5',
    type: 'industrial', //optional type
  }
)
  .then(code => {
    console.log(code)
  })
  .catch(err => {
    console.log(err)
  })

Using await

try {
  const code = await javascriptBarcodeReader(
    Image /* Image ID || HTML5 Image || HTML5 Canvas || HTML5 Canvas ImageData || Image URL */,
    {
      barcode: 'code-2of5',
      type: 'industrial', //optional type
    }
  )
} 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.

Contributors

Thanks goes to these wonderful people (emoji key):

Cristian Nitescu
Cristian Nitescu

💻

This project follows the all-contributors specification. Contributions of any kind welcome!

install

npm i javascript-barcode-reader

Downloadsweekly downloads

59

version

0.5.4

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability