Skip to content

Commit

Permalink
Add the else if blocks
Browse files Browse the repository at this point in the history
Signed-off-by: Zabil Cheriya Maliackal <[email protected]>
  • Loading branch information
zabil committed Aug 13, 2024
1 parent 52dddf9 commit bc9f051
Showing 1 changed file with 46 additions and 46 deletions.
92 changes: 46 additions & 46 deletions lib/elementSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()
: "";
}

Expand Down Expand Up @@ -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) ||
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit bc9f051

Please sign in to comment.