UNPKG

mindee

Version:

Mindee Client Library for Node.js

111 lines (110 loc) 4.41 kB
"use strict"; var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); }; var _PayslipV3SalaryDetail_instances, _PayslipV3SalaryDetail_printableValues; Object.defineProperty(exports, "__esModule", { value: true }); exports.PayslipV3SalaryDetail = void 0; const common_1 = require("../../../parsing/common"); /** * Detailed information about the earnings. */ class PayslipV3SalaryDetail { constructor({ prediction = {} }) { _PayslipV3SalaryDetail_instances.add(this); /** Confidence score */ this.confidence = 0.0; /** * Contains the relative vertices coordinates (points) of a polygon containing * the field in the document. */ this.polygon = []; if (prediction["amount"] !== undefined && prediction["amount"] !== null && !isNaN(prediction["amount"])) { this.amount = +parseFloat(prediction["amount"]); } else { this.amount = null; } if (prediction["base"] !== undefined && prediction["base"] !== null && !isNaN(prediction["base"])) { this.base = +parseFloat(prediction["base"]); } else { this.base = null; } this.description = prediction["description"]; if (prediction["number"] !== undefined && prediction["number"] !== null && !isNaN(prediction["number"])) { this.number = +parseFloat(prediction["number"]); } else { this.number = null; } if (prediction["rate"] !== undefined && prediction["rate"] !== null && !isNaN(prediction["rate"])) { this.rate = +parseFloat(prediction["rate"]); } else { this.rate = null; } this.pageId = prediction["page_id"]; this.confidence = prediction["confidence"] ? prediction.confidence : 0.0; if (prediction["polygon"]) { this.polygon = prediction.polygon; } } /** * Default string representation. */ toString() { const printable = __classPrivateFieldGet(this, _PayslipV3SalaryDetail_instances, "m", _PayslipV3SalaryDetail_printableValues).call(this); return ("Amount: " + printable.amount + ", Base: " + printable.base + ", Description: " + printable.description + ", Number: " + printable.number + ", Rate: " + printable.rate); } /** * Output in a format suitable for inclusion in an rST table. */ toTableLine() { const printable = __classPrivateFieldGet(this, _PayslipV3SalaryDetail_instances, "m", _PayslipV3SalaryDetail_printableValues).call(this); return ("| " + printable.amount.padEnd(12) + " | " + printable.base.padEnd(9) + " | " + printable.description.padEnd(36) + " | " + printable.number.padEnd(6) + " | " + printable.rate.padEnd(9) + " |"); } } exports.PayslipV3SalaryDetail = PayslipV3SalaryDetail; _PayslipV3SalaryDetail_instances = new WeakSet(), _PayslipV3SalaryDetail_printableValues = function _PayslipV3SalaryDetail_printableValues() { return { amount: this.amount !== undefined ? (0, common_1.floatToString)(this.amount) : "", base: this.base !== undefined ? (0, common_1.floatToString)(this.base) : "", description: this.description ? this.description.length <= 36 ? (0, common_1.cleanSpecialChars)(this.description) : (0, common_1.cleanSpecialChars)(this.description).slice(0, 33) + "..." : "", number: this.number !== undefined ? (0, common_1.floatToString)(this.number) : "", rate: this.rate !== undefined ? (0, common_1.floatToString)(this.rate) : "", }; };