UNPKG

mindee

Version:

Mindee Client Library for Node.js

48 lines (47 loc) 1.45 kB
import { BaseField } from "./baseField.js"; export class SimpleField extends BaseField { constructor(serverResponse, indentLevel = 0) { super(serverResponse, indentLevel); this.value = serverResponse["value"] !== undefined ? serverResponse["value"] : null; } /** * Retrieves a string field value as a string. */ get stringValue() { if (this.value !== null && typeof this.value !== "string") { throw new Error("Value is not a string"); } return this.value; } /** * Retrieves a number field value as a number. */ get numberValue() { if (this.value !== null && typeof this.value !== "number") { throw new Error("Value is not a number"); } return this.value; } /** * Retrieves a boolean field value as a boolean. */ get booleanValue() { if (this.value !== null && typeof this.value !== "boolean") { throw new Error("Value is not a boolean"); } return this.value; } toString() { if (this.value === null) { return ""; } if (typeof this.value === "number" && Number.isInteger(this.value)) { return this.value.toString() + ".0"; } if (typeof this.value === "boolean") { return this.value ? "True" : "False"; } return this.value.toString(); } }