Skip to content

Commit

Permalink
Merge pull request #15 from krutoo/url-utils
Browse files Browse the repository at this point in the history
url: JSDoc added
  • Loading branch information
krutoo authored Oct 15, 2024
2 parents 7c2ec26 + 3eedd90 commit 4e79340
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/url/url.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import type { URLSearchParamsInit } from './types.ts';

/**
* Получив параметры применит их к переданному URL.
* Having received the parameters will apply them to the transferred URL.
* @param url URL.
* @param params Параметры.
* @param params Parameters init - object with any property values.
* @return Exactly same URL object.
*/
export function setParams(url: URL, params: URLSearchParamsInit): URL {
for (const [paramName, paramValue] of Object.entries(params)) {
Expand All @@ -21,30 +22,37 @@ export function setParams(url: URL, params: URLSearchParamsInit): URL {
return url;
}

/**
* Having received the URL will delete all the parameters and return it.
* @param url URL.
* @return Exactly same URL object.
*/
export function resetParams(url: URL): URL {
url.search = '';

return url;
}

/**
* Получив URL и параметры вернет новый URL с примененными параметрами.
* Having received the URL and the parameters will return the new URL using the parameters.
* @param url URL.
* @param params Параметры.
* @return URL.
* @param params Parameters.
* @return New URL.
*/
export function withParams(url: string | URL, params: URLSearchParamsInit): URL {
return setParams(new URL(url), params);
}

/**
* Получив URL вернет его копию но без параметров.
* Having received the URL will return its copy but without parameters.
* @param url URL.
* @return URL.
* @return New URL.
*/
export function withoutParams(url: string | URL): URL {
return resetParams(new URL(url));
}

/** Utils for working with URL. */
export const URLUtil = {
setParams,
resetParams,
Expand Down

0 comments on commit 4e79340

Please sign in to comment.