Created
November 1, 2022 17:54
-
-
Save karladler/6e2f24082811c544edcfc8714410226e to your computer and use it in GitHub Desktop.
Some snippets that might be useful one day ...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Converts flat object into Html description list using key => value | |
* ```html | |
* <dl> | |
* <dt>{key}</dt> | |
* <dd>{value}</dd> | |
* </dl> | |
* ``` | |
* | |
* @param obj | |
* @returns | |
*/ | |
export const renderObjectAsDescriptionList = (obj: Record<string, number | string | Date>): string => { | |
const entries = Object.entries(obj).map(([key, val]) => { | |
return `<dt>${key.replace('_', ' ')}</dt><dd>${isDate(val) ? format(val as unknown as Date, 'dd.MM.yyyy') : val}</dd>`; | |
}); | |
return `<dl>${entries.join('\n')}</dl>`; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment