Socket
Socket
Sign inDemoInstall

use-scan-detection

Package Overview
Dependencies
6
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    use-scan-detection

A react hook for detecting barcode scanner input.


Version published
Maintainers
1
Install size
15.8 kB
Created

Readme

Source

useScanDetection

A react hook for detecting barcode scanners in the DOM.

Installation

npm i use-scan-detection

Usage

useScanDetection({
    onComplete: () => {}
});

Parameters

Parameters are supplied by a config object:

ParameterDescription
waitTimeMaximum time between characters in milliseconds. Used to determine if input is from keyboard or a scanner. Defaults to 50.
startCharacterOptional. Character that barcode scanner prefixes input with. Code is only read if this character is read first.
endCharacterCharacter that barcode scanner suffixes input with. Code is only read if this character is read last. Defaults to line return (key code 13)
onCompleteFunction that is called when a complete barcode is scanned. Function is called with a single string which is the read code.
onErrorOptional. Function that is called when an incomplete barcode is scanned. Function is called with a single string which is currently always incomplete scan detected
minLengthMinimum number of characters for a barcode to successfully read. Should be greater than 0. Defaults to 1.
ignoreIfFocusOnOptional. DOM element that if focused prevents codes from being read.
stopPropagationWhether to call stopPropagation on each key event. Defaults to false.
preventDefaultWhether to call preventDefault on each key event. Defaults to false.
containerDOM element to listen for keydown events in. Defaults to document.

Return

This hook returns nothing.

Example

import React, { useState } from 'react';
import useScanDetection from 'use-scan-detection';

const Input = () => {
    const [value, setValue] = useState("");

    useScanDetection({
        onComplete: setValue,
        minLength: 13 // EAN13
    });

    return (
        <input 
            value={value} 
            type="text"
        />
    );
};

export default Input

License

MIT Licensed

Keywords

FAQs

Last updated on 29 Oct 2019

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc