Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@alzera/react-scanner

Package Overview
Dependencies
Maintainers
0
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@alzera/react-scanner

Barcode scanner component for React apps

  • 1.0.18
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-93.75%
Maintainers
0
Weekly downloads
 
Created
Source

React QR Scanner

NPM Version NPM Downloads

@alzera/react-scanner is a lightweight and simple-to-use React library for integrating QR code scanning functionality into your web applications. The primary goal of this library is to provide a hassle-free solution for developers who need a quick and efficient way to incorporate QR code scanning without the bloat.

Features

  • Barcode Formats: Support many different barcode formats, more on here.
  • Legacy: Support image input as camera fallback.
  • Low-level API: Expose low-level API to be able to create your own layout.
  • Flash/Torch: Support handling torch when ever possible.

Installation

Install @alzera/react-scanner using your preferred package manager:

npm install @alzera/react-scanner

Components

BarcodeScanner

Combined version of Scanner component and DropZone component, comes with a built-in button that allows users to switch between the scanning mode and the drop zone mode.

Basic Example
import React, { useState } from 'react';
import { BarcodeScanner } from '@alzera/react-scanner';

export default function MyComponent(){
  const [scannedData, setScannedData] = useState('');

  return (
    <div style={{ maxWidth: '500px' }}>
      <BarcodeScanner onScan={(d) => d && setScannedData(d)} />
      {scannedData && <p>Scanned Data: {scannedData}</p>}
    </div>
  );
};
Properties
NameTypeDescription
onScan*(value: string) => voidCallback function triggered when a QR code is scanned. Passes the scanned data as an argument.
onError(error: any) => voidCallback function triggered when an error occurs during scanning.
delaynumberSet the delay (in milliseconds) between scans.
aspectRatiostringSet the aspect ratio of the scanner window, using css aspect-ratio.
decoderOptionsBarcodeDetectorOptionsExposed BarcodeScanner config, more on here.
switchLabel(isScanner: boolean) => React.ReactNodeFunction to customize the label for the switch component.
dropChildrenReact.ReactNodeReact node to customize the content of the drop area.
styleReact.CSSPropertiesApply custom styles to the scanner component.
classNamestringAdd custom class names to the scanner component.

Scanner

Simple component wrapper for barcode-detector library.

Basic Example
import React, { useState } from 'react';
import { Scanner } from '@alzera/react-scanner';

export default function MyComponent(){
  const [scannedData, setScannedData] = useState('');

  return (
    <div style={{ maxWidth: '500px' }}>
      <Scanner onScan={(d) => d && setScannedData(d)} />
      {scannedData && <p>Scanned Data: {scannedData}</p>}
    </div>
  );
};
Properties
NameTypeDescription
onScan*(value: string) => voidCallback function triggered when a QR code is scanned. Passes the scanned data as an argument.
onError(error: any) => voidCallback function triggered when an error occurs during scanning.
delaynumberSet the delay (in milliseconds) between scans.
aspectRatiostringSet the aspect ratio of the scanner window, using css aspect-ratio.
decoderOptionsBarcodeDetectorOptionsExposed BarcodeScanner config, more on here.
styleReact.CSSPropertiesApply custom styles to the scanner component.
classNamestringAdd custom class names to the scanner component.

DropZone

Simple component wrapper for barcode-detector library.

Basic Example
import React, { useState } from 'react';
import { DropZone } from '@alzera/react-scanner';

export default function MyComponent(){
  const [scannedData, setScannedData] = useState('');

  return (
    <div style={{ maxWidth: '500px' }}>
      <DropZone onScan={(d) => d && setScannedData(d)} />
      {scannedData && <p>Scanned Data: {scannedData}</p>}
    </div>
  );
};
Properties
NameTypeDescription
onScan*(value: string) => voidCallback function triggered when a QR code is scanned. Passes the scanned data as an argument.
onError(error: any) => voidCallback function triggered when an error occurs during scanning.
childrenReact.ReactNodeReact node to customize the content of the drop area.
decoderOptionsBarcodeDetectorOptionsExposed BarcodeScanner config, more on here.
styleReact.CSSPropertiesApply custom styles to the scanner component.
classNamestringAdd custom class names to the scanner component.

API

useDecoder

The useDecoder hook is designed to facilitate barcode detection, returning a ref to a decoder function that can be used to decode barcodes from images.

Parameter
NameTypeDescription
optsBarcodeDetectorOptionsExposed BarcodeScanner config, more on here.
Return
TypeDescription
(imageData: ImageBitmapSourceWebCodecs) => Promise<string | null>Function that take CanvasImageSourceWebCodecs, Blob or ImageData to be processed and return the decoded string or null if failed

useCamera

The useCamera hook is designed to facilitate easy to use camera.

Parameter
NameTypeDescription
onError(error: any) => voidCallback function triggered when an error occurs during scanning.
useLastDeviceIdbooleanUse the last selected device id.
autoStartbooleanSet the initial camera state.
autoPausebooleanSet if the camera should be paused when the component is not visible.
constraints.audiobooleanSet if the camera should have audio enabled.
constraints.videobooleanSet if the camera should have video enabled.
Return
NameTypeDescription
videoReact.RefObject<HTMLVideoElement>Reference object for video element.
camera.capabilitiesMediaTrackCapabilities | undefinedSelected camera capabilities.
camera.stateCameraStateReflect the current camera state, starting, display, stopping, idle.
camera.torchbooleanState of torch.
device.listMediaDeviceInfo[]Reflect available devices options.
device.selectedstring | undefinedState of selected device.
device.lastSelectedstring | undefinedState of last selected device.

Contributing

We welcome contributions! Feel free to open issues, create pull requests, or provide feedback.

Happy scanning! 📷 🚀

Keywords

FAQs

Package last updated on 18 Nov 2024

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc