2.3.2 • Published 7 years ago

path-handler-map v2.3.2

Weekly downloads
4
License
MIT
Repository
github
Last release
7 years ago

path-handler-map

A path to handler map, base on radix tree.

Installation

npm install path-handler-map

Usage

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

SyntaxDescription
:namenamed param
:unnamed param
:name* or *namenamed 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/popular

Above routes would resolve in the following order:

  • /api/users/popular
  • /api/users/:user_name
  • /api/*

Inspired by

License

MIT

2.3.2

7 years ago

2.3.1

7 years ago

2.3.0

7 years ago

2.2.0

7 years ago

2.1.0

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.0.0

7 years ago