Skip to content

Commit

Permalink
Merge pull request #518 from kethinov/refactor-escape-entities
Browse files Browse the repository at this point in the history
refactor escape entities for better type checking
  • Loading branch information
kethinov authored Oct 7, 2021
2 parents 90387d9 + fea0b21 commit 64c5567
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,21 @@ function escapeEntities (value) {
let i
let j

if (value === undefined || typeof value === 'boolean' || typeof value === 'object') { // Cannot escape on these values
return value
} else if (typeof value === 'number') { // Value is a number, no reason to escape
return `${value}`
if (typeof value === 'object') { // Cannot escape on this value
if (!value) {
return false // it is falsey to return false
} else if (Array.isArray(value)) {
if (value.length === 0) {
return false // empty arrays are falsey
} else {
return '[Array]' // print that it is an array with content in it, but do not print the contents
}
}
return '[Object]' // just print that it is an object, do not print the contents
} else if (value === undefined) { // Cannot escape on this value
return false // undefined is falsey
} else if (typeof value === 'boolean' || typeof value === 'number') { // Cannot escape on these values
return value // if it's already a boolean or a number just return it
} else {
// Loop through value to find HTML entities
for (i = 0; i < value.length; i++) {
Expand Down

0 comments on commit 64c5567

Please sign in to comment.