Skip to content

hamxabaig/url-from-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

url-from-template Build Status

A module to convert route template strings like /my-route/:id into valid url according to the params & query given. 🚀

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 ❤️ & ☕ by Hamza Baig

About

Convert your route templates into valid urls 🚀

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published