npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@alzera/react-scanner

v1.0.18

Published

Barcode scanner component for React apps

Downloads

200

Readme

React QR Scanner

@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

| Name | Type | Description | | -------- | ------- | ------- | | onScan* | (value: string) => void | Callback function triggered when a QR code is scanned. Passes the scanned data as an argument. | | onError | (error: any) => void | Callback function triggered when an error occurs during scanning. | | delay | number | Set the delay (in milliseconds) between scans. | | aspectRatio | string | Set the aspect ratio of the scanner window, using css aspect-ratio. | | decoderOptions | BarcodeDetectorOptions | Exposed BarcodeScanner config, more on here. | | switchLabel | (isScanner: boolean) => React.ReactNode | Function to customize the label for the switch component. | | dropChildren | React.ReactNode | React node to customize the content of the drop area. | | style | React.CSSProperties | Apply custom styles to the scanner component. | | className | string | Add 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

| Name | Type | Description | | -------- | ------- | ------- | | onScan* | (value: string) => void | Callback function triggered when a QR code is scanned. Passes the scanned data as an argument. | | onError | (error: any) => void | Callback function triggered when an error occurs during scanning. | | delay | number | Set the delay (in milliseconds) between scans. | | aspectRatio | string | Set the aspect ratio of the scanner window, using css aspect-ratio. | | decoderOptions | BarcodeDetectorOptions | Exposed BarcodeScanner config, more on here. | | style | React.CSSProperties | Apply custom styles to the scanner component. | | className | string | Add 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

| Name | Type | Description | | -------- | ------- | ------- | | onScan* | (value: string) => void | Callback function triggered when a QR code is scanned. Passes the scanned data as an argument. | | onError | (error: any) => void | Callback function triggered when an error occurs during scanning. | | children | React.ReactNode | React node to customize the content of the drop area. | | decoderOptions | BarcodeDetectorOptions | Exposed BarcodeScanner config, more on here. | | style | React.CSSProperties | Apply custom styles to the scanner component. | | className | string | Add 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

| Name | Type | Description | | -------- | ------- | ------- | | opts | BarcodeDetectorOptions | Exposed BarcodeScanner config, more on here. |

Return

| Type | Description | | ------- | ------- | | (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

| Name | Type | Description | | -------- | ------- | ------- | | onError | (error: any) => void | Callback function triggered when an error occurs during scanning. | | useLastDeviceId | boolean | Use the last selected device id. | | autoStart | boolean | Set the initial camera state. | | autoPause | boolean | Set if the camera should be paused when the component is not visible. | | constraints.audio | boolean | Set if the camera should have audio enabled. | | constraints.video | boolean | Set if the camera should have video enabled. |

Return

| Name | Type | Description | | -------- | ------- | ------- | | video | React.RefObject<HTMLVideoElement> | Reference object for video element. | | camera.capabilities | MediaTrackCapabilities | undefined | Selected camera capabilities. | | camera.state | CameraState | Reflect the current camera state, starting, display, stopping, idle. | | camera.torch | boolean | State of torch. | | device.list | MediaDeviceInfo[] | Reflect available devices options. | | device.selected | string | undefined | State of selected device. | | device.lastSelected | string | undefined | State of last selected device. |

Contributing

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

Happy scanning! 📷 🚀