mindee
Version:
Mindee Client Library for Node.js
30 lines (29 loc) • 877 B
JavaScript
import { Field } from "./field.js";
import { floatToString } from "../../../v1/parsing/common/index.js";
/**
* A field containing an amount value.
*/
export class AmountField extends Field {
/**
* @param {BaseFieldConstructor} constructor Constructor parameters.
*/
constructor({ prediction = {}, valueKey = "value", reconstructed = false, pageId = undefined, }) {
super({ prediction, valueKey, reconstructed, pageId });
/** The value. */
this.value = undefined;
this.value = +parseFloat(prediction[valueKey]);
if (isNaN(this.value)) {
this.value = undefined;
this.confidence = 0.0;
}
}
/**
* Default string representation.
*/
toString() {
if (this.value !== undefined) {
return floatToString(this.value);
}
return "";
}
}