From 612c845f957fc5b6ce3450e5909eff0c9b915591 Mon Sep 17 00:00:00 2001 From: Siddharth Singh Date: Tue, 6 Aug 2024 01:51:43 +0530 Subject: [PATCH] get rid of r() and RawHtml from html.ts --- src/utils/html.ts | 32 ++------------------------------ 1 file changed, 2 insertions(+), 30 deletions(-) diff --git a/src/utils/html.ts b/src/utils/html.ts index 557945dd..56edd5d8 100644 --- a/src/utils/html.ts +++ b/src/utils/html.ts @@ -1,29 +1,5 @@ import { escape } from 'entities'; -interface RawHtml { - raw: true; - contents: string; -} - -/** - * Options for r() - */ -interface RawHtmlOptions { - joiner?: string; -} - -/** - * Prevent values from being escaped by html``. - * @param val Any value. - * @returns An object that tells html`` to not escape `val` while building the HTML string. - */ -export function r(val: any, options?: RawHtmlOptions): RawHtml { - return { - raw: true, - contents: Array.isArray(val) ? val.join(options?.joiner ?? ' ') : val.toString(), - }; -} - /** * @param strings The constant portions of the template string. * @param values The templated values. @@ -35,16 +11,12 @@ export function r(val: any, options?: RawHtmlOptions): RawHtml { * console.assert(testing === "foo bar baz oops<script>alert(1)</script>"); * ``` */ -export function html(strings: TemplateStringsArray, ...values: (string | number | RawHtml)[]) { +export function html(strings: TemplateStringsArray, ...values: (string | number)[]) { const built = []; for (let i = 0; i < strings.length; i++) { built.push(strings[i] || ''); const val = values[i]; - if (typeof val !== 'undefined' && typeof val !== 'object') { - built.push(escape((val || '').toString())); - } else { - built.push(val?.contents || ''); - } + built.push(escape((val || '').toString())); } return built.join(''); }