From ab1e9ea0dae937135828a0ddac82d1bc08661e23 Mon Sep 17 00:00:00 2001 From: Julian Lobbes Date: Thu, 1 Jun 2023 00:17:52 +0100 Subject: [PATCH] fix(frontend): add missing docstrings --- frontend/src/lib/components/data-table/utils.ts | 10 ++++++++++ frontend/src/lib/utils/markdown.ts | 7 +++++++ 2 files changed, 17 insertions(+) diff --git a/frontend/src/lib/components/data-table/utils.ts b/frontend/src/lib/components/data-table/utils.ts index 0c03d46..a5270fb 100644 --- a/frontend/src/lib/components/data-table/utils.ts +++ b/frontend/src/lib/components/data-table/utils.ts @@ -1,3 +1,13 @@ +/** + * Replaces placeholders in a template string with values from a replacement items object. + * + * The placeholders are in the format %key%, whereby %key% is replaced with the value of the 'key' + * attribute in the replacementItems object. + * + * @param {string} templateString - The template string containing placeholders to be replaced. + * @param {object} replacementItems - The object containing key-value pairs for replacement. + * @returns {string} The modified string with all placeholders replaced. + */ export function interpolateString(templateString: string, replacementItems: { [key: string]: any }): string { if (typeof templateString !== 'string') { return ''; diff --git a/frontend/src/lib/utils/markdown.ts b/frontend/src/lib/utils/markdown.ts index 7917553..3bd238d 100644 --- a/frontend/src/lib/utils/markdown.ts +++ b/frontend/src/lib/utils/markdown.ts @@ -1,6 +1,13 @@ import { marked } from 'marked'; import dompurify from 'dompurify'; +/** + * Converts the input text, which is assumed to be in markdown format, into HTML and returns it. + * The returned HTML is sanitized to prevent XSS. + * + * @param {string} text - The input text in markdown format to convert. + * @returns {string} The HTML representation of the input text. + */ export function markdownToHtml(text: string): string { // Remove zerowidth chars from beginning of input string // This is probably not necessary...