UNPKG

mindee

Version:

Mindee Client Library for Node.js

69 lines (68 loc) 3.37 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.UsMailV3Document = void 0; const common_1 = require("../../../parsing/common"); const usMailV3SenderAddress_1 = require("./usMailV3SenderAddress"); const usMailV3RecipientAddress_1 = require("./usMailV3RecipientAddress"); const standard_1 = require("../../../parsing/standard"); /** * US Mail API version 3.0 document data. */ class UsMailV3Document { constructor(rawPrediction, pageId) { /** The addresses of the recipients. */ this.recipientAddresses = []; /** The names of the recipients. */ this.recipientNames = []; this.isReturnToSender = new standard_1.BooleanField({ prediction: rawPrediction["is_return_to_sender"], pageId: pageId, }); rawPrediction["recipient_addresses"] && rawPrediction["recipient_addresses"].map((itemPrediction) => this.recipientAddresses.push(new usMailV3RecipientAddress_1.UsMailV3RecipientAddress({ prediction: itemPrediction, pageId: pageId, }))); rawPrediction["recipient_names"] && rawPrediction["recipient_names"].map((itemPrediction) => this.recipientNames.push(new standard_1.StringField({ prediction: itemPrediction, pageId: pageId, }))); this.senderAddress = new usMailV3SenderAddress_1.UsMailV3SenderAddress({ prediction: rawPrediction["sender_address"], pageId: pageId, }); this.senderName = new standard_1.StringField({ prediction: rawPrediction["sender_name"], pageId: pageId, }); } /** * Default string representation. */ toString() { const recipientNames = this.recipientNames.join("\n "); let recipientAddressesSummary = ""; if (this.recipientAddresses && this.recipientAddresses.length > 0) { const recipientAddressesColSizes = [17, 37, 19, 13, 24, 7, 27, 17]; recipientAddressesSummary += "\n" + (0, common_1.lineSeparator)(recipientAddressesColSizes, "-") + "\n "; recipientAddressesSummary += "| City "; recipientAddressesSummary += "| Complete Address "; recipientAddressesSummary += "| Is Address Change "; recipientAddressesSummary += "| Postal Code "; recipientAddressesSummary += "| Private Mailbox Number "; recipientAddressesSummary += "| State "; recipientAddressesSummary += "| Street "; recipientAddressesSummary += "| Unit "; recipientAddressesSummary += "|\n" + (0, common_1.lineSeparator)(recipientAddressesColSizes, "="); recipientAddressesSummary += this.recipientAddresses.map((item) => "\n " + item.toTableLine() + "\n" + (0, common_1.lineSeparator)(recipientAddressesColSizes, "-")).join(""); } const outStr = `:Sender Name: ${this.senderName} :Sender Address: ${this.senderAddress.toFieldList()} :Recipient Names: ${recipientNames} :Recipient Addresses: ${recipientAddressesSummary} :Return to Sender: ${this.isReturnToSender}`.trimEnd(); return (0, common_1.cleanOutString)(outStr); } } exports.UsMailV3Document = UsMailV3Document;