path-params
Version:
Replace path params based on express route notation
53 lines (35 loc) • 1.8 kB
Markdown
# path-params [][travis] [](https://www.npmjs.org/package/path-params) [](http://standardjs.com)
Replace path params based on `express` route notation.
## Installation
Via npm:
```bash
npm install path-params --save
```
Via bower:
```bash
bower install path-params --save
```
Or loading the script:
```html
<script src="//cdn.rawgit.com/h2non/path-params/master/path-params.js"></script>
```
## Environments
Runs in any [ES5 compliant](http://kangax.github.io/mcompat-table/es5/) engine:
 |  |  |  |  | 
--- | --- | --- | --- | --- | --- |
+0.8 | +5 | +3.5 | +9 | +12 | +5 |
## Usage
```js
const pathParams = require('path-params')
const path = pathParams('/users/:id/:action', { id: 123, action: 'foo' })
if (path instanceof Error) {
console.error('Params error:', err.message)
} else {
console.log('Path:', path) // -> '/users/123/foo'
}
```
## API
### pathParams(path, params) => `String|Error`
## License
[MIT](http://opensource.org/licenses/MIT) © Tomas Aparicio
[travis]: http://travis-ci.org/h2non/path-params