# barcode-detector-zbar

> Barcode detector polyfill using zbar.wasm

Latest version **1.1.0** (published 2021-12-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install barcode-detector-zbar
pnpm add barcode-detector-zbar
yarn add barcode-detector-zbar
bun add barcode-detector-zbar
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2021-12-15 |
| First published | 2021-11-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 300 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | LeKoala |
| Maintainers | lekoala |
| Keywords | barcode, detector, polyfill, zbar, wasm, es6 |

## Links

- npm: https://www.npmjs.com/package/barcode-detector-zbar
- Repository: https://github.com/lekoala/barcode-detector-zbar
- Homepage: https://github.com/lekoala/barcode-detector-zbar#readme
- Issues: https://github.com/lekoala/barcode-detector-zbar/issues
- npm.io page: https://npm.io/package/barcode-detector-zbar

## Dependencies (1)

- [zbar.wasm](https://npm.io/package/zbar.wasm.md) ^2.1.1

## Alternatives

- [jsforce](https://npm.io/package/jsforce.md) — 851.2K weekly downloads
- [react-native-qrcode-svg](https://npm.io/package/react-native-qrcode-svg.md) — 693.5K weekly downloads
- [@salesforce/plugin-data](https://npm.io/package/@salesforce/plugin-data.md) — 394.9K weekly downloads
- [@backstage/plugin-search-common](https://npm.io/package/@backstage/plugin-search-common.md) — 308.5K weekly downloads
- [@chain-registry/types](https://npm.io/package/@chain-registry/types.md) — 38.4K weekly downloads

## Recent versions

- 1.1.0 (latest) — 2021-12-15
- 1.0.1 — 2021-11-24
- 1.0.0 — 2021-11-23

## README

# Barcode Detector Api Polyfill using zbar.wasm

[![NPM](https://nodei.co/npm/barcode-detector-zbar.png?mini=true)](https://nodei.co/npm/barcode-detector-zbar/)
[![Downloads](https://img.shields.io/npm/dt/barcode-detector-zbar.svg)](https://www.npmjs.com/package/barcode-detector-zbar)

## How to use

This is a very simple polyfill using zbar.wasm under the hood written in plain ES6.

You can install the polyfill with `BarcodeDetectorPolyfill.setupPolyfill()`.

```html
<script type="module">
  import BarcodeDetectorPolyfill from "./BarcodeDetectorPolyfill.min.js";

  console.log("Native api support", BarcodeDetectorPolyfill.checkBarcodeDetectorSupport());
  BarcodeDetectorPolyfill.setupPolyfill();
</script>
```

Simply use like the regular api (check https://developer.mozilla.org/en-US/docs/Web/API/Barcode_Detection_API).

## zbar.wasm

This polyfill uses zbar.wasm and therefore needs to load a ~200kb bin file in order to work. The polyfill itself is 9.5kb.

## Checking secure context

Webcam is only available in a secure context. Here is some sample code to help you (using Swal to show an error message).

```js
if (!BarcodeDetectorPolyfill.checkWebcamSupport()) {
  if (!BarcodeDetectorPolyfill.checkSecureContext()) {
    Swal.fire("You need a secure context!");
  } else {
    Swal.fire("No webcam connected!");
  }
}
```

## You can try the demo

Running `npm run start` and see demo.html or https://codepen.io/lekoalabe/pen/abyrqaL (currently not working due to CORS issue loading the wasm file)

## Also check out

Other
- https://zbar-wasm.github.io/demo/

Api ref
- https://developer.mozilla.org/en-US/docs/Web/API/Barcode_Detection_API
- https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia

Scanner app
- https://github.com/mebjas/html5-qrcode
- https://github.com/maslick/koder

Zbar
- https://github.com/samsam2310/zbar.wasm
- https://github.com/mchehab/zbar

Zxing
- https://github.com/zxing-js/browser

Other libs
- https://www.npmjs.com/package/qr-scanner (worker support)
- https://serratus.github.io/quaggaJS/ (nice rotation algo)
- https://github.com/ericblade/quagga2

Other polyfills
- https://github.com/giladaya/barcode-detector-polyfill
- https://github.com/gruhn/barcode-detector

---
_Source: https://npm.io/package/barcode-detector-zbar · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
