Skip to content

Commit 2e7370a

Browse files
committed
advanced text field extraction
1 parent 78aaa12 commit 2e7370a

File tree

1 file changed

+50
-34
lines changed

1 file changed

+50
-34
lines changed

src/ext/text.ts

Lines changed: 50 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,66 @@
11
import {
2-
TextAvailableSource as AvailableSource,
3-
CheckResult,
4-
Text as BaseText,
5-
TextFieldType
2+
TextAvailableSource as AvailableSource,
3+
CheckResult,
4+
Text as BaseText,
5+
TextFieldType, LCID
66
} from "../models/index.js";
77
import {TextField} from "./text-field.js";
88

99

1010
export class Text implements BaseText {
1111

12-
status: CheckResult;
13-
validityStatus: CheckResult;
14-
comparisonStatus: CheckResult;
12+
status: CheckResult;
13+
validityStatus: CheckResult;
14+
comparisonStatus: CheckResult;
1515

16-
availableSourceList: Array<AvailableSource>;
17-
fieldList: Array<TextField>;
16+
availableSourceList: Array<AvailableSource>;
17+
fieldList: Array<TextField>;
1818

19-
constructor(origin: BaseText) {
20-
this.status = origin.status
21-
this.validityStatus = origin.validityStatus
22-
this.comparisonStatus = origin.comparisonStatus
23-
this.availableSourceList = origin.availableSourceList
24-
this.fieldList = origin.fieldList.map(field => new TextField(field))
25-
}
19+
constructor(origin: BaseText) {
20+
this.status = origin.status
21+
this.validityStatus = origin.validityStatus
22+
this.comparisonStatus = origin.comparisonStatus
23+
this.availableSourceList = origin.availableSourceList
24+
this.fieldList = origin.fieldList.map(field => new TextField(field))
25+
}
2626

27-
public getField(type: TextFieldType, lcid?: number): TextField | undefined {
28-
return this.fieldList.find(field => field.fieldType == type && (!lcid || field.lcid == lcid))
27+
public getField(type: TextFieldType, lcid?: number): TextField | undefined {
28+
let result = undefined
29+
for (const field of this.fieldList) {
30+
if (field.fieldType == type) {
31+
if (lcid != undefined && field.lcid == lcid) {
32+
return field
33+
} else if (lcid == undefined && field.lcid == LCID.LATIN) {
34+
return field
35+
} else if (lcid == undefined && result == undefined) {
36+
result = field
37+
}
38+
}
2939
}
40+
return result
41+
}
3042

31-
public getFieldValue(type: TextFieldType, lcid?: number): string | undefined {
32-
const field = this.getField(type, lcid)
33-
if (field) {
34-
return field.getValue()
43+
public getFieldByName(name: string, lcid?: number): TextField | undefined {
44+
let result = undefined
45+
for (const field of this.fieldList) {
46+
if (field.fieldName == name) {
47+
if (lcid != undefined && field.lcid == lcid) {
48+
return field
49+
} else if (lcid == undefined && field.lcid == LCID.LATIN) {
50+
return field
51+
} else if (lcid == undefined && result == undefined) {
52+
result = field
3553
}
36-
return undefined
54+
}
3755
}
56+
return result
57+
}
3858

39-
public getFieldByName(name: string, lcid?: number): TextField | undefined {
40-
return this.fieldList.find(field => field.fieldName == name && (!lcid || field.lcid == lcid))
41-
}
59+
public getFieldValue(type: TextFieldType, lcid?: number): string | undefined {
60+
return this.getField(type, lcid)?.getValue()
61+
}
4262

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-
}
50-
}
63+
public getFieldValueByName(name: string, lcid?: number): string | undefined {
64+
return this.getFieldByName(name, lcid)?.getValue()
65+
}
66+
}

0 commit comments

Comments
 (0)