mindee
Version:
Mindee Client Library for Node.js
108 lines (107 loc) • 4.52 kB
JavaScript
"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 _NutritionFactsLabelV1Nutrient_instances, _NutritionFactsLabelV1Nutrient_printableValues;
Object.defineProperty(exports, "__esModule", { value: true });
exports.NutritionFactsLabelV1Nutrient = void 0;
const common_1 = require("../../parsing/common");
/**
* The amount of nutrients in the product.
*/
class NutritionFactsLabelV1Nutrient {
constructor({ prediction = {} }) {
_NutritionFactsLabelV1Nutrient_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["daily_value"] !== undefined &&
prediction["daily_value"] !== null &&
!isNaN(prediction["daily_value"])) {
this.dailyValue = +parseFloat(prediction["daily_value"]);
}
else {
this.dailyValue = null;
}
this.name = prediction["name"];
if (prediction["per_100g"] !== undefined &&
prediction["per_100g"] !== null &&
!isNaN(prediction["per_100g"])) {
this.per100G = +parseFloat(prediction["per_100g"]);
}
else {
this.per100G = null;
}
if (prediction["per_serving"] !== undefined &&
prediction["per_serving"] !== null &&
!isNaN(prediction["per_serving"])) {
this.perServing = +parseFloat(prediction["per_serving"]);
}
else {
this.perServing = 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, _NutritionFactsLabelV1Nutrient_instances, "m", _NutritionFactsLabelV1Nutrient_printableValues).call(this);
return ("Daily Value: " +
printable.dailyValue +
", Name: " +
printable.name +
", Per 100g: " +
printable.per100G +
", Per Serving: " +
printable.perServing +
", Unit: " +
printable.unit);
}
/**
* Output in a format suitable for inclusion in an rST table.
*/
toTableLine() {
const printable = __classPrivateFieldGet(this, _NutritionFactsLabelV1Nutrient_instances, "m", _NutritionFactsLabelV1Nutrient_printableValues).call(this);
return ("| " +
printable.dailyValue.padEnd(11) +
" | " +
printable.name.padEnd(20) +
" | " +
printable.per100G.padEnd(8) +
" | " +
printable.perServing.padEnd(11) +
" | " +
printable.unit.padEnd(4) +
" |");
}
}
exports.NutritionFactsLabelV1Nutrient = NutritionFactsLabelV1Nutrient;
_NutritionFactsLabelV1Nutrient_instances = new WeakSet(), _NutritionFactsLabelV1Nutrient_printableValues = function _NutritionFactsLabelV1Nutrient_printableValues() {
return {
dailyValue: this.dailyValue !== undefined ? (0, common_1.floatToString)(this.dailyValue) : "",
name: this.name ?
this.name.length <= 20 ?
(0, common_1.cleanSpecialChars)(this.name) :
(0, common_1.cleanSpecialChars)(this.name).slice(0, 17) + "..." :
"",
per100G: this.per100G !== undefined ? (0, common_1.floatToString)(this.per100G) : "",
perServing: this.perServing !== undefined ? (0, common_1.floatToString)(this.perServing) : "",
unit: this.unit ?
this.unit.length <= 4 ?
(0, common_1.cleanSpecialChars)(this.unit) :
(0, common_1.cleanSpecialChars)(this.unit).slice(0, 1) + "..." :
"",
};
};