Skip to content

Commit

Permalink
docs: add example to url.ts (#1112)
Browse files Browse the repository at this point in the history
* docs: add example to url.ts

* test: reomve leftover
  • Loading branch information
CollinsC1O authored May 2, 2024
1 parent 366c960 commit ba35b6c
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/utils/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ const nonLocalhostDomainRE = /^[^\s.]+\.\S{2,}$/;

/**
* Loosely validate a URL `string`.
*
* @param {string} s - The URL to check for
* @return {boolean} `true` if url is valid, `false` otherwise
* @example
* ```typescript
* const s = "https://starknetjs.com/docs";
* const result = isUrl(s);
* // result == true
*/
export function isUrl(s?: string): boolean {
if (!s) {
Expand Down Expand Up @@ -53,6 +61,14 @@ export function isUrl(s?: string): boolean {
* @param {string} defaultPath - The default path to use if no URL or path is provided.
* @param {string} [urlOrPath] - The optional URL or path to append to the base URL.
* @return {string} The built URL.
* @example
* ```typescript
* const baseUrl = "https://starknetjs.com";
* const defaultPath = "/";
* const urlOrPath = "/docs";
* const result = buildUrl(baseUrl, defaultPath, urlOrPath);
*
* result = "https://starknetjs.com/docs"
*/
export function buildUrl(baseUrl: string, defaultPath: string, urlOrPath?: string) {
return isUrl(urlOrPath) ? urlOrPath! : urljoin(baseUrl, urlOrPath ?? defaultPath);
Expand Down

0 comments on commit ba35b6c

Please sign in to comment.