refactor: ♻️ Always use explicit types in every function

This commit is contained in:
Jesse Wierzbinski 2024-11-02 00:43:33 +01:00
parent 54cea29ce9
commit c1dcdc78ae
No known key found for this signature in database
62 changed files with 359 additions and 226 deletions

View file

@ -1,7 +1,7 @@
import { stringifyEntitiesLight } from "stringify-entities";
import xss, { type IFilterXSSOptions } from "xss";
export const sanitizedHtmlStrip = (html: string) => {
export const sanitizedHtmlStrip = (html: string): Promise<string> => {
return sanitizeHtml(html, {
whiteList: {},
});
@ -10,7 +10,7 @@ export const sanitizedHtmlStrip = (html: string) => {
export const sanitizeHtmlInline = (
html: string,
extraConfig?: IFilterXSSOptions,
) => {
): Promise<string> => {
return sanitizeHtml(html, {
whiteList: {
a: ["href", "title", "target", "rel", "class"],
@ -33,7 +33,7 @@ export const sanitizeHtmlInline = (
export const sanitizeHtml = async (
html: string,
extraConfig?: IFilterXSSOptions,
) => {
): Promise<string> => {
const sanitizedHtml = xss(html, {
whiteList: {
a: ["href", "title", "target", "rel", "class"],
@ -81,7 +81,7 @@ export const sanitizeHtml = async (
track: ["src", "label", "kind"],
},
stripIgnoreTag: false,
escapeHtml: (unsafeHtml) =>
escapeHtml: (unsafeHtml): string =>
stringifyEntitiesLight(unsafeHtml, {
escapeOnly: true,
}),
@ -103,7 +103,7 @@ export const sanitizeHtml = async (
return await new HTMLRewriter()
.on("*[class]", {
element(element) {
element(element): void {
const classes = element.getAttribute("class")?.split(" ") ?? [];
for (const className of classes) {