{"slug": "a-tool-matcher-in-40-lines-of-vanilla-javascript", "title": "A tool matcher in ~40 lines of vanilla JavaScript", "summary": "A developer built a roughly 40-line vanilla JavaScript tool matcher for a small AI tools directory, mapping user tasks to recommended tools via data attributes and a plain object lookup. The matcher uses native button elements for keyboard support, aria-pressed for selection state, and an aria-live region for results, with tool data kept in a single object so adding a tool requires only one line. The developer packaged it into a static site with search, guides, and 12 tools, offering a live demo and paid source.", "body_md": "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?\"\n\nHere is the whole matcher. No framework, no state library, ~40 lines.\n\n``` js\nconst tools = {\n  writing:  { name: \"Claude\",     why: \"long-form drafting and editing\" },\n  design:   { name: \"Canva\",      why: \"social graphics without a designer\" },\n  research: { name: \"Perplexity\", why: \"answers with sources you can check\" },\n  admin:    { name: \"Zapier\",     why: \"gluing apps together\" },\n};\n\nconst choices = document.querySelectorAll(\"[data-match]\");\nconst result = document.querySelector(\"#match-result\");\n\nchoices.forEach((button) => {\n  button.addEventListener(\"click\", () => {\n    const task = button.dataset.match;\n    const tool = tools[task];\n    if (!tool) return;\n\n    choices.forEach((b) => b.setAttribute(\"aria-pressed\", String(b === button)));\n    result.hidden = false;\n    result.innerHTML =\n      \"<strong>\" + tool.name + \"</strong> - \" + tool.why +\n      ' <a href=\"https://example.com\" rel=\"noopener\">Visit site</a>';\n  });\n});\n```\n\nThree things that made it feel good to use:\n\n`<button type=\"button\" data-match=\"writing\">` gets keyboard support for free.`aria-pressed` for state.`aria-live=\"polite\"` on the result.\nThe 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.\n\nI 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.", "url": "https://wpnews.pro/news/a-tool-matcher-in-40-lines-of-vanilla-javascript", "canonical_source": "https://dev.to/hayden_hall_1ee060e912e1c/a-tool-matcher-in-40-lines-of-vanilla-javascript-2gb7", "published_at": "2026-12-06 11:38:11+00:00", "updated_at": "2026-12-06 11:43:59.483104+00:00", "lang": "en", "topics": ["developer-tools", "ai-tools", "ai-products"], "entities": ["Claude", "Canva", "Perplexity", "Zapier", "Netlify", "Payhip"], "also_reported_by": [], "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.", "recommendation": null, "alternates": {"html": "https://wpnews.pro/news/a-tool-matcher-in-40-lines-of-vanilla-javascript", "markdown": "https://wpnews.pro/news/a-tool-matcher-in-40-lines-of-vanilla-javascript.md", "text": "https://wpnews.pro/news/a-tool-matcher-in-40-lines-of-vanilla-javascript.txt", "jsonld": "https://wpnews.pro/news/a-tool-matcher-in-40-lines-of-vanilla-javascript.jsonld"}}