https://github.com/emartech/koa-router-param
Middlewares for Koa Router Params
https://github.com/emartech/koa-router-param
Last synced: over 1 year ago
JSON representation
Middlewares for Koa Router Params
- Host: GitHub
- URL: https://github.com/emartech/koa-router-param
- Owner: emartech
- License: mit
- Created: 2016-06-20T07:21:57.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2023-01-23T12:22:06.000Z (over 3 years ago)
- Last Synced: 2024-04-14T07:41:03.535Z (over 2 years ago)
- Language: JavaScript
- Size: 14.6 KB
- Stars: 1
- Watchers: 9
- Forks: 1
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# koa-router-param
> Params Router middleware for [koa-router](https://github.com/alexmingoia/koa-router)
## Installation
Install using [npm](https://www.npmjs.org/):
```sh
npm install koa-router-param
```
## API Reference
* [koa-router-param(params)](#module_koa-router-param)
* .Type
* _static_ [.Number](#exp_module_koa-router-param--Type--Number)
## KoaRouterParam(params) ⇒ Generator
Creates a middleware for _koa-router_ route.
#### Parameters
| Param | Type | Description |
| --- | --- | --- |
| params | Object | An object representing the processable URL params |
| ↳ key | String | Name of the param in the URL |
| ↳ value | Generator | A transformer for the param's value |
#### Example
Basic usage:
```javascript
var Router = require('koa-router');
var routerParam = require('koa-router-param');
router
.get(
'/users/:userId',
routerParam({ userId: routerParam.Type.Number }),
function *(next) {
console.log(this.params.userId); // => Number(123)
}
);
```
## RouterParam.Type.Number ⇒ Generator
Casts the given parameter to `Number`.
#### Example
Basic usage:
```javascript
{ paramName: routerParam.Type.Number }
```
## Contributing
Please submit all issues and pull requests to the [emartech/koa-router-param](https://github.com/emartech/koa-router-param) repository!
## Tests
Run tests using `npm test`.
## Support
If you have any problem or suggestion please open an issue [here](https://github.com/emartech/koa-router-param/issues).