@scr2em/capacitor-scanner
v6.0.39
Published
scan codes
Readme
Capacitor Scanner
scan codes
Install
npm install capacitor-scanner
npx cap syncAPI
start(...)stop()openSettings()capturePhoto(...)checkPermissions()requestPermissions()flipCamera()toggleFlash()addListener('barcodeScanned', ...)addListener('rectangleDetected', ...)removeAllListeners()enableObjectDetection(...)disableObjectDetection()enableBarcodeDetection(...)disableBarcodeDetection()zoom(...)- Interfaces
- Type Aliases
- Enums
start(...)
start(options?: StartOptions | undefined) => anyStart the camera preview with optional barcode and object detection.
| Param | Type | Description |
| ------------- | ----------------------------------------------------- | ---------------------------------------------------- |
| options | StartOptions | - Configuration options for the camera and detection |
Returns: any
stop()
stop() => anyStop the camera preview and all detection.
Returns: any
openSettings()
openSettings() => anyReturns: any
capturePhoto(...)
capturePhoto(options?: CapturePhotoOptions | undefined) => any| Param | Type |
| ------------- | ------------------------------------------------------------------- |
| options | CapturePhotoOptions |
Returns: any
checkPermissions()
checkPermissions() => anyReturns: any
requestPermissions()
requestPermissions() => anyReturns: any
flipCamera()
flipCamera() => anyReturns: any
toggleFlash()
toggleFlash() => anyReturns: any
addListener('barcodeScanned', ...)
addListener(event: 'barcodeScanned', listenerFunc: (result: BarcodeScannedEvent) => void) => anyListen for barcode scan results. Returns a handle that can be used to remove the listener.
| Param | Type |
| ------------------ | ---------------------------------------------------------------------------------------- |
| event | 'barcodeScanned' |
| listenerFunc | (result: BarcodeScannedEvent) => void |
Returns: any
addListener('rectangleDetected', ...)
addListener(event: 'rectangleDetected', listenerFunc: (result: RectangleDetectedEvent) => void) => anyListen for rectangle (business card) detection results. Returns a handle that can be used to remove the listener.
| Param | Type |
| ------------------ | ---------------------------------------------------------------------------------------------- |
| event | 'rectangleDetected' |
| listenerFunc | (result: RectangleDetectedEvent) => void |
Returns: any
removeAllListeners()
removeAllListeners() => anyRemove all listeners for this plugin.
Returns: any
enableObjectDetection(...)
enableObjectDetection(options?: ObjectDetectionOptions | undefined) => anyEnable object detection (business card). This will start detecting business cards.
| Param | Type | Description |
| ------------- | ------------------------------------------------------------------------- | --------------------------------------------- |
| options | ObjectDetectionOptions | - Optional configuration for object detection |
Returns: any
disableObjectDetection()
disableObjectDetection() => anyDisable object detection. This will stop detecting business cards.
Returns: any
enableBarcodeDetection(...)
enableBarcodeDetection(options?: BarcodeDetectionOptions | undefined) => anyEnable barcode detection. This will start detecting barcodes.
| Param | Type | Description |
| ------------- | --------------------------------------------------------------------------- | ---------------------------------------------- |
| options | BarcodeDetectionOptions | - Optional configuration for barcode detection |
Returns: any
disableBarcodeDetection()
disableBarcodeDetection() => anyDisable barcode detection. This will stop detecting barcodes and clear cached barcodes.
Returns: any
zoom(...)
zoom(options: ZoomOptions) => anySet the camera zoom level.
| Param | Type | Description |
| ------------- | --------------------------------------------------- | ---------------------------------------------------- |
| options | ZoomOptions | - The zoom options containing the level (1, 2, or 3) |
Returns: any
Interfaces
PluginListenerHandle
| Prop | Type |
| ------------ | ------------------------- |
| remove | () => any |
Type Aliases
StartOptions
{ /** * Barcode formats to detect when barcodeDetection is enabled. / formats?: BarcodeFormat[]; /* * Camera direction to use. Defaults to 'BACK'. / cameraDirection?: 'BACK' | 'FRONT'; /* * Enable barcode detection on start. Defaults to false. * When enabled, the camera will automatically detect barcodes and emit 'barcodeScanned' events. / barcodeDetection?: boolean; /* * Whether to show the highlight overlay for detected barcodes. Defaults to false. * Only applies when barcodeDetection is true. / barcodeHighlight?: boolean; /* * Enable object detection (business card) on start. Defaults to false. * When enabled, the camera will automatically detect business cards and emit 'rectangleDetected' events. / objectDetection?: boolean; /* * Whether to show the highlight overlay for detected business cards. Defaults to true. * Only applies when objectDetection is true. / objectHighlight?: boolean; /* * Minimum interval in seconds between consecutive 'rectangleDetected' events. * Only applies when objectDetection is true. * Defaults to 0 (no throttling beyond initial stability check). / rectangleEmitIntervalSeconds?: number; /* * Optional regex pattern to filter scanned barcodes. * If provided, only barcodes matching this pattern will be reported. / regex?: string; /* * Optional regex flags (e.g., 'i' for case-insensitive, 'm' for multiline). / regexFlags?: string; /* * Cooldown in seconds after any detection event when both barcode and object detection are enabled. * After a barcode or rectangle is emitted, ALL detection pauses for this duration. * When set, barcode dedup TTL becomes 2x this value and rectangle emit interval becomes 2x this value. * Only applies when both barcodeDetection and objectDetection are true. * Defaults to 0 (no throttle, both detections run simultaneously). */ detectionThrottleSeconds?: number; }
CapturePhotoOptions
{ /** * The desired quality of the captured image, expressed as a value between 0.0 (lowest quality, smallest file size) * and 1.0 (highest quality, largest file size). Defaults to 1.0. * This parameter directly influences the compression level of the resulting JPEG image. / qualityRatio?: number; /* * When true, run on-device text recognition (OCR) on the captured image and * return the recognized text in transcribedText. Defaults to false. * The OCR runs on the same image that is returned (the cropped badge region * when a rectangle/business card was detected, otherwise the full photo). * * Supported on both platforms, but the engine differs: iOS uses Vision (see * recognitionLevel / recognitionLanguages / automaticallyDetectLanguage), * while Android uses ML Kit's Latin-script recognizer (those options are ignored). / recognizeText?: boolean; /* * Accuracy/speed trade-off for OCR. Only used when recognizeText is true. * - 'accurate' (default): slower, neural-network based, best quality. Recommended for single captured photos. * - 'fast': quicker, lower quality. Prefer for high-throughput scenarios. * * iOS only. Ignored on Android — ML Kit has no equivalent speed/accuracy setting. * * @default 'accurate' / recognitionLevel?: TextRecognitionLevel; /* * Preferred OCR languages as an ordered priority list of BCP-47 codes * (e.g. ['en-US', 'ar-SA']). Only used when recognizeText is true. * When omitted, recognition falls back to English ('en-US'). * * The set of usable codes depends on the device's iOS version, because Apple's * Vision framework adds languages in successive request revisions. Passing a * code the running OS does not support has no effect on that device. * * | iOS | Newly available languages (cumulative) | * | ------ | ----------------------------------------------------------------------------------------------------------------------- | * | 13 | en-US | * | 14 | fr-FR, it-IT, de-DE, es-ES, pt-BR | * | 16 | zh-Hans, zh-Hant, yue-Hans, yue-Hant, ko-KR, ja-JP, ru-RU, uk-UA, th-TH, vi-VT | * | 17–18 | ar-SA, ar-AE (Arabic) and additional locales | * * Not supported even on the latest iOS: Hindi/Devanagari, Hebrew, and most * Indic/Southeast-Asian scripts. The definitive per-device list comes from * Apple's supportedRecognitionLanguages() at runtime. * * Tip: narrowing this list to the languages you actually expect generally * improves both accuracy and speed versus leaving it broad. * * Ignored when automaticallyDetectLanguage is true. * * iOS only. Ignored on Android, which always uses ML Kit's Latin-script * recognizer regardless of this value. * * @default ['en-US'] / recognitionLanguages?: string[]; /* * When true, let Vision automatically pick the recognition language(s) instead * of using recognitionLanguages. Only used when recognizeText is true. * * Requires iOS 16+. On older devices this flag is ignored and recognition * falls back to recognitionLanguages (or English). Auto-detection can only * choose among the languages the device's iOS actually supports (see the * table on recognitionLanguages) — it will not read unsupported scripts. * * Mutually exclusive with recognitionLanguages: when this is true, the * explicit language list is ignored. For a known, narrow set of languages an * explicit recognitionLanguages list usually yields better accuracy/speed * than auto-detection. * * iOS only. Ignored on Android, which always uses ML Kit's Latin-script * recognizer regardless of this value. * * @default false */ automaticallyDetectLanguage?: boolean; }
TextRecognitionLevel
OCR accuracy/speed trade-off, mapped to Apple Vision's VNRequestTextRecognitionLevel.
'fast' | 'accurate'
CapturePhotoResult
{ imageBase64: string; /** * On-device recognized text from the captured image, with lines joined by '\n'. * Present only when recognizeText was requested; empty string if nothing was recognized. */ transcribedText?: string; }
PermissionsResult
{ camera: 'prompt' | 'denied' | 'granted' }
FlashResult
{ enabled: boolean }
BarcodeScannedEvent
{ scannedCode: string; format: string }
RectangleDetectedEvent
{ detected: true }
ObjectDetectionOptions
{ /** * Whether to show the highlight overlay for detected business cards. * Defaults to true. / showHighlight?: boolean, /* * Minimum interval in seconds between consecutive 'rectangleDetected' events. * After an event is emitted, no new events will be emitted until this interval passes. * Set to 0 to emit events as soon as stability is detected. * Defaults to 0 (no throttling beyond initial stability check). */ emitIntervalSeconds?: number }
BarcodeDetectionOptions
{ /** * Whether to show the highlight overlay for detected barcodes. * Defaults to false. */ showHighlight?: boolean; }
ZoomOptions
{ /** * The zoom level to set. Must be 1, 2, or 3. * - 1 = 1.0x (no zoom) * - 2 = 2.0x * - 3 = 3.0x */ level: 1 | 2 | 3; }
ZoomResult
{ level: number }
Enums
BarcodeFormat
| Members | Value |
| ---------------- | -------------------------- |
| Aztec | 'AZTEC' |
| Code39 | 'CODE_39' |
| Code93 | 'CODE_93' |
| Code128 | 'CODE_128' |
| DataMatrix | 'DATA_MATRIX' |
| Ean8 | 'EAN_8' |
| Ean13 | 'EAN_13' |
| Itf14 | 'ITF14' |
| Pdf417 | 'PDF_417' |
| QrCode | 'QR_CODE' |
| UpcE | 'UPC_E' |
