Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mytecor/path2regexp
Micro version of express routing
https://github.com/mytecor/path2regexp
midly path path-to-regexp regexp routing
Last synced: 4 days ago
JSON representation
Micro version of express routing
- Host: GitHub
- URL: https://github.com/mytecor/path2regexp
- Owner: mytecor
- License: mit
- Created: 2019-04-03T12:09:52.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-05-18T13:08:38.000Z (over 3 years ago)
- Last Synced: 2024-12-12T00:37:50.182Z (12 days ago)
- Topics: midly, path, path-to-regexp, regexp, routing
- Language: JavaScript
- Size: 14.6 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# path2regexp
## Usage
```js
let p2r = require('path2regexp')// Optional parameters
let ex1 = p2r('/user/:login/:method?/:action')
console.log(ex1('/user/mytecor/test')) // {login: 'mytecor', method: undefined, action: 'test'}
console.log(ex1('/user/mytecor/get/test')) // {login: 'mytecor', method: 'get', action: 'test'}// Unnamed parameters
let ex2 = p2r('/user/(.*)/:action')
console.log(ex2('/user/get/test')) // {unnamed: ['get'], action: 'test'}// Regexp route
let ex3 = p2r(/\/user\/(.*)/)
console.log(ex3('/user/get/test')) // {unnamed: ['get/test']}// Other routes
let ex4 = p2r('/user/(get|post)/:action')
console.log(ex4('/user/post/test')) // {unnamed: ['post'], action: 'test'}
```