kalbuddy-barcode-scanner
v0.0.2
Published
Build for Kaloriq
Readme
kalbuddy-barcode-scanner
Build for Digmio
Install
npm install kalbuddy-barcode-scanner
npx cap syncAPI
startScanning(...)stopScanning()checkCameraPermission()requestCameraPermission()switchCamera()toggleFlash()takePhoto()canScan()getScanUsage()setPremiumStatus(...)resetScanCount()addListener('barcodeScanned', ...)addListener('photoTaken', ...)addListener('labelTaken', ...)addListener('foodAnalyzed', ...)addListener('labelAnalyzed', ...)removeAllListeners()- Interfaces
startScanning(...)
startScanning(options: ScanOptions) => Promise<void>Start the barcode scanner with camera preview
| Param | Type |
| ------------- | --------------------------------------------------- |
| options | ScanOptions |
stopScanning()
stopScanning() => Promise<void>Stop the barcode scanner and dismiss the camera
checkCameraPermission()
checkCameraPermission() => Promise<{ granted: boolean; }>Check if camera permission is granted
Returns: Promise<{ granted: boolean; }>
requestCameraPermission()
requestCameraPermission() => Promise<{ granted: boolean; }>Request camera permission
Returns: Promise<{ granted: boolean; }>
switchCamera()
switchCamera() => Promise<void>Switch between front and back camera
toggleFlash()
toggleFlash() => Promise<{ enabled: boolean; }>Toggle flash on/off
Returns: Promise<{ enabled: boolean; }>
takePhoto()
takePhoto() => Promise<{ base64: string; }>Take a photo for food analysis
Returns: Promise<{ base64: string; }>
canScan()
canScan() => Promise<ScanUsageInfo>Check if user can perform a scan (within daily limit)
Returns: Promise<ScanUsageInfo>
getScanUsage()
getScanUsage() => Promise<ScanUsageInfo>Get current scan usage statistics
Returns: Promise<ScanUsageInfo>
setPremiumStatus(...)
setPremiumStatus(options: { isPremium: boolean; expiryDate?: number; }) => Promise<{ success: boolean; }>Set premium status for user (called from RevenueCat)
| Param | Type |
| ------------- | --------------------------------------------------------- |
| options | { isPremium: boolean; expiryDate?: number; } |
Returns: Promise<{ success: boolean; }>
resetScanCount()
resetScanCount() => Promise<ScanUsageInfo>Reset scan count (for testing purposes)
Returns: Promise<ScanUsageInfo>
addListener('barcodeScanned', ...)
addListener(eventName: 'barcodeScanned', listenerFunc: (result: ScanResult) => void) => Promise<PluginListenerHandle>Listen for barcode scan events
| Param | Type |
| ------------------ | ---------------------------------------------------------------------- |
| eventName | 'barcodeScanned' |
| listenerFunc | (result: ScanResult) => void |
Returns: Promise<PluginListenerHandle>
addListener('photoTaken', ...)
addListener(eventName: 'photoTaken', listenerFunc: (result: PhotoResult) => void) => Promise<PluginListenerHandle>Listen for photo taken events
| Param | Type |
| ------------------ | ------------------------------------------------------------------------ |
| eventName | 'photoTaken' |
| listenerFunc | (result: PhotoResult) => void |
Returns: Promise<PluginListenerHandle>
addListener('labelTaken', ...)
addListener(eventName: 'labelTaken', listenerFunc: (result: LabelResult) => void) => Promise<PluginListenerHandle>Listen for label taken events
| Param | Type |
| ------------------ | ------------------------------------------------------------------------ |
| eventName | 'labelTaken' |
| listenerFunc | (result: LabelResult) => void |
Returns: Promise<PluginListenerHandle>
addListener('foodAnalyzed', ...)
addListener(eventName: 'foodAnalyzed', listenerFunc: (result: FoodAnalysisResult) => void) => Promise<PluginListenerHandle>Listen for food analysis events
| Param | Type |
| ------------------ | -------------------------------------------------------------------------------------- |
| eventName | 'foodAnalyzed' |
| listenerFunc | (result: FoodAnalysisResult) => void |
Returns: Promise<PluginListenerHandle>
addListener('labelAnalyzed', ...)
addListener(eventName: 'labelAnalyzed', listenerFunc: (result: LabelAnalysisResult) => void) => Promise<PluginListenerHandle>Listen for label analysis events
| Param | Type |
| ------------------ | ---------------------------------------------------------------------------------------- |
| eventName | 'labelAnalyzed' |
| listenerFunc | (result: LabelAnalysisResult) => void |
Returns: Promise<PluginListenerHandle>
removeAllListeners()
removeAllListeners() => Promise<void>Remove all listeners
Interfaces
ScanOptions
| Prop | Type | Description |
| ------------------ | -------------------------------------------- | --------------------------------------------------------------- |
| camera | 'front' | 'back' | Camera to use (front or back) |
| mode | 'barcode' | 'photo' | 'label' | Scan mode (barcode detection, photo capture, or label scanning) |
| showControls | boolean | Whether to show camera controls |
| timeout | number | Timeout in seconds (0 = no timeout) |
ScanUsageInfo
| Prop | Type | Description |
| ------------------ | -------------------- | -------------------------------------- |
| currentCount | number | Number of scans used today |
| limit | number | Daily scan limit for current user type |
| remaining | number | Remaining scans today |
| isPremium | boolean | Whether user has premium status |
| canScan | boolean | Whether user can perform another scan |
| limitReached | boolean | Whether daily limit has been reached |
PluginListenerHandle
| Prop | Type |
| ------------ | ----------------------------------------- |
| remove | () => Promise<void> |
ScanResult
| Prop | Type | Description |
| ---------------- | ------------------- | --------------------------------------- |
| barcode | string | The scanned barcode/QR code value |
| format | string | The barcode format (EAN13, UPC_A, etc.) |
| image | string | Base64 encoded image of the scan moment |
| confidence | number | Confidence level of the scan (0-1) |
PhotoResult
| Prop | Type | Description |
| ------------ | ------------------- | -------------------- |
| base64 | string | Base64 encoded image |
| width | number | Image width |
| height | number | Image height |
LabelResult
| Prop | Type | Description |
| ------------ | ------------------- | -------------------- |
| base64 | string | Base64 encoded image |
| width | number | Image width |
| height | number | Image height |
FoodAnalysisResult
| Prop | Type | Description |
| -------------- | -------------------------------------------------------------------------------------------------------------- | -------------------- |
| foodData | { name: string; foods: any[]; total: any; confidence: string; notes: string; timestamp: string; } | Analyzed food data |
| photo | string | Base64 encoded photo |
LabelAnalysisResult
| Prop | Type | Description |
| --------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------- |
| labelData | { name: string; ingredients: string[]; nutrition: any; allergens: string[]; claims: string[]; brand: string; confidence: string; notes: string; timestamp: string; } | Analyzed label data |
| photo | string | Base64 encoded photo |
