Skip to content

Instantly share code, notes, and snippets.

@eddiemoore
Last active July 20, 2022 23:51
Show Gist options
  • Save eddiemoore/04678592bc7894079857790c70cf823c to your computer and use it in GitHub Desktop.
Save eddiemoore/04678592bc7894079857790c70cf823c to your computer and use it in GitHub Desktop.
BarcodeDetector TypeScript types
/*
Spec: https://wicg.github.io/shape-detection-api/#barcode-detection-api
*/
interface BarcodeDetector {
detect(image: ImageBitmapSource): Promise<DetectedBarcode[]>;
}
type BarcodeFormat =
| "aztec"
| "code_128"
| "code_39"
| "code_93"
| "codabar"
| "data_matrix"
| "ean_13"
| "ean_8"
| "itf"
| "pdf417"
| "qr_code"
| "unknown"
| "upc_a"
| "upc_e";
interface BarcodeDetectorOptions {
formats: BarcodeFormat[];
}
interface Point2D {
x: number;
y: number;
}
interface DetectedBarcode {
readonly boundingBox: DOMRectReadOnly;
rawValue: string;
format: BarcodeFormat;
cornerPoints: Point2D[];
}
interface BarcodeDetectorConstructor {
/**
* A reference to the prototype.
*/
readonly prototype: BarcodeDetector;
/**
* Creates a new BarcodeDetector.
*/
new (barcodeDetectorOptions?: BarcodeDetectorOptions): BarcodeDetector;
static getSupportedFormats(): Promise<BarcodeFormat[]>;
}
declare var BarcodeDetector: BarcodeDetectorConstructor;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment