# A tool matcher in ~40 lines of vanilla JavaScript

> Source: <https://dev.to/hayden_hall_1ee060e912e1c/a-tool-matcher-in-40-lines-of-vanilla-javascript-2gb7>
> Published: 2026-12-06 11:38:11+00:00

**Key takeaway:** A task-to-tool matcher can be built in about 40 lines of vanilla JavaScript by storing tools in a plain object keyed by task and using data-match buttons with aria-pressed and an aria-live result region.

When I built a small AI tools directory, the feature people actually used was not the tool list - it was one question: "what are you trying to do?"

Here is the whole matcher. No framework, no state library, ~40 lines.

``` js
const tools = {
  writing:  { name: "Claude",     why: "long-form drafting and editing" },
  design:   { name: "Canva",      why: "social graphics without a designer" },
  research: { name: "Perplexity", why: "answers with sources you can check" },
  admin:    { name: "Zapier",     why: "gluing apps together" },
};

const choices = document.querySelectorAll("[data-match]");
const result = document.querySelector("#match-result");

choices.forEach((button) => {
  button.addEventListener("click", () => {
    const task = button.dataset.match;
    const tool = tools[task];
    if (!tool) return;

    choices.forEach((b) => b.setAttribute("aria-pressed", String(b === button)));
    result.hidden = false;
    result.innerHTML =
      "<strong>" + tool.name + "</strong> - " + tool.why +
      ' <a href="https://example.com" rel="noopener">Visit site</a>';
  });
});
```

Three things that made it feel good to use:

`<button type="button" data-match="writing">` gets keyboard support for free.`aria-pressed` for state.`aria-live="polite"` on the result.
The data stays in a plain object, so adding a tool means adding one line. If you later want search, filter `Object.entries(tools)` - the matcher and the list can share the same source of truth.

I wrapped this into a complete static site (search, guides, 12 tools) - live demo: [https://toolroom-ai-tools.netlify.app](https://toolroom-ai-tools.netlify.app) - and the source is available here: [https://payhip.com/b/5j0hC](https://payhip.com/b/5j0hC) if you want to skip the setup.
