UNPKG

mindee

Version:

Mindee Client Library for Node.js

52 lines (51 loc) 1.59 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SimpleField = void 0; const baseField_1 = require("./baseField"); class SimpleField extends baseField_1.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(); } } exports.SimpleField = SimpleField;