https://github.com/hamxabaig/url-from-template
Convert your route templates into valid urls :rocket:
https://github.com/hamxabaig/url-from-template
querystring route url url-generator
Last synced: 2 months ago
JSON representation
Convert your route templates into valid urls :rocket:
- Host: GitHub
- URL: https://github.com/hamxabaig/url-from-template
- Owner: hamxabaig
- License: mit
- Created: 2018-12-22T17:50:07.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-12-22T18:06:16.000Z (over 6 years ago)
- Last Synced: 2025-03-10T09:19:35.164Z (2 months ago)
- Topics: querystring, route, url, url-generator
- Language: JavaScript
- Size: 2.93 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# url-from-template [](https://travis-ci.com/hamxabaig/url-from-template)
> A module to convert route template strings like `/my-route/:id` into valid url according to the params & query given. :rocket:
## Install
```
$ npm install url-from-template
```## Usage
```js
const buildUrl = require('url-from-template');buildUrl('/test/:id', {params: {id: '123'}});
//=> '/test/123'buildUrl('/test/:id', {params: {id: '123'}, query: {awesome: 'yeah'}});
//=> '/test/123?awesome=yeah'
```## API
### buildUrl(template, options)
#### template
Type: `string`
Template to generate url from. For params, you can use `:` to make it a param.
> When you give param to route, you must give its value in params object in options.#### options
Type: `Object`
##### params
Type: `Object`
Params to replace in template.
##### query
Type: `Object`
Query params to add in route.
> If your query has invalid value, it'll not be in the return url.## Dependencies
It uses the following awesome libraries:
- [query-string](https://github.com/sindresorhus/query-string)
- [route-parser](https://github.com/rcs/route-parser)## License
MIT © with :heart: & :coffee: by [Hamza Baig](http://hamxabaig.github.io)