Skip to content

Instantly share code, notes, and snippets.

@karladler
Created November 1, 2022 17:54
Show Gist options
  • Save karladler/6e2f24082811c544edcfc8714410226e to your computer and use it in GitHub Desktop.
Save karladler/6e2f24082811c544edcfc8714410226e to your computer and use it in GitHub Desktop.
Some snippets that might be useful one day ...
/**
* 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