barcode-detector-api-polyfill 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,15 +18,36 @@ As you can see there is a huge gap in the support across mobile and desktop plat
|
|
|
18
18
|
|
|
19
19
|
This project implements a polyfill for the BarcodeDetector API that follows the [W3C specification](https://wicg.github.io/shape-detection-api/#barcode-detection-api) with the help of the [ZXing library](https://github.com/zxing-js/library) and [its browser layer](https://github.com/zxing-js/browser). ZXing ("zebra crossing") is a popular open-source library that works with 1D and 2D barcode formats. It was originally written in Java but was eventually ported to many different languages including JavaScript and TypeScript.
|
|
20
20
|
|
|
21
|
-
## How to
|
|
21
|
+
## How to install?
|
|
22
22
|
|
|
23
23
|
### Standalone browser script
|
|
24
24
|
|
|
25
|
-
Download the latest build and use it as a regular JS file in a `<script>` tag
|
|
25
|
+
Download the latest build and use it as a regular JS file in a `<script>` tag. This build takes care of adding the missing BarcodeDetector object to the global scope and you are able to use it the same way as the real BarcodeDetector API.
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
```html
|
|
28
|
+
<script src="browser/barcode-detector-polyfill.min.js"></script>
|
|
29
|
+
```
|
|
28
30
|
|
|
29
|
-
|
|
31
|
+
|
|
32
|
+
### NPM module
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
npm install barcode-detector-api-polyfill
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Include `node_modules/barcode-detector-api-polyfill/browser/barcode-detector-polyfill.min.js` to your script imports if you use a bundler
|
|
39
|
+
|
|
40
|
+
If you just want to have the detector and handle the polyfilling by yourself you can simply import the `BarcodeDetector` class in your code.
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
import { BarcodeDetector, WindowWithBarcodeDetector } from 'barcode-detector-api-polyfill';
|
|
44
|
+
|
|
45
|
+
if (!('BarcodeDetector' in window)) {
|
|
46
|
+
(window as WindowWithBarcodeDetector).BarcodeDetector = BarcodeDetector;
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
A valid use case for this could be if you use a bundler and you want to lazy load the polyfill only when its needed.
|
|
30
51
|
|
|
31
52
|
## Important notes and known drawbacks
|
|
32
53
|
|