UNPKG

mindee

Version:

Mindee Client Library for Node.js

46 lines (45 loc) 1.61 kB
import { StringField } from "../../../v1/parsing/standard/index.js"; import { GeneratedObjectField, isGeneratedObject } from "./generatedObject.js"; /** * A list of values or objects, used in generated APIs. */ export 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 (isGeneratedObject(value)) { this.values.push(new GeneratedObjectField({ prediction: value, pageId })); } else { const valueStr = { ...value }; if (valueStr["value"] !== null && valueStr["value"] !== undefined) { valueStr["value"] = value["value"].toString(); } this.values.push(new 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(); } }