Noncommital Premarital Mischief
    Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

    barcode-detector-polyfillpublic

    BarcodeDetector Polyfill

    Polyfill for BarcodeDetector, part of shape detection api

    Implementation

    This is basically a Promise wrapper around DecoderWorker from the JOB barcode decoding library.

    Note that currently this polyfill enables detection and decoding of 1D barcodes only, 2D barcodes (EG QR-code) might be added in the future using an additional library.

    Usage

    In the browser

    Install:

    bower install barcode-detector-polyfill
    

    Use:

    <script>
      (function () {
        function loadScript(src, done) {
          var $script = document.createElement('script');
          $script.src = src;
          $script.onload = function() {
            done();
          };
          $script.onerror = function() {
            done(new Error('Failed to load script ' + src));
          };
          document.head.appendChild($script);
        }
        if (BarcodeDetector in window) {
          continueToStartTheApp();
        } else {
          loadScript(
            "bower_components/barcode-detector-polyfill/BarcodeDetector.min.js", 
            continueToStartTheApp
          );
        }
      })()
      // ...
    </script>
    

    With webpack

    Install:

    npm install --save barcode-detector-polyfill
    

    Use:

    if ('BarcodeDetector' in window) {
      continueToStartTheApp();
    } else {
      require.ensure(['barcode-detector-polyfill'], function(require) {
        const BarcodeDetector = require('barcode-detector-polyfill');
        window.BarcodeDetector = BarcodeDetector;
        continueToStartTheApp();
      }, function(err) {
        console.log('Failed to load BarcodeDetector', err);
      });
    }
    

    See demo

    Examples

    See the examples folder, or live demo

    Browser support

    Requires Promises (can also be polyfilled) and typed arrays which are supported in all modern browsers, down to IE11.

    install

    npm i barcode-detector-polyfill

    Downloadsweekly downloads

    7

    version

    0.1.2

    license

    MIT

    repository

    githubgithub

    last publish

    collaborators

    • avatar