UNPKG

mindee

Version:

Mindee Client Library for Node.js

50 lines (49 loc) 1.77 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GeneratedListField = void 0; const standard_1 = require("../standard"); const generatedObject_1 = require("./generatedObject"); /** * A list of values or objects, used in generated APIs. */ class GeneratedListField { constructor({ prediction = [], pageId = undefined, }) { this.values = []; for (const value of prediction) { if (value["page_id"] !== undefined && value["page_id"] !== null) { this.pageId = value["page_id"]; } if ((0, generatedObject_1.isGeneratedObject)(value)) { this.values.push(new generatedObject_1.GeneratedObjectField({ prediction: value, pageId })); } else { const valueStr = { ...value }; if (valueStr["value"] !== null && valueStr["value"] !== undefined) { valueStr["value"] = value["value"].toString(); } this.values.push(new standard_1.StringField({ prediction: valueStr, pageId: pageId })); } } } /** * Returns an array of the contents of all values. */ contentsList() { return this.values.map((item) => item.toString()); } /** * Return a string representation of all values. * @param separator Character(s) to use when concatenating fields. * @returns string representation. */ contentsString(separator = " ") { return this.contentsList().map((item) => `${item.toString()}`).join(separator); } /** * Default string representation. */ toString() { return this.contentsString(); } } exports.GeneratedListField = GeneratedListField;