@scr2em/capacitor-scanner
v6.0.33
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(...)- 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) => any| Param | Type |
| ------------------ | ---------------------------------------------------------------------------------------- |
| event | 'barcodeScanned' |
| listenerFunc | (result: BarcodeScannedEvent) => void |
Returns: any
addListener('rectangleDetected', ...)
addListener(event: 'rectangleDetected', listenerFunc: (result: RectangleDetectedEvent) => void) => any| Param | Type |
| ------------------ | ---------------------------------------------------------------------------------------------- |
| event | 'rectangleDetected' |
| listenerFunc | (result: RectangleDetectedEvent) => void |
Returns: any
removeAllListeners()
removeAllListeners() => anyReturns: 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
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; }
CapturePhotoResult
{ imageBase64: 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' |
