Skip to content

Commit

Permalink
35 add aliases for tag names (#91)
Browse files Browse the repository at this point in the history
* closes #35

* rename heroSection tag to hero
  • Loading branch information
willpinha authored Feb 19, 2024
1 parent 968959c commit 1f12d02
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 3 deletions.
99 changes: 99 additions & 0 deletions src/utils/aliases.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
const aliases: { [tag: string]: string[] } = {
"alert": [
"success",
"info",
"warning",
"error",
"danger",
"feedback",
"notification"
],
"authentication": [
"login",
"register",
"account",
"signin",
"password",
"email"
],
"card": [
"image",
"socials",
"product",
"stars"
],
"cookies": [
"browser",
"web",
"internet",
"http",
"session"
],
"dropdown": [
"list",
"select"
],
"faq": [
"questions",
"q&a",
"support",
"help",
"assistance"
],
"footer": [
"bottom",
"section",
"bar"
],
"hero": [
"welcome",
"section",
"home",
"page"
],
"input": [
"text",
"data",
"typing",
"form"
],
"modal": [
"popup",
"dialog",
"overlay",
"window"
],
"navbar": [
"section",
"menu",
"header",
"bar"
],
"pricing": [
"money",
"costing",
"fee",
"charge"
],
"sidebar": [
"bar",
"column",
"menu",
"section"
],
"subscribe": [
"register",
"signup",
"follow",
"email",
"update"
],
"team": [
"group",
"company",
"squad",
"employees"
]
};

export default aliases;
26 changes: 23 additions & 3 deletions src/utils/filter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
import aliases from "./aliases";

// Format tag and filter before comparison
function format(name: string) {
return name.toLowerCase().replace(/\s+/g, ""); // Case and whitespace insensitive
}

export function isMatch(tag: string, filter: string): boolean {
tag = tag.toLowerCase();
filter = filter.replace(/\s+/g, "").toLowerCase(); // Case and whitespace insensitive
filter = format(filter)

const targets = [tag]

if (tag in aliases) {
targets.push(...aliases[tag]);
}

for (let target of targets) {
target = format(target);

if (target.startsWith(filter)) {
return true;
}
}

return tag.startsWith(filter);
return false;
}

0 comments on commit 1f12d02

Please sign in to comment.