Skip to content

Commit

Permalink
chore: use snake case for constant variable
Browse files Browse the repository at this point in the history
  • Loading branch information
Sang-minKIM committed Mar 8, 2024
1 parent ed032df commit 6c18bd3
Showing 1 changed file with 43 additions and 43 deletions.
86 changes: 43 additions & 43 deletions src/ts/controllers/utils/escapeTextForBrowser.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
const matchHtmlRegExp = /["'&<>]/;
const MATCH_HTML_REG_EXP = /["'&<>]/;

function escapeHtml(string: string) {
const str = "" + string;
const match = matchHtmlRegExp.exec(str);

if (!match) {
return str;
}

let escape;
let html = "";
let index;
let lastIndex = 0;

for (index = match.index; index < str.length; index++) {
switch (str.charCodeAt(index)) {
case 34: // "
escape = "&quot;";
break;
case 38: // &
escape = "&amp;";
break;
case 39: // '
escape = "&#x27;"; // modified from escape-html; used to be '&#39'
break;
case 60: // <
escape = "&lt;";
break;
case 62: // >
escape = "&gt;";
break;
default:
continue;
}
const str = "" + string;
const match = MATCH_HTML_REG_EXP.exec(str);

if (lastIndex !== index) {
html += str.slice(lastIndex, index);
if (!match) {
return str;
}

lastIndex = index + 1;
html += escape;
}
let escape;
let html = "";
let index;
let lastIndex = 0;

for (index = match.index; index < str.length; index++) {
switch (str.charCodeAt(index)) {
case 34: // "
escape = "&quot;";
break;
case 38: // &
escape = "&amp;";
break;
case 39: // '
escape = "&#x27;"; // modified from escape-html; used to be '&#39'
break;
case 60: // <
escape = "&lt;";
break;
case 62: // >
escape = "&gt;";
break;
default:
continue;
}

if (lastIndex !== index) {
html += str.slice(lastIndex, index);
}

lastIndex = index + 1;
html += escape;
}

return lastIndex !== index ? html + str.slice(lastIndex, index) : html;
return lastIndex !== index ? html + str.slice(lastIndex, index) : html;
}

/**
Expand All @@ -52,10 +52,10 @@ function escapeHtml(string: string) {
* @return {string} An escaped string.
*/
function escapeTextForBrowser(text: any) {
if (typeof text === "boolean" || typeof text === "number") {
return "" + text;
}
return escapeHtml(text);
if (typeof text === "boolean" || typeof text === "number") {
return "" + text;
}
return escapeHtml(text);
}

export default escapeTextForBrowser;

0 comments on commit 6c18bd3

Please sign in to comment.