@bbfan/populate-url
v1.0.5
Published
Helps to manage your URL templates and populate parameters to it. Has a TS type validation that shows required template params to be filled.
Downloads
3
Maintainers
Readme
@bbfan/populate-url
Helps to populate your URL with path and query parameters. Has a TS support, that parse constant templates and shows expected parameters.
Install
$ npm install @bbfan/populate-url
Usage
const ROUTES = {
testRoute: '/test/:testId/foo/:bar?id=:id',
} as const;
const populatedUrl = populateUrl(ROUTES.testRoute, {
id: 123,
bar: 'test',
testId: null,
});
console.log(populatedUrl); // /test/null/foo/test?id=123
Examples of valid URL formats
http://test.com/path/:param1/:param2/?id=:id&test=:test
/test.com/path/:param1/:param2/?id=:id&test=:test
test.com/path/:param1/:param2/?id=:id&test=:test
test.com/path/:param1/:param2?id=:id&test=:test
/path/:param1/:param2?id=:id&test=:test
path/:param1/:param2?id=:id&test=:test
path/:param1/:param2