Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
vue3-barcode-scanner
Advanced tools
Barcode Scanner Plugin for Vue.js
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.
Install via npm
npm install vue3-barcode-scanner
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 'vue3-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
requiredAttr: true, // default is false
controlSequenceKeys: ['NumLock', 'Clear'], // default is null
callbackAfterTimeout: true // default is false
}
Vue.use(VueBarcodeScanner, options)
controlSequenceKeys
: when a control key in this list is encountered in a scan sequence, it will be replaced with tags for easy string replacementcallbackAfterTimeout
: this will fire the callback defined in the component once sensitivity
ms has elapsed, following the last character in the barcode sequence. This is useful for scanners that don't end their sequences with ENTER and is backwards compatible with scanners that do.Init method use for add event listener (keypress) for the scanner.
this.$barcodeScanner.init(callbackFunction, options)
options
defaults to an empty object, {}
, and can be safely ignored. See Advanced Usage for an example.
Destroy method is for remove the listener when it's unnecessary.
this.$barcodeScanner.destroy()
Return the value that currently has a listener or not.
this.$barcodeScanner.hasListener() // return Boolean
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
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
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...
}
}
}
export default {
data: () => ({
loading: false
}),
created () {
// Pass an options object with `eventBus: true` to receive an eventBus back
// which emits `start` and `finish` events
const eventBus = this.$barcodeScanner.init(this.onBarcodeScanned, { eventBus: true })
if (eventBus) {
eventBus.$on('start', () => { this.loading = true })
eventBus.$on('finish', () => { this.loading = false })
}
},
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...
}
}
}
This is NOT a barcode scanner. This is a scanner throttle to reduce innacurate scanner inputs.
FAQs
Barcode Scanner Plugin for Vue.js
We found that vue3-barcode-scanner demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.