TypeScript icon, indicating that this package has built-in type declarations

    2.0.0 • Public • Published

    Barcode Scanner

    npm license gzip size

    A simple JavaScript utility to read barcode from devices emulating a fast keyboard.

    Table of Contents


    # Yarn 
    yarn add simple-barcode-scanner
    # NPM 
    npm install --save simple-barcode-scanner

    Then with a module bundler like rollup or webpack, use as you would anything else:

    // using ES6 modules
    import BarcodeScanner from "simple-barcode-scanner";
    // using CommonJS modules
    const BarcodeScanner = require("simple-barcode-scanner");

    The UMD build is also available on unpkg:

    <script src=""></script>

    You can find the library on window.BarcodeScanner.


    import BarcodeScanner from "simple-barcode-scanner";
    const scanner = BarcodeScanner();
    // Add a listener
    scanner.on((code, event) => {
    // Remove the listener;



    Creates a simple function to listen to barcode scanners


    • Options Object

      • latency Number Max time duration (in ms) between consecutive inputs

        default: 50

      • minLength Number Min length of a valid barcode

        default: 3

      • element HTMLElement The HTML element to attach the event listener to

        default: document

      • endKeys Array<string> Array of keys indicating end of barcode

        Refer Key Values | MDN

        default: ["Enter"]

      • validKey RegExp Regular expression to check for a valid key in barcode

        Refer Key Values | MDN

        default: /^\w$/

    Returns Scanner


    • #### on

      Starts listening for barcode scans and add/replace the listener


      • handler Function Function to call on completion of barcode scan

        Recieves the scanned code and the keyboard event of the last input as the parameters

    • #### off Stop listening for barcode scans and remove the listener


    First off, thanks for taking the time to contribute! Now, take a moment to be sure your contributions make sense to everyone else.

    Development Start:

    This project uses Typescript for development and yarn for dependency management.

    Reporting Issues

    Found a problem? Want a new feature? First of all see if your issue or idea has already been reported. If not, just open a new clear and descriptive issue.

    Submitting pull requests

    Pull requests are the greatest contributions, so be sure they are focused in scope, and do avoid unrelated commits.

    • Fork it!
    • Clone your fork: git clone<your-username>/simple-barcode-scanner
    • Navigate to the newly cloned directory: cd simple-barcode-scanner
    • Create a new branch for the new feature: git checkout -b my-new-feature
    • Install the tools necessary for development: yarn
    • Make your changes.
    • Commit your changes: git commit -am 'Add some feature'
    • Push to the branch: git push origin my-new-feature
    • Submit a pull request with full remarks documenting your changes.


    npm i simple-barcode-scanner

    DownloadsWeekly Downloads






    Unpacked Size

    10.1 kB

    Total Files


    Last publish


    • hadeeb