Adds type checking for section search

This commit is contained in:
Alicia Sykes 2022-02-01 19:15:18 +00:00
parent 11291ae0e6
commit a5944c1d06
1 changed files with 3 additions and 3 deletions

View File

@ -64,10 +64,10 @@ export default {
/* If an initial URL is specified, then open relevant section */ /* If an initial URL is specified, then open relevant section */
openDefaultSection() { openDefaultSection() {
if (!this.initUrl) return; if (!this.initUrl) return;
const process = (url) => url.replace(/[^\w\s]/gi, '').toLowerCase(); const process = (url) => (url ? url.replace(/[^\w\s]/gi, '').toLowerCase() : undefined);
const compare = (item) => (process(item.url) === process(this.initUrl)); const compare = (item) => (process(item.url) === process(this.initUrl));
this.sections.forEach((section, sectionIndex) => { this.sections.forEach((section, secIndex) => {
if (section.items.findIndex(compare) !== -1) this.openSection(sectionIndex); if (section.items && section.items.findIndex(compare) !== -1) this.openSection(secIndex);
}); });
}, },
}, },