use-scan-detection
Version:
A react hook for detecting barcode scanner input.
31 lines (30 loc) • 1.54 kB
TypeScript
interface config {
/** Time to wait from last character to then trigger an evaluation of the buffer. */
timeToEvaluate?: number;
/** Average time between characters in milliseconds. Used to determine if input is from keyboard or a scanner. Defaults to 50ms.*/
averageWaitTime?: number;
/** Character that barcode scanner prefixes input with.*/
startCharacter?: Array<number>;
/** Character that barcode scanner suffixes input with. Defaults to line return.*/
endCharacter?: Array<number>;
/** Callback to use on complete scan input.*/
onComplete: (code: String) => void;
/** Callback to use on error. */
onError?: (error: String) => void;
/** Minimum length a scanned code should be. Defaults to 0.*/
minLength?: number;
/** Ignore scan input if this node is focused.*/
ignoreIfFocusOn?: Node;
/** Stop propagation on keydown event. Defaults to false.*/
stopPropagation?: Boolean;
/** Prevent default on keydown event. Defaults to false.*/
preventDefault?: Boolean;
/** Bind keydown event to this node. Defaults to document.*/
container?: Node;
}
/**
* Checks for scan input within a container and sends the output to a callback function.
* @param param0 Config object
*/
declare const useScanDetection: ({ timeToEvaluate, averageWaitTime, startCharacter, endCharacter, onComplete, onError, minLength, ignoreIfFocusOn, stopPropagation, preventDefault, container }: config) => void;
export default useScanDetection;