Coder Social home page Coder Social logo

hyunseunglee-travis / browser-barcodescanner Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 0.0 124 KB

This NPM library has an organized and precise code for scanning and detecting barcodes with the best support for users and developers using this tool. It is based on the Web API Barcode Detection API.

Home Page: https://www.npmjs.com/package/browser-barcodescanner

License: MIT License

TypeScript 29.66% HTML 3.30% CSS 13.83% JavaScript 53.21%
barcode barcode-reader barcode-scanner

browser-barcodescanner's Introduction

browser-BarcodeScanner

logo
Barcode Scanner for the Browser


Installation

npm install browser-barcodescanner
yarn add browser-barcodescanner

Usage

import { BrowserBarcodeScanner } from 'browser-barcodescanner'

const scanButton = document.querySelector('#scan')
const fileInput = document.querySelector('#file')

scanButton.addEventListener('click', () => {
  const file = fileInput.files?.[0]
  if (!file) return

  BrowserBarcodeScanner(['ean_13'], file, result => {
    // Do something with result.res (The barcode value)
    // Do Something with result.corner (The corner points of the barcode)
    // Do Something with result.box (The bounding box of the barcode)
  })
})
import { BrowserBarcodeScanner } from 'browser-barcodescanner'

const scanButton = document.querySelector('#scan')
const video = document.querySelector('#video')

scanButton.addEventListener('click', () => {
  navigator.mediaDevices.getUserMedia({ video: true }).then(stream => {
    video.srcObject = stream
  })

  BrowserBarcodeScanner(['ean_13'], video, result => {
    // Do something with result.res (The barcode value)
    // Do Something with result.corner (The corner points of the barcode)
    // Do Something with result.box (The bounding box of the barcode)
  })
})

See https://developer.mozilla.org/en-US/docs/Web/API/BarcodeDetector/detect for more information about the result.

API

BrowserBarcodeScanner

declare global {
  interface Window {
    BarcodeDetector: any
  }
}
export declare function BrowserBarcodeScanner(
  formats: string[],
  object: File | HTMLVideoElement | HTMLImageElement | HTMLCanvasElement | null,
  callback: (result: { res: string }) => void
): Promise<void>

Contributing

Contributing is always welcome!

I cannot maintain this project alone, so please feel free to open issues and pull requests.

Testing

If you are going to contribute, follow these steps

git clone https://github.com/hslee2008/browser-barcodescanner.git
npm install
cd playground
yarn dev

In another terminal

lt --port 5173

Then, open the url in your mobile phone as the api is only supported on mobile devices.

browser-barcodescanner's People

Contributors

dependabot[bot] avatar hslee2008 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.