path-handler-map
v2.3.2
Published
> A path to handler map, base on [radix tree](http://en.wikipedia.org/wiki/Radix_tree).
Readme
path-handler-map
A path to handler map, base on radix tree.
Installation
npm install path-handler-mapUsage
import { PathHandlerMap } from 'path-handler-map';
let m = new PathHandlerMap();
m.add('/user', 'GET', () => { });
m.add('/post/:post_id', 'GET', () => { });
let r = m.find('GET', '/post/234');Pattern Rule
| Syntax | Description |
|--------|-------------|
| :name | named param |
| : | unnamed param |
| :name* or *name | named catch-all param |
| :* or * | unnamed catch-all param |
- Named parameters and unnamed parameters match anything until the next '/' or the path end.
- Named catch-all param and unnamed catch-all param match anything until the path end.
Path matching order
- Static
- Param
- Match any
Examples
/api/*
/api/users/:user_name
/api/users/popularAbove routes would resolve in the following order:
/api/users/popular/api/users/:user_name/api/*
Inspired by
License
MIT
