UNPKG

mindee

Version:

Mindee Client Library for Node.js

33 lines (32 loc) 1.64 kB
import { cleanOutString, lineSeparator, } from "../../../v1/parsing/common/index.js"; import { InvoiceSplitterV1InvoicePageGroup } from "./invoiceSplitterV1InvoicePageGroup.js"; /** * Invoice Splitter API version 1.4 document data. */ export class InvoiceSplitterV1Document { constructor(rawPrediction, pageId) { /** List of page groups. Each group represents a single invoice within a multi-invoice document. */ this.invoicePageGroups = []; if (rawPrediction["invoice_page_groups"]) { rawPrediction["invoice_page_groups"].map((itemPrediction) => this.invoicePageGroups.push(new InvoiceSplitterV1InvoicePageGroup({ prediction: itemPrediction, pageId: pageId, }))); } } /** * Default string representation. */ toString() { let invoicePageGroupsSummary = ""; if (this.invoicePageGroups && this.invoicePageGroups.length > 0) { const invoicePageGroupsColSizes = [74]; invoicePageGroupsSummary += "\n" + lineSeparator(invoicePageGroupsColSizes, "-") + "\n "; invoicePageGroupsSummary += "| Page Indexes "; invoicePageGroupsSummary += "|\n" + lineSeparator(invoicePageGroupsColSizes, "="); invoicePageGroupsSummary += this.invoicePageGroups.map((item) => "\n " + item.toTableLine() + "\n" + lineSeparator(invoicePageGroupsColSizes, "-")).join(""); } const outStr = `:Invoice Page Groups: ${invoicePageGroupsSummary}`.trimEnd(); return cleanOutString(outStr); } }