UNPKG

mindee

Version:

Mindee Client Library for Node.js

67 lines (66 loc) 2.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 _NutritionFactsLabelV1ServingSize_instances, _NutritionFactsLabelV1ServingSize_printableValues; Object.defineProperty(exports, "__esModule", { value: true }); exports.NutritionFactsLabelV1ServingSize = void 0; const common_1 = require("../../parsing/common"); const geometry_1 = require("../../geometry"); /** * The size of a single serving of the product. */ class NutritionFactsLabelV1ServingSize { constructor({ prediction = {} }) { _NutritionFactsLabelV1ServingSize_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 = new geometry_1.Polygon(); if (prediction["amount"] !== undefined && prediction["amount"] !== null && !isNaN(prediction["amount"])) { this.amount = +parseFloat(prediction["amount"]); } else { this.amount = null; } this.unit = prediction["unit"]; 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, _NutritionFactsLabelV1ServingSize_instances, "m", _NutritionFactsLabelV1ServingSize_printableValues).call(this); return ("Amount: " + printable.amount + ", Unit: " + printable.unit); } /** * Output in a format suitable for inclusion in a field list. */ toFieldList() { const printable = __classPrivateFieldGet(this, _NutritionFactsLabelV1ServingSize_instances, "m", _NutritionFactsLabelV1ServingSize_printableValues).call(this); return ` :Amount: ${printable.amount} :Unit: ${printable.unit}`.trimEnd(); } } exports.NutritionFactsLabelV1ServingSize = NutritionFactsLabelV1ServingSize; _NutritionFactsLabelV1ServingSize_instances = new WeakSet(), _NutritionFactsLabelV1ServingSize_printableValues = function _NutritionFactsLabelV1ServingSize_printableValues() { return { amount: this.amount !== undefined ? (0, common_1.floatToString)(this.amount) : "", unit: this.unit ?? "", }; };