Skip to content

Commit 3011e0a

Browse files
author
TFX-98
committed
FE-918 - fix lint
1 parent e9338cd commit 3011e0a

File tree

1 file changed

+72
-91
lines changed

1 file changed

+72
-91
lines changed

src/ext/process-response.ts

Lines changed: 72 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -14,182 +14,163 @@ import {
1414
TextResult,
1515
ChosenDocumentTypeResult,
1616
DocBarCodeInfo,
17-
TransactionInfo,
17+
TransactionInfo
1818
} from "../models/index.js";
19-
import { Text } from "./text.js";
20-
import { Images } from "./images.js";
19+
import {Text} from "./text.js";
20+
import {Images} from "./images.js";
2121
import * as converter from "base64-arraybuffer";
22-
import { Authenticity } from "./authenticity/authenticity.js";
23-
import * as pako from "pako";
22+
import {Authenticity} from "./authenticity/authenticity.js";
23+
import * as pako from 'pako'
2424

2525
export class Response {
26+
2627
// other future modules:
2728
// - authenticity
2829
// - document
29-
status?: Status;
30-
text?: Text;
31-
images?: Images;
30+
status?: Status
31+
text?: Text
32+
images?: Images
3233

33-
lowLvlResponse: LowLvlResponse;
34-
rawResponse: ProcessResponse;
34+
lowLvlResponse: LowLvlResponse
35+
rawResponse: ProcessResponse
3536

3637
constructor(original: ProcessResponse) {
37-
const lowLvlResponse = new LowLvlResponse(original);
38-
this.lowLvlResponse = lowLvlResponse;
39-
this.rawResponse = original;
4038

41-
this.status = lowLvlResponse.statusResult()?.Status;
42-
const textResult = lowLvlResponse.textResult();
39+
const lowLvlResponse = new LowLvlResponse(original)
40+
this.lowLvlResponse = lowLvlResponse
41+
this.rawResponse = original
42+
43+
this.status = lowLvlResponse.statusResult()?.Status
44+
const textResult = lowLvlResponse.textResult()
4345
if (textResult) {
44-
this.text = new Text(textResult.Text);
46+
this.text = new Text(textResult.Text)
4547
}
46-
const imagesResult = lowLvlResponse.imagesResult();
48+
const imagesResult = lowLvlResponse.imagesResult()
4749
if (imagesResult) {
48-
this.images = new Images(imagesResult.Images);
50+
this.images = new Images(imagesResult.Images)
4951
}
5052
}
5153

5254
public authenticity(page_idx = 0): Authenticity | undefined {
53-
const r = <AuthenticityResult>(
54-
this.lowLvlResponse.resultByTypeAndPage(Result.AUTHENTICITY, page_idx)
55-
);
55+
const r = <AuthenticityResult>this.lowLvlResponse.resultByTypeAndPage(Result.AUTHENTICITY, page_idx)
5656
if (r) {
57-
return new Authenticity(r.AuthenticityCheckList, page_idx);
57+
return new Authenticity(r.AuthenticityCheckList, page_idx)
5858
}
5959
}
6060

6161
public authenticityPerPage(): Array<Authenticity> {
62-
const filteredByTypeArray = <Array<AuthenticityResult>>(
63-
this.lowLvlResponse.resultsByType(Result.AUTHENTICITY)
64-
);
62+
const filteredByTypeArray = <Array<AuthenticityResult>>this.lowLvlResponse.resultsByType(Result.AUTHENTICITY)
6563

6664
return filteredByTypeArray
67-
.map(
68-
(e: AuthenticityResult) =>
69-
new Authenticity(e.AuthenticityCheckList, e.page_idx || 0)
70-
)
71-
.sort((a, b) => a.page_idx - b.page_idx);
65+
.map((e: AuthenticityResult) => new Authenticity(e.AuthenticityCheckList, e.page_idx || 0))
66+
.sort((a, b) => a.page_idx - b.page_idx)
7267
}
7368

7469
public imageQualityChecks(page_idx = 0): ImageQualityCheckList | undefined {
75-
const result = <ImageQualityResult>(
76-
this.lowLvlResponse.resultByTypeAndPage(Result.IMAGE_QUALITY, page_idx)
77-
);
70+
const result = <ImageQualityResult>this.lowLvlResponse.resultByTypeAndPage(Result.IMAGE_QUALITY, page_idx)
7871
if (result) {
7972
return result.ImageQualityCheckList;
8073
}
8174
}
8275

8376
public imageQualityChecksPerPage(): Array<ImageQualityCheckList> | undefined {
84-
return <Array<ImageQualityCheckList>>(
85-
this.lowLvlResponse.resultsByType(Result.IMAGE_QUALITY)
86-
);
77+
return <Array<ImageQualityCheckList>>this.lowLvlResponse.resultsByType(Result.IMAGE_QUALITY)
8778
}
8879

8980
public decodedLog(): string | undefined {
90-
const log = this.lowLvlResponse.log;
81+
const log = this.lowLvlResponse.log
9182
if (log) {
92-
const decoded = converter.decode(log);
93-
const uintArray = new Uint8Array(decoded);
83+
const decoded = converter.decode(log)
84+
const uintArray = new Uint8Array(decoded)
9485

95-
let dataUintArray;
86+
let dataUintArray
9687
try {
97-
const currentDataUintArray = pako.inflate(uintArray);
98-
88+
const currentDataUintArray = pako.inflate(uintArray)
89+
9990
dataUintArray =
100-
currentDataUintArray.length > uintArray.length
101-
? currentDataUintArray
102-
: uintArray;
91+
currentDataUintArray.length > uintArray.length
92+
? currentDataUintArray
93+
: uintArray
94+
10395
} catch (err) {
104-
dataUintArray = uintArray;
96+
dataUintArray = uintArray
10597
}
10698

107-
const uintArraySize = dataUintArray.length;
108-
const step = 10000;
109-
const result = [];
110-
const convertedUnitArray = [].slice.call(dataUintArray);
99+
const uintArraySize = dataUintArray.length
100+
const step = 10000
101+
const result = []
102+
const convertedUnitArray = [].slice.call(dataUintArray)
111103
// To avoid maximum call stack size excess
112104
for (let i = 0; i < uintArraySize; i += step) {
113-
const chunk = String.fromCharCode.apply(
114-
null,
115-
convertedUnitArray.slice(i, i + step)
116-
);
117-
result.push(chunk);
105+
const chunk = String.fromCharCode.apply(null, convertedUnitArray.slice(i, i + step))
106+
result.push(chunk)
118107
}
119-
return result.join("");
108+
return result.join('')
120109
} else {
121-
return undefined;
110+
return undefined
122111
}
123112
}
124113
}
125114

126115
export class LowLvlResponse implements ProcessResponse {
127-
ContainerList: ContainerList;
128-
ProcessingFinished: ProcessingStatus;
129-
TransactionInfo: TransactionInfo;
130-
ChipPage?: RfidLocation;
131-
log?: string;
132-
passBackObject?: { [key: string]: any };
116+
117+
ContainerList: ContainerList
118+
ProcessingFinished: ProcessingStatus
119+
TransactionInfo: TransactionInfo
120+
ChipPage?: RfidLocation
121+
log?: string
122+
passBackObject?: { [key: string]: any; };
133123
morePagesAvailable?: number;
134124

135125
constructor(original: ProcessResponse) {
136-
this.ContainerList = original.ContainerList;
137-
this.ProcessingFinished = original.ProcessingFinished;
138-
this.TransactionInfo = original.TransactionInfo;
139-
this.ChipPage = original.ChipPage;
140-
this.log = original.log;
141-
this.passBackObject = original.passBackObject;
142-
this.morePagesAvailable = original.morePagesAvailable;
126+
this.ContainerList = original.ContainerList
127+
this.ProcessingFinished = original.ProcessingFinished
128+
this.TransactionInfo = original.TransactionInfo
129+
this.ChipPage = original.ChipPage
130+
this.log = original.log
131+
this.passBackObject = original.passBackObject
132+
this.morePagesAvailable = original.morePagesAvailable
143133
}
144134

145135
public statusResult(): StatusResult | undefined {
146-
return <StatusResult>this.resultByType(Result.STATUS);
136+
return <StatusResult>this.resultByType(Result.STATUS)
147137
}
148138

149139
public textResult(): TextResult | undefined {
150-
return <TextResult>this.resultByType(Result.TEXT);
140+
return <TextResult>this.resultByType(Result.TEXT)
151141
}
152142

153143
public imagesResult(): ImagesResult | undefined {
154-
return <ImagesResult>this.resultByType(Result.IMAGES);
144+
return <ImagesResult>this.resultByType(Result.IMAGES)
155145
}
156146

157147
public barcodeResult(): DocBarCodeInfo | undefined {
158-
return <DocBarCodeInfo>this.resultByType(Result.BARCODES);
148+
return <DocBarCodeInfo>this.resultByType(Result.BARCODES)
159149
}
160150

161151
public documentTypeResults(): Array<ChosenDocumentTypeResult> | undefined {
162-
return <Array<ChosenDocumentTypeResult>>(
163-
this.resultsByType(Result.DOCUMENT_TYPE)
164-
);
152+
return <Array<ChosenDocumentTypeResult>>this.resultsByType(Result.DOCUMENT_TYPE)
165153
}
166154

167155
public resultByType(type: Result): ResultItem | undefined {
168156
for (const container of this.ContainerList.List) {
169157
if (container.result_type === type) {
170-
return container;
158+
return container
171159
}
172160
}
173-
return undefined;
161+
return undefined
174162
}
175163

176-
public resultByTypeAndPage(
177-
type: Result,
178-
page_idx = 0
179-
): ResultItem | undefined {
164+
public resultByTypeAndPage(type: Result, page_idx = 0): ResultItem | undefined {
180165
for (const container of this.ContainerList.List) {
181166
if (container.result_type === type && container.page_idx == page_idx) {
182-
return container;
167+
return container
183168
}
184169
}
185-
return undefined;
170+
return undefined
186171
}
187172

188-
public resultsByType(
189-
type: Result
190-
): Array<ResultItem | AuthenticityResult | ImageQualityCheckList> {
191-
return this.ContainerList.List.filter(
192-
(container) => container.result_type === type
193-
);
173+
public resultsByType(type: Result): Array<ResultItem | AuthenticityResult | ImageQualityCheckList> {
174+
return this.ContainerList.List.filter(container => container.result_type === type)
194175
}
195176
}

0 commit comments

Comments
 (0)