Add undefined check for humanFriendlyTitle

humanFriendlyTitle() now returns an empty string if title is undefined
which is handled in loadAndDisplayOptions()
This commit is contained in:
Nikhil Tanwar 2022-01-21 22:51:03 +05:30 committed by Emmanuel Engelhart
parent 234606b170
commit 270773d6ba
No known key found for this signature in database
GPG Key ID: 120B30D020B553D3
1 changed files with 8 additions and 3 deletions

View File

@ -53,8 +53,12 @@
};
const humanFriendlyTitle = (title) => {
title = title.replace(/_/g, ' ');
return htmlEncode(title[0].toUpperCase() + title.slice(1));
if (typeof title === 'string' && title.length > 0) {
title = title.replace(/_/g, ' ');
return htmlEncode(title[0].toUpperCase() + title.slice(1));
} else {
return '';
}
}
function htmlEncode(str) {
@ -238,7 +242,8 @@
data.querySelectorAll('entry').forEach(entry => {
const title = getInnerHtml(entry, 'title');
const value = getInnerHtml(entry, valueEntryNode);
optionStr += `<option value="${value}">${humanFriendlyTitle(title)}</option>`;
const hfTitle = humanFriendlyTitle(title);
optionStr += (hfTitle != '') ? `<option value="${value}">${hfTitle}</option>` : '';
});
document.querySelector(nodeQuery).innerHTML += optionStr;
});