diff --git a/src/utils/url.ts b/src/utils/url.ts index 9f1bb47ce..c43389688 100644 --- a/src/utils/url.ts +++ b/src/utils/url.ts @@ -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) { @@ -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);