UNPKG

mindee

Version:

Mindee Client Library for Node.js

110 lines (109 loc) 3.88 kB
import { cleanOutString, } from "../../../v1/parsing/common/index.js"; import { ClassificationField, DateField, StringField, } from "../../../v1/parsing/standard/index.js"; /** * International ID API version 2.2 document data. */ export class InternationalIdV2Document { constructor(rawPrediction, pageId) { /** The list of the document holder's given names. */ this.givenNames = []; /** The list of the document holder's family names. */ this.surnames = []; this.address = new StringField({ prediction: rawPrediction["address"], pageId: pageId, }); this.birthDate = new DateField({ prediction: rawPrediction["birth_date"], pageId: pageId, }); this.birthPlace = new StringField({ prediction: rawPrediction["birth_place"], pageId: pageId, }); this.countryOfIssue = new StringField({ prediction: rawPrediction["country_of_issue"], pageId: pageId, }); this.documentNumber = new StringField({ prediction: rawPrediction["document_number"], pageId: pageId, }); this.documentType = new ClassificationField({ prediction: rawPrediction["document_type"], }); this.expiryDate = new DateField({ prediction: rawPrediction["expiry_date"], 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.mrzLine1 = new StringField({ prediction: rawPrediction["mrz_line1"], pageId: pageId, }); this.mrzLine2 = new StringField({ prediction: rawPrediction["mrz_line2"], pageId: pageId, }); this.mrzLine3 = new StringField({ prediction: rawPrediction["mrz_line3"], pageId: pageId, }); this.nationality = new StringField({ prediction: rawPrediction["nationality"], pageId: pageId, }); this.personalNumber = new StringField({ prediction: rawPrediction["personal_number"], pageId: pageId, }); this.sex = new StringField({ prediction: rawPrediction["sex"], pageId: pageId, }); this.stateOfIssue = new StringField({ prediction: rawPrediction["state_of_issue"], pageId: pageId, }); if (rawPrediction["surnames"]) { rawPrediction["surnames"].map((itemPrediction) => this.surnames.push(new StringField({ prediction: itemPrediction, pageId: pageId, }))); } } /** * Default string representation. */ toString() { const surnames = this.surnames.join("\n "); const givenNames = this.givenNames.join("\n "); const outStr = `:Document Type: ${this.documentType} :Document Number: ${this.documentNumber} :Surnames: ${surnames} :Given Names: ${givenNames} :Sex: ${this.sex} :Birth Date: ${this.birthDate} :Birth Place: ${this.birthPlace} :Nationality: ${this.nationality} :Personal Number: ${this.personalNumber} :Country of Issue: ${this.countryOfIssue} :State of Issue: ${this.stateOfIssue} :Issue Date: ${this.issueDate} :Expiration Date: ${this.expiryDate} :Address: ${this.address} :MRZ Line 1: ${this.mrzLine1} :MRZ Line 2: ${this.mrzLine2} :MRZ Line 3: ${this.mrzLine3}`.trimEnd(); return cleanOutString(outStr); } }