Options
All
  • Public
  • Public/Protected
  • All
Menu

Class RouteTrie

A trie data structure that stores routes. The trie supports :param and *wildcard values.

Hierarchy

  • RouteTrie

Index

Constructors

constructor

Properties

Private children

children: Record<string, RouteTrie> = {}

Private Optional paramChild

paramChild: ParamChild

Private Optional route

route: Route

Private Optional wildcardChild

wildcardChild: WildcardChild

Methods

add

  • add(path: string, route: Route): void
  • Adds a route to the trie.

    Parameters

    • path: string
    • route: Route

    Returns void

get

  • get(path: string): [undefined | Route, Record<string, string>]
  • Returns a route mapped to the given path and any parameter values from the URL.

    Parameters

    • path: string

    Returns [undefined | Route, Record<string, string>]

Private getRoute

  • getRoute(path: string, params: Record<string, string>): undefined | Route
  • Parameters

    • path: string
    • params: Record<string, string>

    Returns undefined | Route

Private normalizePath

  • normalizePath(path: string): string
  • Normalizes a path for inclusion into the route trie.

    Parameters

    • path: string

    Returns string

Private splitPath

  • splitPath(path: string): [string, string]
  • Splits the parent directory from its children, e.g.:

    splitPath("foo/bar/baz") -> ["foo", "bar/baz"]
    

    Parameters

    • path: string

    Returns [string, string]

walk

  • walk(cb: (path: string, route: Route) => void): void
  • Walks the route trie and calls a callback function for each route.

    Parameters

    • cb: (path: string, route: Route) => void
        • (path: string, route: Route): void
        • Parameters

          • path: string
          • route: Route

          Returns void

    Returns void

Generated using TypeDoc