mirror of
https://github.com/honojs/hono.git
synced 2024-12-01 10:51:01 +00:00
390d05b006
* feat(context): `c.routerName()` * chore: denoify * Enable to get router name via `app.routerName`. (#1110) --------- Co-authored-by: Taku Amano <taku@taaas.jp>
29 lines
674 B
TypeScript
29 lines
674 B
TypeScript
import type { Result, Router } from '../../router.ts'
|
|
import { checkOptionalParameter } from '../../utils/url.ts'
|
|
import { Node } from './node.ts'
|
|
|
|
export class TrieRouter<T> implements Router<T> {
|
|
name: string = 'TrieRouter'
|
|
node: Node<T>
|
|
|
|
constructor() {
|
|
this.node = new Node()
|
|
}
|
|
|
|
add(method: string, path: string, handler: T) {
|
|
const results = checkOptionalParameter(path)
|
|
if (results) {
|
|
for (const p of results) {
|
|
this.node.insert(method, p, handler)
|
|
}
|
|
return
|
|
}
|
|
|
|
this.node.insert(method, path, handler)
|
|
}
|
|
|
|
match(method: string, path: string): Result<T> | null {
|
|
return this.node.search(method, path)
|
|
}
|
|
}
|