mirror of
https://github.com/danielsogl/awesome-cordova-plugins.git
synced 2025-02-13 19:29:37 +08:00
42 lines
1.3 KiB
TypeScript
42 lines
1.3 KiB
TypeScript
import {Plugin, Cordova} from './plugin';
|
|
|
|
/**
|
|
* The Barcode Scanner Plugin opens a camera view and automatically scans a barcode, returning the data back to you.
|
|
*
|
|
* Requires Cordova plugin: `phonegap-plugin-barcodescanner`. For more info, please see the [BarcodeScanner plugin docs](https://github.com/phonegap/phonegap-plugin-barcodescanner).
|
|
*
|
|
* @usage
|
|
* ```js
|
|
* BarcodeScanner.scan().then((barcodeData) => {
|
|
* // Success! Barcode data is here
|
|
* }, (err) => {
|
|
* // An error occurred
|
|
* });
|
|
* ```
|
|
*/
|
|
@Plugin({
|
|
name: 'BarcodeScanner',
|
|
plugin: 'phonegap-plugin-barcodescanner',
|
|
pluginRef: 'cordova.plugins.barcodeScanner'
|
|
})
|
|
export class BarcodeScanner {
|
|
|
|
/**
|
|
* Open the barcode scanner.
|
|
* @return Returns a Promise that resolves with scanner data, or rejects with an error.
|
|
*/
|
|
@Cordova()
|
|
static scan(){
|
|
// This Promise is replaced by one from the @Cordova decorator that wraps
|
|
// the plugin's callbacks. We provide a dummy one here so TypeScript
|
|
// knows that the correct return type is Promise, because there's no way
|
|
// for it to know the return type from a decorator.
|
|
// See https://github.com/Microsoft/TypeScript/issues/4881
|
|
return new Promise<any>((res, rej) => {});
|
|
};
|
|
|
|
// Not well supported
|
|
// @Cordova()
|
|
// static encode(type, data){};
|
|
}
|