This is a simple path template replacement tool for nodejs.
$ npm install path-templater
import pathTemplater from 'path-templater';
pathTemplater('/:name', { name: 'wcj' }) // => /wcj
pathTemplater('/:name/:name', { name: 'wcj' }) // => /wcj/wcj
pathTemplater('https://localhost/:name/:name', { name: 'wcj' }) // => https://localhost/wcj/wcj
pathTemplater('https://github.com/:owner/:repo', { owner: 'jaywcjlove', repo: 'path-templater' })
// => https://github.com/jaywcjlove/path-templater
pathTemplater(':apiBaseUrl/:owner/:repo', {
owner: 'jaywcjlove',
repo: 'path-templater',
apiBaseUrl: 'https://github.com'
})
// => https://github.com/jaywcjlove/path-templater
pathTemplater('https://localhost:3001/:name/:name', { name: 'wcj' })
// => https://localhost:3001/wcj/wcj
pathTemplater('https://localhost:3001/:name/:name?id=:user', { name: 'wcj', user: 'jaywcjlove' })
// => https://localhost:3001/wcj/wcj?id=jaywcjlove
pathTemplater(':apiBaseUrl/:owner/:repo', { owner: 'jaywcjlove', repo: 'path-templater' })
// 🚨 => Could not find url parameter apiBaseUrl in passed options object;
As always, thanks to our amazing contributors!
Made with contributors.
This package is licensed under the MIT License.