Skip to content

Commit

Permalink
add it all (i can clean it up before merge)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshgoebel committed Nov 24, 2020
1 parent f1f45c3 commit 63373a4
Show file tree
Hide file tree
Showing 3 changed files with 11,754 additions and 5 deletions.
10 changes: 6 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,16 @@ module.exports = { escapeHtml, escapeHtmlFast, escapeHtmlNoRegex }
*/

var matchHtmlRegExpFast = /["'&<>]/g
function escapeHtmlFast (str) {
function escapeHtmlFast (string) {
var str = '' + string

var lastIndex = 0
var html = ''
var escape = ''
var match

while (match = matchHtmlRegExpFast.test(str)) {
switch (str.charCodeAt(matchHtmlRegExpFast.lastIndex)) {
switch (str.charCodeAt(matchHtmlRegExpFast.lastIndex-1)) {
case 34: // "
escape = '&quot;'
break
Expand All @@ -56,8 +58,8 @@ function escapeHtmlFast (str) {
break
}
// console.log(lastIndex, matchHtmlRegExpFast.lastIndex, str.length)
html += str.substring(lastIndex, matchHtmlRegExpFast.lastIndex)
lastIndex = matchHtmlRegExpFast.lastIndex + 1
html += str.substring(lastIndex, matchHtmlRegExpFast.lastIndex - 1)
lastIndex = matchHtmlRegExpFast.lastIndex
html += escape
}
return html + str.substring(lastIndex)
Expand Down
Loading

0 comments on commit 63373a4

Please sign in to comment.