Skip to content

Commit c4067c5

Browse files
committed
feat(types): DetectedBarcode improvements
1. Update `detect()` to return a `DetectedBarcode` promise array 2. Update `DetectedBarcode.cornerPoints` to use a tuple and specify that `x` and `y` are of type `number`
1 parent 757651e commit c4067c5

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/BarcodeDetectorPolyfill.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ export class BarcodeDetectorPolyfill {
5656
/**
5757
* Scans an image for barcodes and returns a {@link Promise} for the result.
5858
*
59-
* @param {ImageBitmapSource} image the image to be scanned
60-
* @returns {Promise<Object>} the scan result as described for {@link BarcodeDetector}
59+
* @param {ImageBitmapSource} source the image to be scanned
60+
* @returns {Promise<Array<DetectedBarcode>>} the scan result as described for {@link BarcodeDetector}
6161
*/
6262
// TODO Enable cache for video source, disable for others unless overridden in zbarConfig
63-
detect(source: ImageBitmapSource): Promise<Array<Object>> {
63+
detect(source: ImageBitmapSource): Promise<Array<DetectedBarcode>> {
6464
// Return an empty array immediately if the source is an object with any zero dimension,
6565
// see https://wicg.github.io/shape-detection-api/#image-sources-for-detection
6666
const intrinsic = BarcodeDetectorPolyfill.intrinsicDimensions(source)

src/DetectedBarcode.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
type Point = { x: number, y: number }
2+
13
/**
24
* @see https://wicg.github.io/shape-detection-api/#detectedbarcode-section
35
*/
46
export interface DetectedBarcode {
57

68
boundingBox: DOMRectReadOnly
7-
cornerPoints: Array<{ x, y }>
9+
cornerPoints: [Point, Point, Point, Point]
810
format: string
911
rawValue: string
1012

0 commit comments

Comments
 (0)