Skip to content

Instantly share code, notes, and snippets.

@srflp
Last active August 7, 2021 12:53
Show Gist options
  • Save srflp/84219f09c009572442c6859016f4d98d to your computer and use it in GitHub Desktop.
Save srflp/84219f09c009572442c6859016f4d98d to your computer and use it in GitHub Desktop.
Barcode Detector API Types, not yet implemented in libdom.d.ts in TypeScript, because the browser support is two low. Docs: https://developer.mozilla.org/en-US/docs/Web/API/Barcode_Detection_API
// Barcode Detector API Types
// remove these types after they get implemented in TypeScript
type BarcodeFormat =
| 'aztec'
| 'code_128'
| 'code_39'
| 'code_93'
| 'codabar'
| 'data_matrix'
| 'ean_13'
| 'ean_8'
| 'itf'
| 'pdf417'
| 'qr_code'
| 'upc_a'
| 'upc_e'
| 'unknown';
interface CornerPoint {
x: number;
y: number;
}
interface DetectedBarcode {
boundingBox: DOMRectReadOnly;
cornerPoints: [CornerPoint, CornerPoint, CornerPoint, CornerPoint];
format: BarcodeFormat;
rawValue: string;
}
interface BarcodeDetector {
detect(image: ImageBitmapSource): Promise<DetectedBarcode[]>;
getSupportedFormats(): Promise<BarcodeFormat[]>;
}
interface BarcodeDetectorOptions {
formats: BarcodeFormat[];
}
declare global {
var BarcodeDetector: {
prototype: BarcodeDetector;
new (barcodeDetectorOptions?: BarcodeDetectorOptions): BarcodeDetector;
};
}
export {};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment