PathTree Playground

A tiny TypeScript path tree matcher for static routes, named parameters, wildcards, and optional groups.

📖 Path Syntax

  • /users — static text
  • /:id — named parameter
  • /*rest — wildcard
  • {/segment} — optional group
  • /"hello" — quoted segment preserved with quotes
  • /:"something", /*"something" — quoted param/wildcard tokens preserve prefixes

💡 Examples

/a/b{/d}/hello matches both /a/b/hello and /a/b/d/hello

/blog/:year/:slug captures year and slug parameters

/api/posts/:id/*rest captures post ID and remaining path

/api/"hello" treats "hello" as a quoted literal segment

🚀 Quick Start

npm install path-tree-matcher

Import and create a tree instance:

import { PathTree } from "path-tree-matcher"
const tree = new PathTree()
tree.setPattern("/api/users/:id")
const matches = tree.match("/api/users/123")