UNPKG

mindee

Version:

Mindee Client Library for Node.js

98 lines (97 loc) 3.93 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 _PayslipV2SalaryDetail_instances, _PayslipV2SalaryDetail_printableValues; Object.defineProperty(exports, "__esModule", { value: true }); exports.PayslipV2SalaryDetail = void 0; const common_1 = require("../../../parsing/common"); /** * Detailed information about the earnings. */ class PayslipV2SalaryDetail { constructor({ prediction = {} }) { _PayslipV2SalaryDetail_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["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, _PayslipV2SalaryDetail_instances, "m", _PayslipV2SalaryDetail_printableValues).call(this); return ("Amount: " + printable.amount + ", Base: " + printable.base + ", Description: " + printable.description + ", Rate: " + printable.rate); } /** * Output in a format suitable for inclusion in an rST table. */ toTableLine() { const printable = __classPrivateFieldGet(this, _PayslipV2SalaryDetail_instances, "m", _PayslipV2SalaryDetail_printableValues).call(this); return ("| " + printable.amount.padEnd(12) + " | " + printable.base.padEnd(9) + " | " + printable.description.padEnd(36) + " | " + printable.rate.padEnd(9) + " |"); } } exports.PayslipV2SalaryDetail = PayslipV2SalaryDetail; _PayslipV2SalaryDetail_instances = new WeakSet(), _PayslipV2SalaryDetail_printableValues = function _PayslipV2SalaryDetail_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) + "..." : "", rate: this.rate !== undefined ? (0, common_1.floatToString)(this.rate) : "", }; };