mindee
Version:
Mindee Client Library for Node.js
63 lines (62 loc) • 3.1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.UsMailV2Document = void 0;
const common_1 = require("../../../parsing/common");
const usMailV2SenderAddress_1 = require("./usMailV2SenderAddress");
const usMailV2RecipientAddress_1 = require("./usMailV2RecipientAddress");
const standard_1 = require("../../../parsing/standard");
/**
* US Mail API version 2.0 document data.
*/
class UsMailV2Document {
constructor(rawPrediction, pageId) {
/** The addresses of the recipients. */
this.recipientAddresses = [];
/** The names of the recipients. */
this.recipientNames = [];
rawPrediction["recipient_addresses"] &&
rawPrediction["recipient_addresses"].map((itemPrediction) => this.recipientAddresses.push(new usMailV2RecipientAddress_1.UsMailV2RecipientAddress({
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 usMailV2SenderAddress_1.UsMailV2SenderAddress({
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];
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 += "|\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}`.trimEnd();
return (0, common_1.cleanOutString)(outStr);
}
}
exports.UsMailV2Document = UsMailV2Document;