diff --git a/lib/elementSearch.js b/lib/elementSearch.js index ad5c0fe98..16caa4c71 100644 --- a/lib/elementSearch.js +++ b/lib/elementSearch.js @@ -32,43 +32,43 @@ function match(text, options = {}, ...args) { const searchText = args.text[0] === "/" && args.text.lastIndexOf("/") > 0 ? new RegExp( - args.text.substring(1, args.text.lastIndexOf("/")), - args.text.substring(args.text.lastIndexOf("/") + 1), - ) + args.text.substring(1, args.text.lastIndexOf("/")), + args.text.substring(args.text.lastIndexOf("/") + 1), + ) : args.text - .toLowerCase() - .replace( - /\s+/g /* all kinds of spaces*/, - " " /* ordinary space */, - ) - .trim(); + .toLowerCase() + .replace( + /\s+/g /* all kinds of spaces*/, + " " /* ordinary space */, + ) + .trim(); const nodeFilter = args.tagName === "*" ? { - acceptNode(node) { - //Filter nodes that need not be searched for text - return [ - "head", - "script", - "style", - "html", - "body", - "#comment", - ].includes(node.nodeName.toLowerCase()) - ? NodeFilter.FILTER_REJECT - : NodeFilter.FILTER_ACCEPT; - }, - } + acceptNode(node) { + //Filter nodes that need not be searched for text + return [ + "head", + "script", + "style", + "html", + "body", + "#comment", + ].includes(node.nodeName.toLowerCase()) + ? NodeFilter.FILTER_REJECT + : NodeFilter.FILTER_ACCEPT; + }, + } : { - acceptNode(node) { - //Filter nodes that match tagName - return args.tagName.toLowerCase() === - node.nodeName.toLowerCase() - ? NodeFilter.FILTER_ACCEPT - : NodeFilter.FILTER_REJECT; - }, - }; + acceptNode(node) { + //Filter nodes that match tagName + return args.tagName.toLowerCase() === + node.nodeName.toLowerCase() + ? NodeFilter.FILTER_ACCEPT + : NodeFilter.FILTER_REJECT; + }, + }; const iterator = document.createNodeIterator( selectorElement, @@ -82,21 +82,21 @@ function match(text, options = {}, ...args) { function checkIfRegexMatch(text, searchText, exactMatch) { return exactMatch ? isRegex(searchText) && - text && - text.match(searchText) && - text.match(searchText)[0] === text + text && + text.match(searchText) && + text.match(searchText)[0] === text : isRegex(searchText) && text && text.match(searchText); } function normalizeText(text) { return text ? text - .toLowerCase() - .replace( - /\s+/g /* all kinds of spaces*/, - " " /* ordinary space */, - ) - .trim() + .toLowerCase() + .replace( + /\s+/g /* all kinds of spaces*/, + " " /* ordinary space */, + ) + .trim() : ""; } @@ -141,8 +141,8 @@ function match(text, options = {}, ...args) { ) { exactMatches.push(node); continue; - } - if ( + // biome-ignore lint/style/noUselessElse: Does not work without this logic + } else if ( // Contains match of values and types !args.exactMatch && (checkIfRegexMatch(node.value, searchText, false) || @@ -285,11 +285,11 @@ const findElements = async (selector, tag) => { const elements = await (async () => { if (isString(selector)) { return match(selector).elements(tag); - } - if (isSelector(selector)) { + // biome-ignore lint/style/noUselessElse: Does not work without this logic + } else if (isSelector(selector)) { return selector.elements(); - } - if (isElement(selector)) { + // biome-ignore lint/style/noUselessElse: Does not work without this logic + } else if (isElement(selector)) { return [selector]; } return null;