0.2.9 • Published 5 years ago

@arriva/wedge v0.2.9

Weekly downloads
-
License
ISC
Repository
-
Last release
5 years ago

Wedge reader for browsers

Wedge module will capture data from keyboard wedge readers and send them to a listener function. Essentially all barcode readers, magnetic stripe readers and RFID readers that sends data over keyboard commands and that can be programmed to use start and end characters can be used.

Installation

npm i @arriva/wedge

Examples

ES6

import wedge from '@arriva/wedge'

let options = {
    // Configuration options
}

let wedge = new Wedge(options)

let eventListener = wedge.listen(function(data){
    console.log([data])
})

eventListener.destroy()

Browser support

<script src="js/wedge.js"></script>
<script>
    var options = {
        // Configuration options
    }

    var wedge = new Wedge(options)

    var instance = wedge.listen(function(data){
        console.log([data])
    })

    instance.destroy()
</script>

Configuration options

When initializing Wedge the following options can be set:

  • escapeStringBegin: Character that starts the code read sequence. (Default: ¤)
  • escapeStringEnd: Character that ends the code read sequence. (Default: ¤)
  • delay: Milliseconds minimum delay between keystrokes to allow read. (Default: 50)
    var options = {
        escapeStringBegin: '¤',
        escapeStringEnd: '¤',
        delay: 50
    }

    var instance = new Wedge(options)

Methods and properties

Wedge instance

  • Wedge::listen(listenerFunc): Create listener. Listener instance object returned.
  • Wedge::trigger(data [,delay]): Simulate as if data string was read by a keyboard reader. Optional delay in milliseconds.
  • Wedge::purge([listenerId]): Destroy all listeners. Optional listenerId will destroy only that listener.

Listener instance

  • Listener::id: Return listener id.
  • Listener::destroy(): Destroy this listener.

Method examples

    var options = {
        escapeStringBegin: '¤',
        escapeStringEnd: '¤',
        delay: 50
    }

    var instance = new Wedge(options)

    var listener1 = instance.listen(function(data){
        console.log(data)
    })
    var listener2 = instance.listen(function(data){
        console.log(data)
    })

    // Trigger all listeners
    instance.trigger('123456789')

    // Purge listener with id
    instance.purge(listener1.id)

    // Purge all listeners
    instance.purge()

Tested units

Environment considerations

Since many wedge readers simulate keyboard strokes, data from keyboard is dependent on keyboard language and layout settings. That means that you will not always get the exact keycodes that you expected. To find out how it looks for your device, run this code piece in your browser, for example in the console:

    document.onkeydown = (e) => {
        console.log(e.key)
    }

Conflict situations

If two or more instances of Wedge is launched, listening at same trigger characters, they will interfere and it is unpredictable which listener will catch what characters. Avoid this situation.

Warranty

This piece of software is provided "AS-IS". No warranties applies. Backward compability is sustained inside major version number only, start from version 1.0.0.

Release history

Pre 1.0.0

Releases prior to version 1.0.0 is entirely intended as development state. Do not expect stable releases. Check changelog for details.

Version history

VersionDateDescription
0.3.0-beta.02019-04-17First fully working version. Candidate for release.
0.3.0 and less2019-04-16 and beforeDevelopment versions. Learning NPM publishing system.

Contact information

Contact information will be published later.

Author

Odd Holstensson, Arriva Sweden 2019

0.3.0-beta.0

5 years ago

0.2.9

5 years ago

0.2.8

5 years ago

0.2.7

5 years ago

0.2.6

5 years ago

0.2.5

5 years ago

0.2.4

5 years ago

0.2.3

5 years ago

0.2.2

5 years ago