Git Product home page Git Product logo

vue-barcode-scanner's Introduction

Vue Barcode Scanner

Barcode Scanner Plugin for Vue.js

Features

Usually in the market have a lot of barcode scanner. So we need to handle a lot of things to make this input right as it was for all scanner.

This plugin allows for better control of scanning inputs as speed of scanners lead to noisy and innacurate results. This plugin will allow you to use your already implemented barcode scanner in your project with better control and accuracy.

vue-barcode-scanner is a throttle for existing barcode scanners such as https://github.com/serratus/quaggaJS or https://github.com/hypery2k/cordova-barcodescanner-plugin/. vue-barcode-scanner is not a scanning tool on its own.

What's the problem

  • The listener will alway trigger for each character input, So we need to put it together and check when it's finished and ready to use.
  • Need to handle some special characters for some scanner, Because it's not the same for all scanner.

What this plugin do for you

  • Handle the listener for you and return the ready barcode to your callback just once when scanning is finished.
  • Handle special characters and return the complete barcode to you.

Update

  • Tab suffix barcode scanner compatibility
  • Listener for keypress instead of keydown (0.2)
  • New method to get previous barcode (0.2)
  • Listen to for all keypress not only textbox or textarea like previous version (0.3)
  • Check the input is come from barcode scanner by check elapsed time less than 500ms (0.3)
  • Support scanner that use "TAB" instead of "Enter" in the last scanned charactor (adding keydown event) (0.4)
  • Clear elapsed time when submit the barcode (0.4)
  • Change by pass elapsed time from 500ms to 30ms and change the logic to make scanner detection better (0.4)
  • Options to set scan sensitivity (it's elapsed time for each key scanned, default 100ms) (0.5)
  • New method to set scan sensitivity manually (0.5)

Dependencies

  • vue

Installation

Install via npm

npm install vue-barcode-scanner

Initiate

Inject plugin to your vue instance by Vue.use then initial it in your component that need to use barcode scanner

Default Injection

import Vue from 'vue'
import VueBarcodeScanner from 'vue-barcode-scanner'

...

// inject vue barcode scanner
Vue.use(VueBarcodeScanner)

Inject with option

// inject barcode scanner with option (add sound effect)
// sound will trigger when it's already scanned
let options = {
  sound: true, // default is false
  soundSrc: '/static/sound.wav' // default is blank
  sensitivity: 300 // default is 100
}

Vue.use(VueBarcodeScanner, options)

Methods

init

Init method use for add event listener (keypress) for the scanner.

this.$barcodeScanner.init(callbackFunction)

destroy

Destroy method is for remove the listener when it's unnecessary.

this.$barcodeScanner.destroy()

hasListener

Return the value that currently has a listener or not.

this.$barcodeScanner.hasListener() // return Boolean

getPreviousCode

Return last barcode scanned whatever your input is (In textbox currently). The last barcode will be replace when hit enter key.

this.$barcodeScanner.getPreviousCode() // return String

setSensitivity

Set limit of the time elapsed between each key stroke to distinguish between human typing and barcode scanner. Barcode scanner is determined by how fast between each key stoke. Argument is number of milliseconds.

this.$barcodeScanner.setSensitivity(200) // sets barcode scanner recognition sensitivity to 200 ms

Usage

In your component file (.vue) just for the component you need to listener for barcode.

  export default {
    created () {
      // Add barcode scan listener and pass the callback function
      this.$barcodeScanner.init(this.onBarcodeScanned)
    },
    destroyed () {
      // Remove listener when component is destroyed
      this.$barcodeScanner.destroy()
    },
    methods: {
      // Create callback function to receive barcode when the scanner is already done
      onBarcodeScanned (barcode) {
        console.log(barcode)
        // do something...
      },
      // Reset to the last barcode before hitting enter (whatever anything in the input box)
      resetBarcode () {
        let barcode = this.$barcodeScanner.getPreviousCode()
        // do something...
      }
    }
  }

Disclaimer

This is NOT a barcode scanner. This is a scanner throttle to reduce innacurate scanner inputs.

vue-barcode-scanner's People

Contributors

noomerzx avatar kykungz avatar pangaunn avatar safinn avatar redpanda-bit avatar

Watchers

James Cloos avatar Ismail avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.