url-from-template
v0.1.0
Published
A module to convert route template strings like /my-route/:id into valid url
Downloads
2
Readme
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
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:
License
MIT © with :heart: & :coffee: by Hamza Baig