mindee
Version:
Mindee Client Library for Node.js
96 lines (95 loc) • 3.25 kB
JavaScript
import { cleanOutString, } from "../../../../v1/parsing/common/index.js";
import { DateField, StringField } from "../../../../v1/parsing/standard/index.js";
/**
* Carte Nationale d'Identité API version 2.0 document data.
*/
export class IdCardV2Document {
constructor(rawPrediction, pageId) {
/** The given name(s) of the card holder. */
this.givenNames = [];
this.alternateName = new StringField({
prediction: rawPrediction["alternate_name"],
pageId: pageId,
});
this.authority = new StringField({
prediction: rawPrediction["authority"],
pageId: pageId,
});
this.birthDate = new DateField({
prediction: rawPrediction["birth_date"],
pageId: pageId,
});
this.birthPlace = new StringField({
prediction: rawPrediction["birth_place"],
pageId: pageId,
});
this.cardAccessNumber = new StringField({
prediction: rawPrediction["card_access_number"],
pageId: pageId,
});
this.documentNumber = new StringField({
prediction: rawPrediction["document_number"],
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.issueDate = new DateField({
prediction: rawPrediction["issue_date"],
pageId: pageId,
});
this.mrz1 = new StringField({
prediction: rawPrediction["mrz1"],
pageId: pageId,
});
this.mrz2 = new StringField({
prediction: rawPrediction["mrz2"],
pageId: pageId,
});
this.mrz3 = new StringField({
prediction: rawPrediction["mrz3"],
pageId: pageId,
});
this.nationality = new StringField({
prediction: rawPrediction["nationality"],
pageId: pageId,
});
this.surname = new StringField({
prediction: rawPrediction["surname"],
pageId: pageId,
});
}
/**
* Default string representation.
*/
toString() {
const givenNames = this.givenNames.join("\n ");
const outStr = `:Nationality: ${this.nationality}
:Card Access Number: ${this.cardAccessNumber}
:Document Number: ${this.documentNumber}
:Given Name(s): ${givenNames}
:Surname: ${this.surname}
:Alternate Name: ${this.alternateName}
:Date of Birth: ${this.birthDate}
:Place of Birth: ${this.birthPlace}
:Gender: ${this.gender}
:Expiry Date: ${this.expiryDate}
:Mrz Line 1: ${this.mrz1}
:Mrz Line 2: ${this.mrz2}
:Mrz Line 3: ${this.mrz3}
:Date of Issue: ${this.issueDate}
:Issuing Authority: ${this.authority}`.trimEnd();
return cleanOutString(outStr);
}
}