| 41 | * @param {object|number|string} value The value to return | 41 | * @param {object|number|string} value The value to return |
| 42 | * @param {object} [options={}] Options | 42 | * @param {object} [options={}] Options |
| 43 | * @param {(o: object) => string} [options.objectToStringFunc=null] Function to convert the object to a string, if object was provided and 'object' was not the chosen return type | 43 | * @param {(o: object) => string} [options.objectToStringFunc=null] Function to convert the object to a string, if object was provided and 'object' was not the chosen return type |
| | 44 | * @param {(o: object) => string} [options.objectToHtmlFunc=null] Analog to 'objectToStringFunc', which will be used here if not provided - but can do a different string layout if HTML is requested |
| 44 | * @returns {Promise<*>} The processed return value | 45 | * @returns {Promise<*>} The processed return value |
| 45 | */ | 46 | */ |
| 46 | async doReturn(type, value, { objectToStringFunc = o => o?.toString() } = {}) { | 47 | async doReturn(type, value, { objectToStringFunc = o => o?.toString(), objectToHtmlFunc = null } = {}) { |
| 47 | const stringValue = typeof value !== 'string' ? objectToStringFunc(value) : value; | 48 | const shouldHtml = type.endsWith('html'); |
| | 49 | const actualConverterFunc = shouldHtml && objectToHtmlFunc ? objectToHtmlFunc : objectToStringFunc; |
| | 50 | const stringValue = typeof value !== 'string' ? actualConverterFunc(value) : value; |
| 48 | | 51 | |
| 49 | switch (type) { | 52 | switch (type) { |
| 50 | case 'popup-html': | 53 | case 'popup-html': |