UNPKG

@cognigy/rest-api-client

Version:

Cognigy REST-Client

37 lines 1.14 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.generateAnswerShortForm = void 0; /** * Generates a readable shortform answer from any Question Type answer * Especially important for dates * * @param type The question type * @param answer The result of the question * @returns string */ const generateAnswerShortForm = (type, answer, text) => { let shortForm = answer; switch (type) { case "date": shortForm = answer.plain; break; case "yesNo": shortForm = text; break; case "temperature": case "age": shortForm = answer.value; break; case "money": shortForm = `${answer.value} ${answer.unit}`; break; // and either case "data": shortForm = JSON.stringify(answer); break; // there are no good short forms for duration and others, so we will just leave them out } return shortForm; }; exports.generateAnswerShortForm = generateAnswerShortForm; //# sourceMappingURL=generateAnswerShortForm.js.map