-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
255 lines (227 loc) · 10.5 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
'use strict';
import { Platform, NativeModules } from 'react-native';
import { RecognizerResultState } from './recognizer'
const BlinkInputNative = Platform.select({
ios: NativeModules.BlinkInputIos,
android: NativeModules.BlinkInputAndroid
})
/**
* This exposes the appropriate native BlinkInput module module as a JS module, based on
* detected platform: Android or iOS. This has functions:
* -> 'scanWithCamera' which takes the following parameters:
* 1. Object overlaySettings: instance of OverlaySettings, contains settings for desired camera overlay
* 2. RecognizerCollection recognizerCollection: object containing recognizers to use for scanning
* 3. String license: BlinkInput base64 license key bound to application ID for Android or iOS. To obtain
* valid license key, please visit http://microblink.com/login or
* contact us at http://help.microblink.com
*
* OR
*
* Object license: containing:
* - mandatory parameter 'licenseKey': base64 license key bound to application ID
* for Android or iOS. To obtain valid license key, please visit
* http://microblink.com/login or contact us at http://help.microblink.com
* - optioanl parameter 'licensee' when license for multiple apps is used
* - optional flag 'showTimeLimitedLicenseKeyWarning' which indicates
* whether warning for time limited license key will be shown
* in format
* {
* licenseKey: '<base64iOSLicense or base64AndroidLicense>',
* licensee: String,
* showTimeLimitedLicenseKeyWarning: Boolean
* }
* -> 'captureDocument' which takes following parameters:
* 1. DocumentCaptureRecognizer documentCaptureRecognizer: object containing settings for document capture recognizer
* 2. String license: the same as 'license' for 'scanWithCamera' function
*/
class BlinkInputWrapper {
async scanWithCamera(overlaySettings, recognizerCollection, license) {
try {
var bla = NativeModules;
console.log(bla);
var licenseObject = license;
if (typeof license === 'string' || license instanceof String) {
licenseObject = { licenseKey: license };
}
const nativeResults = await BlinkInputNative.scanWithCamera(overlaySettings, recognizerCollection, licenseObject);
if (nativeResults.length != recognizerCollection.recognizerArray.length) {
console.log("INTERNAL ERROR: native plugin returned wrong number of results!");
return [];
} else {
let results = [];
for (let i = 0; i < nativeResults.length; ++i) {
// native plugin must ensure types match
// recognizerCollection.recognizerArray[i].result = recognizerCollection.recognizerArray[i].createResultFromNative(nativeResults[i]);
// unlike Cordova, ReactNative does not allow mutation of user-provided recognizers, so we need to
// return results and let user handle them manually.
let result = recognizerCollection.recognizerArray[i].createResultFromNative(nativeResults[i]);
if (result.resultState != RecognizerResultState.empty) {
results.push(result);
}
}
return results;
}
} catch (error) {
console.log(error);
return [];
}
}
async captureDocument(documentCaptureRecognizer, license) {
try {
var licenseObject = license;
if (typeof license === 'string' || license instanceof String) {
licenseObject = { licenseKey: license };
}
const nativeDocumentCaptureResult = await BlinkInputNative.captureDocument(documentCaptureRecognizer, licenseObject);
return new DocumentCaptureResult(nativeDocumentCaptureResult);
} catch (error) {
console.log(error);
return [];
}
}
async scanWithFieldByField(fieldByFieldCollection, license) {
try {
var licenseObject = license;
if (typeof license === 'string' || license instanceof String) {
licenseObject = { licenseKey: license };
}
const nativeFieldByFieldResult = await BlinkInputNative.scanWithFieldByField(fieldByFieldCollection, licenseObject);
let results = [];
for (let i = 0; i < nativeFieldByFieldResult.length; ++i) {
let result = new FieldByFieldResult(nativeFieldByFieldResult[i]);
results.push(result);
}
return results;
} catch (error) {
console.log(error);
return [];
}
}
}
export var BlinkInput = new BlinkInputWrapper();
import { Recognizer } from './recognizer'
/**
* Represents a collection of recognizer objects.
*/
export class RecognizerCollection {
/**
*
* @param recognizerArray Array of recognizer objects that will be used for recognition. Must not be empty!
*/
constructor(recognizerArray) {
/** Array of recognizer objects that will be used for recognition */
this.recognizerArray = recognizerArray;
/**
* Whether or not it is allowed for multiple recognizers to process the same image.
* If not, then first recognizer that will be successful in processing the image will
* end the processing chain and other recognizers will not get the chance to process
* that image.
*/
this.allowMultipleResults = false;
/** Number of miliseconds after first non-empty result becomes available to end scanning with a timeout */
this.milisecondsBeforeTimeout = 10000;
if (!(this.recognizerArray instanceof Array)) {
throw new Error("recognizerArray must be array of Recognizer objects!");
}
// ensure every element in array is Recognizer
for (var i = 0; i < this.recognizerArray.length; ++i) {
if (!(this.recognizerArray[i] instanceof Recognizer )) {
throw new Error( "Each element in recognizerArray must be instance of Recognizer" );
}
}
}
}
import { Parser } from './parser'
/**
* Represents a collection of scane elements
*/
export class FieldByFieldCollection {
/**
*
* @param fieldByFieldElementArray Array of field by field elements objects that will be used for recognition. Must not be empty!
*/
constructor(fieldByFieldElementArray) {
/** Array of recognizer objects that will be used for recognition */
this.fieldByFieldElementArray = fieldByFieldElementArray;
if (!(this.fieldByFieldElementArray instanceof Array)) {
throw new Error("recognizerArray must be array of Recognizer objects!");
}
// ensure every element in array is Recognizer
for (var i = 0; i < this.fieldByFieldElementArray.length; ++i) {
if (!(this.fieldByFieldElementArray[i] instanceof FieldByFieldElement )) {
throw new Error( "Each element in fieldByFieldElementArray must be instance of FieldByFieldElement" );
}
}
}
}
export class FieldByFieldElement {
constructor(identifier, parser, localizedTitle, localizedTooltip) {
/**
* Unique name of the element
*/
this.identifier = identifier;
/**
Parser object which is reponsible scanning the text.
*/
this.parser = parser;
/**
* Localized title (used in the Pivot control)
*/
this.localizedTitle = localizedTitle;
/**
* Localized tooltip (used in the tooltip label above the viewfinder)
*/
this.localizedTooltip = localizedTooltip;
if (!(this.parser instanceof Parser)) {
throw new Error("Parser must be instance of Parser!");
}
}
}
export class FieldByFieldResult {
constructor(nativeFieldByFieldResult) {
/**
* Unique name of the element
*/
this.identifier = nativeFieldByFieldResult.identifier;
/**
Value of parser object after scanning.
*/
this.value = nativeFieldByFieldResult.value;
}
}
import { DocumentCaptureRecognizerResult } from './recognizers/documentCaptureRecognizer'
/**
* Represents a result of 'captureDocument' functionality.
*/
export class DocumentCaptureResult {
constructor(nativeDocumentCaptureResult) {
this.documentCaptureRecognizerResult = new DocumentCaptureRecognizerResult(nativeDocumentCaptureResult.documentCaptureRecognizerResult);
this.capturedFullImage = nativeDocumentCaptureResult.capturedFullImage;
}
}
export { RecognizerResultState } from './recognizer'
export * from './types'
// export overlays that can be used
export * from './overlays/barcodeOverlays'
// export recognizers that can be used and their results
export * from './recognizers/successFrameGrabberRecognizer'
export * from './recognizers/barcodeRecognizer'
export * from './recognizers/documentCaptureRecognizer'
export * from './recognizers/pdf417Recognizer'
export * from './recognizers/simNumberRecognizer'
// export * from './recognizers/blinkInputRecognizer'
export { ParserResultState } from './parser'
export { ProcessorResultState } from './processor'
// export parsers that can be used and their results
export * from './parsers/amountParser'
export * from './parsers/dateParser'
export * from './parsers/emailParser'
export * from './parsers/ibanParser'
export * from './parsers/licensePlatesParser'
export * from './parsers/rawParser'
export * from './parsers/topUpParser'
export * from './parsers/vinParser'
export * from './parsers/regexParser'
// // export processors that can be used and their results
// export * from './processors/parserGroupProcessor'
//