barcode-detector-api-polyfill 1.0.1 → 1.0.3
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 +9 -7
- package/browser/barcode-detector-polyfill.min.js +10 -10
- package/browser/barcode-detector-polyfill.min.js.map +4 -4
- package/cjs/BarcodeDetector.d.ts +0 -2
- package/cjs/BarcodeDetector.js +5 -39
- package/cjs/BarcodeDetector.js.map +1 -1
- package/cjs/constants.d.ts +3 -0
- package/cjs/constants.js +40 -0
- package/cjs/constants.js.map +1 -0
- package/es2022/BarcodeDetector.d.ts +0 -2
- package/es2022/BarcodeDetector.js +6 -40
- package/es2022/BarcodeDetector.js.map +1 -1
- package/es2022/constants.d.ts +3 -0
- package/es2022/constants.js +37 -0
- package/es2022/constants.js.map +1 -0
- package/package.json +10 -4
package/cjs/BarcodeDetector.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import type { IDetectedBarcode, IBarcodeDetector } from './models';
|
|
2
2
|
export declare class BarcodeDetector implements IBarcodeDetector {
|
|
3
3
|
private reader;
|
|
4
|
-
private static zxingToNativeFormat;
|
|
5
|
-
private static nativeToZxingFormat;
|
|
6
4
|
constructor(options?: {
|
|
7
5
|
formats: string[];
|
|
8
6
|
});
|
package/cjs/BarcodeDetector.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.BarcodeDetector = void 0;
|
|
4
4
|
const browser_1 = require("@zxing/browser");
|
|
5
5
|
const library_1 = require("@zxing/library");
|
|
6
|
+
const constants_1 = require("./constants");
|
|
6
7
|
class BarcodeDetector {
|
|
7
8
|
constructor(options) {
|
|
8
9
|
const hints = new Map([
|
|
@@ -10,14 +11,14 @@ class BarcodeDetector {
|
|
|
10
11
|
[
|
|
11
12
|
library_1.DecodeHintType.POSSIBLE_FORMATS,
|
|
12
13
|
options
|
|
13
|
-
? options.formats.map((f) =>
|
|
14
|
-
: Object.values(
|
|
14
|
+
? options.formats.map((f) => constants_1.nativeToZxingFormat[f])
|
|
15
|
+
: Object.values(constants_1.nativeToZxingFormat),
|
|
15
16
|
],
|
|
16
17
|
]);
|
|
17
18
|
this.reader = new browser_1.BrowserMultiFormatReader(hints);
|
|
18
19
|
}
|
|
19
20
|
static getSupportedFormats() {
|
|
20
|
-
return Promise.resolve(Object.values(
|
|
21
|
+
return Promise.resolve(Object.values(constants_1.zxingToNativeFormat));
|
|
21
22
|
}
|
|
22
23
|
async detect(imageSource) {
|
|
23
24
|
try {
|
|
@@ -40,7 +41,7 @@ class BarcodeDetector {
|
|
|
40
41
|
}
|
|
41
42
|
return [{
|
|
42
43
|
rawValue: result.getText(),
|
|
43
|
-
format:
|
|
44
|
+
format: constants_1.zxingToNativeFormat[result.getBarcodeFormat()],
|
|
44
45
|
boundingBox: new DOMRectReadOnly(),
|
|
45
46
|
cornerPoints: result.getResultPoints().map((p) => ({ x: p.getX(), y: p.getY() })),
|
|
46
47
|
}];
|
|
@@ -74,39 +75,4 @@ class BarcodeDetector {
|
|
|
74
75
|
}
|
|
75
76
|
}
|
|
76
77
|
exports.BarcodeDetector = BarcodeDetector;
|
|
77
|
-
// format names taken from https://developer.mozilla.org/en-US/docs/Web/API/Barcode_Detection_API#supported_barcode_formats
|
|
78
|
-
BarcodeDetector.zxingToNativeFormat = {
|
|
79
|
-
[browser_1.BarcodeFormat.AZTEC]: 'aztec',
|
|
80
|
-
[browser_1.BarcodeFormat.CODABAR]: 'codabar',
|
|
81
|
-
[browser_1.BarcodeFormat.CODE_39]: 'code_39',
|
|
82
|
-
[browser_1.BarcodeFormat.CODE_93]: 'code_93',
|
|
83
|
-
[browser_1.BarcodeFormat.CODE_128]: 'code_128',
|
|
84
|
-
[browser_1.BarcodeFormat.DATA_MATRIX]: 'data_matrix',
|
|
85
|
-
[browser_1.BarcodeFormat.EAN_8]: 'ean_8',
|
|
86
|
-
[browser_1.BarcodeFormat.EAN_13]: 'ean_13',
|
|
87
|
-
[browser_1.BarcodeFormat.ITF]: 'itf',
|
|
88
|
-
[browser_1.BarcodeFormat.PDF_417]: 'pdf417',
|
|
89
|
-
[browser_1.BarcodeFormat.QR_CODE]: 'qr_code',
|
|
90
|
-
[browser_1.BarcodeFormat.UPC_A]: 'upc_a',
|
|
91
|
-
[browser_1.BarcodeFormat.UPC_E]: 'upc_e',
|
|
92
|
-
[browser_1.BarcodeFormat.UPC_EAN_EXTENSION]: 'unknown',
|
|
93
|
-
[browser_1.BarcodeFormat.MAXICODE]: 'unknown',
|
|
94
|
-
[browser_1.BarcodeFormat.RSS_14]: 'unknown',
|
|
95
|
-
[browser_1.BarcodeFormat.RSS_EXPANDED]: 'unknown',
|
|
96
|
-
};
|
|
97
|
-
BarcodeDetector.nativeToZxingFormat = {
|
|
98
|
-
aztec: browser_1.BarcodeFormat.AZTEC,
|
|
99
|
-
codabar: browser_1.BarcodeFormat.CODABAR,
|
|
100
|
-
code_39: browser_1.BarcodeFormat.CODE_39,
|
|
101
|
-
code_93: browser_1.BarcodeFormat.CODE_93,
|
|
102
|
-
code_128: browser_1.BarcodeFormat.CODE_128,
|
|
103
|
-
data_matrix: browser_1.BarcodeFormat.DATA_MATRIX,
|
|
104
|
-
ean_8: browser_1.BarcodeFormat.EAN_8,
|
|
105
|
-
ean_13: browser_1.BarcodeFormat.EAN_13,
|
|
106
|
-
itf: browser_1.BarcodeFormat.ITF,
|
|
107
|
-
pdf417: browser_1.BarcodeFormat.PDF_417,
|
|
108
|
-
qr_code: browser_1.BarcodeFormat.QR_CODE,
|
|
109
|
-
upc_a: browser_1.BarcodeFormat.UPC_A,
|
|
110
|
-
upc_e: browser_1.BarcodeFormat.UPC_E,
|
|
111
|
-
};
|
|
112
78
|
//# sourceMappingURL=BarcodeDetector.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BarcodeDetector.js","sourceRoot":"","sources":["../../src/BarcodeDetector.ts"],"names":[],"mappings":";;;AAAA,
|
|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AAC,MAAM,EAAE,CAAC;YAE/B,KAAK,CAAC,GAAG,GAAG,WAAW,CAAC;QAC1B,CAAC,CAAC,CAAC;IACL,CAAC;IAEO,mBAAmB,CAAC,WAAwB;QAClD,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QAChD,MAAM,GAAG,GAAG,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QAEpC,IAAI,GAAG,EAAE;YACP,GAAG,CAAC,SAAS,CAAC,WAAW,EAAE,WAAW,CAAC,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;SACnE;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AA7ED,0CA6EC"}
|
package/cjs/constants.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.nativeToZxingFormat = exports.zxingToNativeFormat = void 0;
|
|
4
|
+
const library_1 = require("@zxing/library");
|
|
5
|
+
// format names taken from https://developer.mozilla.org/en-US/docs/Web/API/Barcode_Detection_API#supported_barcode_formats
|
|
6
|
+
exports.zxingToNativeFormat = {
|
|
7
|
+
[library_1.BarcodeFormat.AZTEC]: 'aztec',
|
|
8
|
+
[library_1.BarcodeFormat.CODABAR]: 'codabar',
|
|
9
|
+
[library_1.BarcodeFormat.CODE_39]: 'code_39',
|
|
10
|
+
[library_1.BarcodeFormat.CODE_93]: 'code_93',
|
|
11
|
+
[library_1.BarcodeFormat.CODE_128]: 'code_128',
|
|
12
|
+
[library_1.BarcodeFormat.DATA_MATRIX]: 'data_matrix',
|
|
13
|
+
[library_1.BarcodeFormat.EAN_8]: 'ean_8',
|
|
14
|
+
[library_1.BarcodeFormat.EAN_13]: 'ean_13',
|
|
15
|
+
[library_1.BarcodeFormat.ITF]: 'itf',
|
|
16
|
+
[library_1.BarcodeFormat.PDF_417]: 'pdf417',
|
|
17
|
+
[library_1.BarcodeFormat.QR_CODE]: 'qr_code',
|
|
18
|
+
[library_1.BarcodeFormat.UPC_A]: 'upc_a',
|
|
19
|
+
[library_1.BarcodeFormat.UPC_E]: 'upc_e',
|
|
20
|
+
[library_1.BarcodeFormat.UPC_EAN_EXTENSION]: 'unknown',
|
|
21
|
+
[library_1.BarcodeFormat.MAXICODE]: 'unknown',
|
|
22
|
+
[library_1.BarcodeFormat.RSS_14]: 'unknown',
|
|
23
|
+
[library_1.BarcodeFormat.RSS_EXPANDED]: 'unknown',
|
|
24
|
+
};
|
|
25
|
+
exports.nativeToZxingFormat = {
|
|
26
|
+
aztec: library_1.BarcodeFormat.AZTEC,
|
|
27
|
+
codabar: library_1.BarcodeFormat.CODABAR,
|
|
28
|
+
code_39: library_1.BarcodeFormat.CODE_39,
|
|
29
|
+
code_93: library_1.BarcodeFormat.CODE_93,
|
|
30
|
+
code_128: library_1.BarcodeFormat.CODE_128,
|
|
31
|
+
data_matrix: library_1.BarcodeFormat.DATA_MATRIX,
|
|
32
|
+
ean_8: library_1.BarcodeFormat.EAN_8,
|
|
33
|
+
ean_13: library_1.BarcodeFormat.EAN_13,
|
|
34
|
+
itf: library_1.BarcodeFormat.ITF,
|
|
35
|
+
pdf417: library_1.BarcodeFormat.PDF_417,
|
|
36
|
+
qr_code: library_1.BarcodeFormat.QR_CODE,
|
|
37
|
+
upc_a: library_1.BarcodeFormat.UPC_A,
|
|
38
|
+
upc_e: library_1.BarcodeFormat.UPC_E,
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;;AAAA,4CAA+C;AAE/C,2HAA2H;AAE9G,QAAA,mBAAmB,GAAkC;IAChE,CAAC,uBAAa,CAAC,KAAK,CAAC,EAAE,OAAO;IAC9B,CAAC,uBAAa,CAAC,OAAO,CAAC,EAAE,SAAS;IAClC,CAAC,uBAAa,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K;IAC1B,KAAK,EAAE,uBAAa,CAAC,KAAK;CAC3B,CAAC"}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import type { IDetectedBarcode, IBarcodeDetector } from './models';
|
|
2
2
|
export declare class BarcodeDetector implements IBarcodeDetector {
|
|
3
3
|
private reader;
|
|
4
|
-
private static zxingToNativeFormat;
|
|
5
|
-
private static nativeToZxingFormat;
|
|
6
4
|
constructor(options?: {
|
|
7
5
|
formats: string[];
|
|
8
6
|
});
|
|
@@ -1,56 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BrowserMultiFormatReader } from '@zxing/browser';
|
|
2
2
|
import { DecodeHintType, NotFoundException } from '@zxing/library';
|
|
3
|
+
import { nativeToZxingFormat, zxingToNativeFormat } from './constants';
|
|
3
4
|
export class BarcodeDetector {
|
|
4
5
|
reader;
|
|
5
|
-
// format names taken from https://developer.mozilla.org/en-US/docs/Web/API/Barcode_Detection_API#supported_barcode_formats
|
|
6
|
-
static zxingToNativeFormat = {
|
|
7
|
-
[BarcodeFormat.AZTEC]: 'aztec',
|
|
8
|
-
[BarcodeFormat.CODABAR]: 'codabar',
|
|
9
|
-
[BarcodeFormat.CODE_39]: 'code_39',
|
|
10
|
-
[BarcodeFormat.CODE_93]: 'code_93',
|
|
11
|
-
[BarcodeFormat.CODE_128]: 'code_128',
|
|
12
|
-
[BarcodeFormat.DATA_MATRIX]: 'data_matrix',
|
|
13
|
-
[BarcodeFormat.EAN_8]: 'ean_8',
|
|
14
|
-
[BarcodeFormat.EAN_13]: 'ean_13',
|
|
15
|
-
[BarcodeFormat.ITF]: 'itf',
|
|
16
|
-
[BarcodeFormat.PDF_417]: 'pdf417',
|
|
17
|
-
[BarcodeFormat.QR_CODE]: 'qr_code',
|
|
18
|
-
[BarcodeFormat.UPC_A]: 'upc_a',
|
|
19
|
-
[BarcodeFormat.UPC_E]: 'upc_e',
|
|
20
|
-
[BarcodeFormat.UPC_EAN_EXTENSION]: 'unknown',
|
|
21
|
-
[BarcodeFormat.MAXICODE]: 'unknown',
|
|
22
|
-
[BarcodeFormat.RSS_14]: 'unknown',
|
|
23
|
-
[BarcodeFormat.RSS_EXPANDED]: 'unknown',
|
|
24
|
-
};
|
|
25
|
-
static nativeToZxingFormat = {
|
|
26
|
-
aztec: BarcodeFormat.AZTEC,
|
|
27
|
-
codabar: BarcodeFormat.CODABAR,
|
|
28
|
-
code_39: BarcodeFormat.CODE_39,
|
|
29
|
-
code_93: BarcodeFormat.CODE_93,
|
|
30
|
-
code_128: BarcodeFormat.CODE_128,
|
|
31
|
-
data_matrix: BarcodeFormat.DATA_MATRIX,
|
|
32
|
-
ean_8: BarcodeFormat.EAN_8,
|
|
33
|
-
ean_13: BarcodeFormat.EAN_13,
|
|
34
|
-
itf: BarcodeFormat.ITF,
|
|
35
|
-
pdf417: BarcodeFormat.PDF_417,
|
|
36
|
-
qr_code: BarcodeFormat.QR_CODE,
|
|
37
|
-
upc_a: BarcodeFormat.UPC_A,
|
|
38
|
-
upc_e: BarcodeFormat.UPC_E,
|
|
39
|
-
};
|
|
40
6
|
constructor(options) {
|
|
41
7
|
const hints = new Map([
|
|
42
8
|
[DecodeHintType.TRY_HARDER, true],
|
|
43
9
|
[
|
|
44
10
|
DecodeHintType.POSSIBLE_FORMATS,
|
|
45
11
|
options
|
|
46
|
-
? options.formats.map((f) =>
|
|
47
|
-
: Object.values(
|
|
12
|
+
? options.formats.map((f) => nativeToZxingFormat[f])
|
|
13
|
+
: Object.values(nativeToZxingFormat),
|
|
48
14
|
],
|
|
49
15
|
]);
|
|
50
16
|
this.reader = new BrowserMultiFormatReader(hints);
|
|
51
17
|
}
|
|
52
18
|
static getSupportedFormats() {
|
|
53
|
-
return Promise.resolve(Object.values(
|
|
19
|
+
return Promise.resolve(Object.values(zxingToNativeFormat));
|
|
54
20
|
}
|
|
55
21
|
async detect(imageSource) {
|
|
56
22
|
try {
|
|
@@ -73,7 +39,7 @@ export class BarcodeDetector {
|
|
|
73
39
|
}
|
|
74
40
|
return [{
|
|
75
41
|
rawValue: result.getText(),
|
|
76
|
-
format:
|
|
42
|
+
format: zxingToNativeFormat[result.getBarcodeFormat()],
|
|
77
43
|
boundingBox: new DOMRectReadOnly(),
|
|
78
44
|
cornerPoints: result.getResultPoints().map((p) => ({ x: p.getX(), y: p.getY() })),
|
|
79
45
|
}];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BarcodeDetector.js","sourceRoot":"","sources":["../../src/BarcodeDetector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"BarcodeDetector.js","sourceRoot":"","sources":["../../src/BarcodeDetector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAU,MAAM,gBAAgB,CAAC;AAE3E,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAEvE,MAAM,OAAO,eAAe;IAClB,MAAM,CAA2B;IAEzC,YAAY,OAA+B;QACzC,MAAM,KAAK,GAAG,IAAI,GAAG,CAA0B;YAC7C,CAAC,cAAc,CAAC,UAAU,EAAE,IAAI,CAAC;YACjC;gBACE,cAAc,CAAC,gBAAgB;gBAC/B,OAAO;oBACL,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC;oBACpD,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,mBAAmB,CAAC;aACvC;SACF,CAAC,CAAC;QAEH,IAAI,CAAC,MAAM,GAAG,IAAI,wBAAwB,CAAC,KAAK,CAAC,CAAC;IACpD,CAAC;IAEM,MAAM,CAAC,mBAAmB;QAC/B,OAAO,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC,CAAC;IAC7D,CAAC;IAEM,K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,YAAY,iBAAiB,CAAC,EAAE;gBAC9C,MAAM,GAAG,CAAC;aACX;YAED,OAAO,EAAE,CAAC;SACX;IACH,CAAC;IAEO,KAAK,CAAC,WAAW,CAAC,IAAU;QAClC,OAAO,IAAI,OAAO,CAAmB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACvD,MAAM,WAAW,GAAG,GAAG,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;YAC9C,MAAM,KAAK,GAAG,IAAI,KAAK,EAAE,CAAC;YAC1B,KAAK,CAAC,MAAM,GAAG,GAAG,EAAE;gBAClB,GAAG,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC;gBACjC,OAAO,CAAC,KAAK,CAAC,CAAC;YACjB,CAAC,CAAC;YACF,KAAK,CAAC,OAAO,GAAG,GAAG,EAAE,CAAC,MAAM,EAAE,CAAC;YAE/B,KAAK,CAAC,GAAG,GAAG,WAAW,CAAC;QAC1B,CAAC,CAAC,CAAC;IACL,CAAC;IAEO,mBAAmB,CAAC,WAAwB;QAClD,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QAChD,MAAM,GAAG,GAAG,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QAEpC,IAAI,GAAG,EAAE;YACP,GAAG,CAAC,SAAS,CAAC,WAAW,EAAE,WAAW,CAAC,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;SACnE;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { BarcodeFormat } from '@zxing/library';
|
|
2
|
+
// format names taken from https://developer.mozilla.org/en-US/docs/Web/API/Barcode_Detection_API#supported_barcode_formats
|
|
3
|
+
export const zxingToNativeFormat = {
|
|
4
|
+
[BarcodeFormat.AZTEC]: 'aztec',
|
|
5
|
+
[BarcodeFormat.CODABAR]: 'codabar',
|
|
6
|
+
[BarcodeFormat.CODE_39]: 'code_39',
|
|
7
|
+
[BarcodeFormat.CODE_93]: 'code_93',
|
|
8
|
+
[BarcodeFormat.CODE_128]: 'code_128',
|
|
9
|
+
[BarcodeFormat.DATA_MATRIX]: 'data_matrix',
|
|
10
|
+
[BarcodeFormat.EAN_8]: 'ean_8',
|
|
11
|
+
[BarcodeFormat.EAN_13]: 'ean_13',
|
|
12
|
+
[BarcodeFormat.ITF]: 'itf',
|
|
13
|
+
[BarcodeFormat.PDF_417]: 'pdf417',
|
|
14
|
+
[BarcodeFormat.QR_CODE]: 'qr_code',
|
|
15
|
+
[BarcodeFormat.UPC_A]: 'upc_a',
|
|
16
|
+
[BarcodeFormat.UPC_E]: 'upc_e',
|
|
17
|
+
[BarcodeFormat.UPC_EAN_EXTENSION]: 'unknown',
|
|
18
|
+
[BarcodeFormat.MAXICODE]: 'unknown',
|
|
19
|
+
[BarcodeFormat.RSS_14]: 'unknown',
|
|
20
|
+
[BarcodeFormat.RSS_EXPANDED]: 'unknown',
|
|
21
|
+
};
|
|
22
|
+
export const nativeToZxingFormat = {
|
|
23
|
+
aztec: BarcodeFormat.AZTEC,
|
|
24
|
+
codabar: BarcodeFormat.CODABAR,
|
|
25
|
+
code_39: BarcodeFormat.CODE_39,
|
|
26
|
+
code_93: BarcodeFormat.CODE_93,
|
|
27
|
+
code_128: BarcodeFormat.CODE_128,
|
|
28
|
+
data_matrix: BarcodeFormat.DATA_MATRIX,
|
|
29
|
+
ean_8: BarcodeFormat.EAN_8,
|
|
30
|
+
ean_13: BarcodeFormat.EAN_13,
|
|
31
|
+
itf: BarcodeFormat.ITF,
|
|
32
|
+
pdf417: BarcodeFormat.PDF_417,
|
|
33
|
+
qr_code: BarcodeFormat.QR_CODE,
|
|
34
|
+
upc_a: BarcodeFormat.UPC_A,
|
|
35
|
+
upc_e: BarcodeFormat.UPC_E,
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","source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AAE,aAAa,CAAC,WAAW;IACtC,KAAK,EAAE,aAAa,CAAC,KAAK;IAC1B,MAAM,EAAE,aAAa,CAAC,MAAM;IAC5B,GAAG,EAAE,aAAa,CAAC,GAAG;IACtB,MAAM,EAAE,aAAa,CAAC,OAAO;IAC7B,OAAO,EAAE,aAAa,CAAC,OAAO;IAC9B,KAAK,EAAE,aAAa,CAAC,KAAK;IAC1B,KAAK,EAAE,aAAa,CAAC,KAAK;CAC3B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "barcode-detector-api-polyfill",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "A polyfill for the BarcodeDetector API using the ZXing library",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"clean": "shx rm -rf dist",
|
|
8
|
-
"build": "npm run clean && tsc && npm run build:cjs && npm run build:browser && npm run build:copy",
|
|
8
|
+
"build": "npm run clean && npm run test && tsc && npm run build:cjs && npm run build:browser && npm run build:copy",
|
|
9
9
|
"build:cjs": "tsc --build tsconfig.cjs.json",
|
|
10
10
|
"build:browser": "esbuild src/browser.ts --outfile=dist/browser/barcode-detector-polyfill.min.js --bundle --tree-shaking --target=firefox112,safari16 --minify --sourcemap",
|
|
11
11
|
"build:copy": "shx cp README.md dist && shx cp package.json dist && shx cp LICENSE dist",
|
|
12
|
-
"lint": "eslint src",
|
|
13
|
-
"test": "
|
|
12
|
+
"lint": "eslint src __tests__",
|
|
13
|
+
"test": "jest"
|
|
14
14
|
},
|
|
15
15
|
"keywords": [
|
|
16
16
|
"barcode",
|
|
@@ -36,12 +36,18 @@
|
|
|
36
36
|
"@zxing/library": "^0.20.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
+
"@types/jest": "^29.5.2",
|
|
39
40
|
"@types/node": "^18.16.19",
|
|
40
41
|
"@typescript-eslint/eslint-plugin": "^5.61.0",
|
|
41
42
|
"@typescript-eslint/parser": "^5.61.0",
|
|
43
|
+
"canvas": "^2.11.2",
|
|
42
44
|
"esbuild": "^0.18.11",
|
|
43
45
|
"eslint": "^8.44.0",
|
|
46
|
+
"jest": "^29.6.1",
|
|
47
|
+
"jest-canvas-mock": "^2.5.2",
|
|
48
|
+
"jest-environment-jsdom": "^29.6.1",
|
|
44
49
|
"shx": "^0.3.4",
|
|
50
|
+
"ts-jest": "^29.1.1",
|
|
45
51
|
"typescript": "~5.1.6"
|
|
46
52
|
}
|
|
47
53
|
}
|