Commit 9f84b43f authored by Alejandro Celaya's avatar Alejandro Celaya Committed by Alejandro Celaya

Migrate url module to TS

parent 7ff6ebdb
...@@ -8,15 +8,12 @@ import { hasOwn } from '../../shared/has-own'; ...@@ -8,15 +8,12 @@ import { hasOwn } from '../../shared/has-own';
* *
* replaceURLParams('/things/:id', {id: 'foo', q: 'bar'}) => * replaceURLParams('/things/:id', {id: 'foo', q: 'bar'}) =>
* {url: '/things/foo', unusedParams: {q: 'bar'}} * {url: '/things/foo', unusedParams: {q: 'bar'}}
*
* @template Param
* @param {string} url
* @param {Record<string, Param>} params
* @return {{ url: string, unusedParams: Record<string, Param>}}
*/ */
export function replaceURLParams(url, params) { export function replaceURLParams<Param>(
/** @type {Record<string, Param>} */ url: string,
const unusedParams = {}; params: Record<string, Param>
): { url: string; unusedParams: Record<string, Param> } {
const unusedParams: Record<string, Param> = {};
for (const param in params) { for (const param in params) {
if (hasOwn(params, param)) { if (hasOwn(params, param)) {
const value = params[param]; const value = params[param];
...@@ -33,10 +30,7 @@ export function replaceURLParams(url, params) { ...@@ -33,10 +30,7 @@ export function replaceURLParams(url, params) {
/** /**
* Resolve a relative URL against a base URL to get an absolute URL. * Resolve a relative URL against a base URL to get an absolute URL.
*
* @param {string} relativeURL
* @param {string} baseURL
*/ */
export function resolve(relativeURL, baseURL) { export function resolve(relativeURL: string, baseURL: string): string {
return new URL(relativeURL, baseURL).href; return new URL(relativeURL, baseURL).href;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment