mindee
Version:
Mindee Client Library for Node.js
86 lines (85 loc) • 3.76 kB
JavaScript
;
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 _NutritionFactsLabelV1TotalFat_instances, _NutritionFactsLabelV1TotalFat_printableValues;
Object.defineProperty(exports, "__esModule", { value: true });
exports.NutritionFactsLabelV1TotalFat = void 0;
const common_1 = require("../../parsing/common");
const geometry_1 = require("../../geometry");
/**
* The total amount of fat in the product.
*/
class NutritionFactsLabelV1TotalFat {
constructor({ prediction = {} }) {
_NutritionFactsLabelV1TotalFat_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["daily_value"] !== undefined &&
prediction["daily_value"] !== null &&
!isNaN(prediction["daily_value"])) {
this.dailyValue = +parseFloat(prediction["daily_value"]);
}
else {
this.dailyValue = null;
}
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.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, _NutritionFactsLabelV1TotalFat_instances, "m", _NutritionFactsLabelV1TotalFat_printableValues).call(this);
return ("Daily Value: " +
printable.dailyValue +
", Per 100g: " +
printable.per100G +
", Per Serving: " +
printable.perServing);
}
/**
* Output in a format suitable for inclusion in a field list.
*/
toFieldList() {
const printable = __classPrivateFieldGet(this, _NutritionFactsLabelV1TotalFat_instances, "m", _NutritionFactsLabelV1TotalFat_printableValues).call(this);
return `
:Daily Value: ${printable.dailyValue}
:Per 100g: ${printable.per100G}
:Per Serving: ${printable.perServing}`.trimEnd();
}
}
exports.NutritionFactsLabelV1TotalFat = NutritionFactsLabelV1TotalFat;
_NutritionFactsLabelV1TotalFat_instances = new WeakSet(), _NutritionFactsLabelV1TotalFat_printableValues = function _NutritionFactsLabelV1TotalFat_printableValues() {
return {
dailyValue: this.dailyValue !== undefined ? (0, common_1.floatToString)(this.dailyValue) : "",
per100G: this.per100G !== undefined ? (0, common_1.floatToString)(this.per100G) : "",
perServing: this.perServing !== undefined ? (0, common_1.floatToString)(this.perServing) : "",
};
};