Skip to content

Commit

Permalink
Mention & operation order in comment (#21)
Browse files Browse the repository at this point in the history
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
  • Loading branch information
fregante and sindresorhus authored Sep 13, 2021
1 parent d4a6516 commit 3b69aa6
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// TODO: Use `String#replaceAll` when targeting Node.js 16.
// Multiple `.replace()` calls are actually faster than using replacer functions #2.
const _htmlEscape = string => string
.replace(/&/g, '&amp;')
.replace(/&/g, '&amp;') // Must happen first or else it will escape other just-escaped characters.
.replace(/"/g, '&quot;')
.replace(/'/g, '&#39;')
.replace(/</g, '&lt;')
Expand All @@ -10,7 +12,7 @@ const _htmlUnescape = htmlString => htmlString
.replace(/&lt;/g, '<')
.replace(/&#0?39;/g, '\'')
.replace(/&quot;/g, '"')
.replace(/&amp;/g, '&');
.replace(/&amp;/g, '&'); // Must happen last or else it will unescape other characters in the wrong order.

export function htmlEscape(strings, ...values) {
if (typeof strings === 'string') {
Expand Down

0 comments on commit 3b69aa6

Please sign in to comment.