UNPKG

@straw-hat/fetcher

Version:
14 lines 783 B
export function replacePathParams(urlPath, pathParams = {}) { return Object.entries(pathParams).reduce((theUrlPath, [name, value]) => theUrlPath.replaceAll(`{${name}}`, value), urlPath); } function addQueryParams(urlPath, queryParams) { const searchParams = new URLSearchParams(queryParams); return `${urlPath}?${searchParams.toString()}`; } export function createUrlPath(urlPath, params) { // @ts-ignore TODO: Not sure how to fix the problem with `never` type being a possibility const normalizedPath = replacePathParams(urlPath, params.path); // @ts-ignore TODO: Not sure how to fix the problem with `never` type being a possibility return params.query ? addQueryParams(normalizedPath, params.query) : normalizedPath; } //# sourceMappingURL=index.js.map