Skip to content

Commit 78aaa12

Browse files
alshundactions-userAleksey Shundrikhleb-albau
authored
rl-476/field-name FieldName: (#11)
Co-authored-by: GitHub Action <action@github.com> Co-authored-by: Aleksey Shundrik <al.shundrik@insspring.com> Co-authored-by: Hleb Albau <hleb.albau@gmail.com>
1 parent 60b7880 commit 78aaa12

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

example/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ const {DOCUMENT_NUMBER} = TextFieldType;
3636

3737
// text fields example
3838
const docNumberField = response.text.getField(DOCUMENT_NUMBER);
39+
const docNumberFieldByName = response.text.getFieldByName("Document Number")
40+
3941
const docNumberVisual = docNumberField.getValue(Source.VISUAL)
4042
const docNumberMrz = docNumberField.getValue(Source.MRZ)
4143
const docNumberVisualValidity = docNumberField.sourceValidity(Source.VISUAL)

src/ext/text.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {
22
TextAvailableSource as AvailableSource,
33
CheckResult,
4-
54
Text as BaseText,
65
TextFieldType
76
} from "../models/index.js";
@@ -28,4 +27,24 @@ export class Text implements BaseText {
2827
public getField(type: TextFieldType, lcid?: number): TextField | undefined {
2928
return this.fieldList.find(field => field.fieldType == type && (!lcid || field.lcid == lcid))
3029
}
30+
31+
public getFieldValue(type: TextFieldType, lcid?: number): string | undefined {
32+
const field = this.getField(type, lcid)
33+
if (field) {
34+
return field.getValue()
35+
}
36+
return undefined
37+
}
38+
39+
public getFieldByName(name: string, lcid?: number): TextField | undefined {
40+
return this.fieldList.find(field => field.fieldName == name && (!lcid || field.lcid == lcid))
41+
}
42+
43+
public getFieldValueByName(name: string, lcid?: number): string | undefined {
44+
const field = this.getFieldByName(name, lcid)
45+
if (field) {
46+
return field.getValue()
47+
}
48+
return undefined
49+
}
3150
}

0 commit comments

Comments
 (0)