1.1.0 • Published 6 years ago

url-constructor v1.1.0

Weekly downloads
5
License
MIT
Repository
github
Last release
6 years ago

url-constructor

Given a url with parameters defined by colons, we can match the key and replace it with values from an object:

const urlConstruct = require('url-constructor')

const url = '/orders/:id'
const id = 123

urlConstruct(url, { id })
// '/orders/123'

Or a more complex situation with query params

const urlConstruct = require('url-constructor')

const url = '/orders/:id?cancel=:cancel'
const id = 123
const cancel = true

urlConstruct(url, { id, cancel })
// '/orders/123?cancel=true'