mindee
Version:
Mindee Client Library for Node.js
76 lines (75 loc) • 2.5 kB
JavaScript
import { cleanOutString, } from "../../../v1/parsing/common/index.js";
import { DateField, StringField } from "../../../v1/parsing/standard/index.js";
/**
* Passport API version 1.1 document data.
*/
export class PassportV1Document {
constructor(rawPrediction, pageId) {
/** The given name(s) of the passport holder. */
this.givenNames = [];
this.birthDate = new DateField({
prediction: rawPrediction["birth_date"],
pageId: pageId,
});
this.birthPlace = new StringField({
prediction: rawPrediction["birth_place"],
pageId: pageId,
});
this.country = new StringField({
prediction: rawPrediction["country"],
pageId: pageId,
});
this.expiryDate = new DateField({
prediction: rawPrediction["expiry_date"],
pageId: pageId,
});
this.gender = new StringField({
prediction: rawPrediction["gender"],
pageId: pageId,
});
if (rawPrediction["given_names"]) {
rawPrediction["given_names"].map((itemPrediction) => this.givenNames.push(new StringField({
prediction: itemPrediction,
pageId: pageId,
})));
}
this.idNumber = new StringField({
prediction: rawPrediction["id_number"],
pageId: pageId,
});
this.issuanceDate = new DateField({
prediction: rawPrediction["issuance_date"],
pageId: pageId,
});
this.mrz1 = new StringField({
prediction: rawPrediction["mrz1"],
pageId: pageId,
});
this.mrz2 = new StringField({
prediction: rawPrediction["mrz2"],
pageId: pageId,
});
this.surname = new StringField({
prediction: rawPrediction["surname"],
pageId: pageId,
});
}
/**
* Default string representation.
*/
toString() {
const givenNames = this.givenNames.join("\n ");
const outStr = `:Country Code: ${this.country}
:ID Number: ${this.idNumber}
:Given Name(s): ${givenNames}
:Surname: ${this.surname}
:Date of Birth: ${this.birthDate}
:Place of Birth: ${this.birthPlace}
:Gender: ${this.gender}
:Date of Issue: ${this.issuanceDate}
:Expiry Date: ${this.expiryDate}
:MRZ Line 1: ${this.mrz1}
:MRZ Line 2: ${this.mrz2}`.trimEnd();
return cleanOutString(outStr);
}
}