Skip to content
Myr

html.ts

This file

Path

src/utils/html.ts

44 lines · 1.1 KiB · TypeScript

Last changed by

Not known.

History of this file

Take it

The walk stopped after 200 commits: lines older than 543fdba point at it.

fix(type): fix order of method overloading (#490)azukiazusa1before adoption543fdba

lines 1–44why, one step back
1export type HtmlEscaped = { isEscaped: true }
2export type HtmlEscapedString = string & HtmlEscaped3export type StringBuffer = [string]45// The `escapeToBuffer` implementation is based on code from the MIT licensed `react-dom` package.6// https://github.com/facebook/react/blob/main/packages/react-dom/src/server/escapeTextForBrowser.js78const escapeRe = /[&<>"]/910export const escapeToBuffer = (str: string, buffer: StringBuffer): void => {11 const match = str.search(escapeRe)12 if (match === -1) {13 buffer[0] += str14 return15 }1617 let escape18 let index19 let lastIndex = 02021 for (index = match; index < str.length; index++) {22 switch (str.charCodeAt(index)) {23 case 34: // "24 escape = '&quot;'25 break26 case 38: // &27 escape = '&amp;'28 break29 case 60: // <30 escape = '&lt;'31 break32 case 62: // >33 escape = '&gt;'34 break35 default:36 continue37 }3839 buffer[0] += str.substring(lastIndex, index) + escape40 lastIndex = index + 141 }4243 buffer[0] += str.substring(lastIndex, index)44}