import { type ArrayOrValue } from '../array/array'; import { type EmailAddress } from '../contact/email'; import { type E164PhoneNumberExtensionPair, type E164PhoneNumberWithOptionalExtension, type PhoneNumber } from '../contact/phone'; import { type IndexRangeInput } from './../value/indexed'; import { type MapFunction } from '../value/map'; import { type Maybe } from '../value/maybe.type'; /** * Connection protocol * * I.E. http, https, etc. * * @semanticType * @semanticTopic url * @semanticTopic string */ export type WebsiteProtocol = string; /** * The HTTP protocol string literal type. */ export type HttpWebsiteProtocol = 'http'; /** * The HTTPS protocol string literal type. */ export type HttpsWebsiteProtocol = 'https'; /** * Known HTTP protocols: `"http"` or `"https"`. */ export type KnownHttpWebsiteProtocol = HttpWebsiteProtocol | HttpsWebsiteProtocol; /** * Returns true if the input string is a known HTTP protocol (`"http"` or `"https"`). * * @param input - The protocol string to check. * @returns Whether the input is `"http"` or `"https"`. */ export declare function isKnownHttpWebsiteProtocol(input: string): input is KnownHttpWebsiteProtocol; /** * A website domain. * * Examples: * - dereekb.com * - components.dereekb.com * * @semanticType * @semanticTopic url * @semanticTopic string */ export type WebsiteDomain = string; /** * Simple website domain regex that looks for a period in the string between the domain and the tld. * * Anchored character-class form prevents catastrophic backtracking on inputs without a period. */ export declare const HAS_WEBSITE_DOMAIN_NAME_REGEX: RegExp; /** * Returns true if the input probably contains a website domain (has at least one period separating parts). * * Examples where it will return true: * - dereekb.com * - test://dereekb.com * - https://components.dereekb.com * - https://components.dereekb.com/ * - https://components.dereekb.com/doc/home * * @param input - The string to check for a domain. * @returns Whether the input appears to contain a website domain. */ export declare function hasWebsiteDomain(input: string): input is WebsiteDomain; /** * The top-level domain (tld). * * Examples: * - com * - net * * @semanticType * @semanticTopic url * @semanticTopic string */ export type WebsiteTopLevelDomain = string; /** * This Regex is really only reliable for detecting that the TLD exists, but due to the nature of tld's * it cannot always be determined whether or not the part of the url is part of the tld or a subdomain. */ export declare const WEBSITE_TLD_DETECTION_REGEX: RegExp; /** * Returns true if the input url has a website top level domain. * * It does not check whether or not the tld is a recognized tld. * * @param input - The URL string to check. * @returns Whether the input appears to have a top-level domain. */ export declare function hasWebsiteTopLevelDomain(input: string): boolean; /** * Regex that matches a colon followed by digits, used to detect port numbers in URLs. */ export declare const HAS_PORT_NUMBER_REGEX: RegExp; /** * A connection port number. * * Example: * - 443 * - 8080 * * @semanticType * @semanticTopic numeric * @semanticTopic url */ export type PortNumber = number; /** * Returns true if the input string contains a port number (e.g., `:8080`). * * Examples where it will return true: * - localhost:8080 * - dereekb.com:8080 * - https://components.dereekb.com:8080 * - https://components.dereekb.com:8080/ * - https://components.dereekb.com:8080/doc/home * * @param input - The string to check for a port number. * @returns Whether the input contains a port number. */ export declare function hasPortNumber(input: string): boolean; /** * Extracts the port number from the input string, if one is present. * * @param input - The string to extract a port number from. * @returns The port number, or `undefined` if none is found. */ export declare function readPortNumber(input: string): Maybe; /** * A website url that starts with http:// or https:// * * May or may not end with a slash. */ export type BaseWebsiteUrl = `http://${D}` | `https://${D}`; /** * Input for baseWebsiteUrl() */ export type BaseWebsiteUrlInput = string | WebsiteUrl | WebsiteDomain; /** * Creates a base website URL (with `http://` or `https://` prefix) from the input domain or URL. * If the input lacks a TLD and port, the default TLD is appended. * * @param input - A domain, URL, or partial URL string. * @param defaultTld - The TLD to append if none is detected. Defaults to `"com"`. * @returns A fully-qualified base website URL. */ export declare function baseWebsiteUrl(input: BaseWebsiteUrlInput, defaultTld?: string): BaseWebsiteUrl; /** * A website url. Is at minimum a domain. * * Examples: * - dereekb.com * - https://components.dereekb.com * - https://components.dereekb.com/ * - https://components.dereekb.com/doc/home? * - https://components.dereekb.com/doc/home?test=true&test2=true * * @semanticType * @semanticTopic url * @semanticTopic string */ export type WebsiteUrl = string; /** * Returns true if the input string is probably a website URL. * * Checks that it has a domain and the path is a valid slash path. Query parameters are ignored. * * @param input - The string to check. * @returns Whether the input appears to be a valid website URL. */ export declare function isWebsiteUrl(input: string): input is WebsiteUrl; /** * Detailed analysis of whether an input string is a valid website URL, including its parsed components. */ export interface WebsiteUrlDetails { /** * The original input string. */ readonly input: string; /** * Whether the input is a valid website URL. */ readonly isWebsiteUrl: boolean; /** * Whether the input has an `http://` or `https://` prefix. */ readonly hasHttpPrefix: boolean; /** * Whether the input contains a website domain. */ readonly hasWebsiteDomain: boolean; /** * Whether the input contains a port number. */ readonly hasPortNumber: boolean; /** * The port number, or `undefined` if none is present. */ readonly portNumber: Maybe; /** * The domain and path split pair. */ readonly splitPair: WebsiteDomainAndPathPair; /** * The extracted domain. */ readonly domain: WebsiteDomain; /** * The full website path including query string. */ readonly websitePath: WebsitePath; /** * The path portion without query parameters. */ readonly path: string; /** * The query string portion, or undefined if none. */ readonly query: Maybe; } /** * Parses the input string as a website URL and returns detailed information about its components. * * @param input - The string to analyze as a URL. * @returns An object containing parsed URL components and validation flags. */ export declare function websiteUrlDetails(input: string): WebsiteUrlDetails; /** * A website url that starts with the proper http/https prefix. * * @semanticType * @semanticTopic url * @semanticTopic string */ export type WebsiteUrlWithPrefix = string; /** * Returns true if the input string is probably a website URL and has an `http://` or `https://` prefix. * * @param input - The string to check. * @returns Whether the input is a website URL with an HTTP prefix. */ export declare function isWebsiteUrlWithPrefix(input: string): input is WebsiteUrlWithPrefix; /** * A "standard" internet accessible website url with a tld (.com/.net/etc) and optionally has the http/https protocol, but no other protocol. * * Examples: * - dereekb.com * - dereekb.com:8080 * - components.dereekb.com/ * - components.dereekb.com/doc/home * - http://dereekb.com * - https://components.dereekb.com/ * - https://components.dereekb.com/doc/home * * Non-examples: * - localhost:8080 // not internet-accessible * - test://dereekb.com // non-http/https protocol * * @semanticType * @semanticTopic url * @semanticTopic string */ export type StandardInternetAccessibleWebsiteUrl = string; /** * Returns true if the input is a standard internet-accessible website URL with a recognized TLD and optionally an HTTP/HTTPS protocol. * * @param input - The string to check. * @returns Whether the input is a standard internet-accessible website URL. */ export declare function isStandardInternetAccessibleWebsiteUrl(input: string): input is StandardInternetAccessibleWebsiteUrl; /** * A website's domain and path combined, without the BaseWebsiteUrl * * Examples: * - dereekb.com * - components.dereekb.com/ * - components.dereekb.com/doc/home * * @semanticType * @semanticTopic url * @semanticTopic string */ export type WebsiteDomainAndPath = string; /** * A website's path component. * * Examples: * - / * - /doc/home * - /doc/home?test=true */ export type WebsitePath = `/${string}`; /** * Creates a {@link WebsiteUrl} by merging the base path with additional path segments, preserving the original protocol. * * @param basePath - The base URL or domain to build upon. * @param paths - One or more path segments to append. * @param defaultProtocol - Optional protocol to use if the base path has none. * @returns The constructed website URL. */ export declare function websiteUrlFromPaths(basePath: BaseWebsiteUrlInput, paths: ArrayOrValue>, defaultProtocol?: WebsiteProtocol): WebsiteUrl; /** * Any query parameters that follow the path. */ export type WebsiteQueryString = `?${string}`; /** * Function that extracts and isolates a specific path portion from a website URL, domain-and-path, or path string. */ export type IsolateWebsitePathFunction = MapFunction; /** * Configuration for creating an {@link IsolateWebsitePathFunction}. */ export interface IsolateWebsitePathFunctionConfig { /** * Optional range of paths to isolate. */ readonly isolatePathComponents?: IndexRangeInput; /** * Base path to remove/ignore when isolating a path from the input. * * For example: * - For Reddit it could ignore /u or /u */ readonly ignoredBasePath?: string; /** * Whether or not to remove any query parameters if they exist. * * False by default. */ readonly removeQueryParameters?: boolean; /** * Whether or not to remove any trailing slash from the path. * * False by default. */ readonly removeTrailingSlash?: boolean; } /** * Creates an {@link IsolateWebsitePathFunction} that extracts and transforms a path from a website URL based on the configuration. * * @param config - Configuration for path isolation, including base path removal, component range, query handling, and trailing slash behavior. * @returns Isolates the configured portion of a website path. * * @dbxUtil * @dbxUtilCategory string * @dbxUtilKind factory * @dbxUtilTags string, url, path, isolate, transform, factory, query * @dbxUtilRelated website-path-from-website-url, website-path-and-query-pair, fix-extra-query-parameters * * @__NO_SIDE_EFFECTS__ */ export declare function isolateWebsitePathFunction(config?: IsolateWebsitePathFunctionConfig): IsolateWebsitePathFunction; /** * A pair containing the path and optional query string components of a website URL. */ export interface WebsitePathAndQueryPair { /** * The path portion of the URL (before the `?`). */ path: WebsitePath; /** * The query string portion of the URL (including the leading `?`), if present. */ query?: Maybe; } /** * Splits a website path string into its path and query string components. * * @param inputPath - The path string to split. * @returns A pair containing the path and optional query string. */ export declare function websitePathAndQueryPair(inputPath: string | WebsitePath): WebsitePathAndQueryPair; /** * Replaces extra `?` characters in a query string with `&` to fix malformed query parameters. * * By default, preserves the first `?` and replaces subsequent ones. If `replaceAll` is true, all `?` characters are replaced. * * @param input - The query string to fix. * @param replaceAll - If true, replaces all `?` characters (useful when the input is already past the initial `?`). * @returns The fixed query string. */ export declare function fixExtraQueryParameters(input: string, replaceAll?: boolean): string; /** * Extracts the path component from a website URL, stripping the protocol and domain. * * @param inputUrl - The URL to extract the path from. * @returns The website path component. */ export declare function websitePathFromWebsiteUrl(inputUrl: WebsiteUrl | WebsiteDomainAndPath): WebsitePath; /** * Splits a website URL into its domain and path components after removing the protocol prefix. * * @param inputUrl - The URL to split. * @returns A pair containing the domain and path. */ export declare function websiteDomainAndPathPairFromWebsiteUrl(inputUrl: WebsiteUrl | WebsiteDomainAndPath): WebsiteDomainAndPathPair; /** * Extracts the path component from a domain-and-path string. * * @param input - The domain-and-path string to extract the path from. * @returns The website path component. */ export declare function websitePathFromWebsiteDomainAndPath(input: WebsiteDomainAndPath): WebsitePath; /** * A pair containing the domain and path components of a website URL. */ export interface WebsiteDomainAndPathPair { /** * The domain portion of the URL. */ domain: WebsiteDomain; /** * The path portion of the URL. */ path: WebsitePath; } /** * Splits a domain-and-path string into its domain and path components at the first slash. * * @param input - The domain-and-path string to split. * @returns A pair containing the domain and path. */ export declare function websiteDomainAndPathPair(input: WebsiteDomainAndPath): WebsiteDomainAndPathPair; /** * A URI scheme, without the trailing colon. * * Examples: * - https * - mailto * - tel * * @semanticType * @semanticTopic url * @semanticTopic string */ export type UriScheme = string; /** * Regex that captures the scheme prefix of any URI, per RFC 3986 3.1. * * Unlike {@link WEB_PROTOCOL_PREFIX_REGEX} this does not require the `//` authority separator, so it also matches * schemes that address no authority, such as `mailto:` and `tel:`. */ export declare const URI_SCHEME_REGEX: RegExp; /** * Returns true if the input carries a URI scheme prefix. * * Examples where it will return true: * - mailto:hello@dereekb.com * - tel:+15550100 * - https://dereekb.com * * @param input - The string to check. * @returns Whether the input starts with a URI scheme. * * @dbxUtil * @dbxUtilCategory string * @dbxUtilTags string, url, uri, scheme, protocol, predicate * @dbxUtilRelated read-uri-scheme, read-website-protocol */ export declare function hasUriScheme(input: string): boolean; /** * Reads the URI scheme from the input string, if one exists. Does not include the trailing colon. * * @param input - The URI string to extract the scheme from. * @returns The scheme (e.g. `"mailto"`), or `undefined` if the input carries no scheme. * * @dbxUtil * @dbxUtilCategory string * @dbxUtilTags string, url, uri, scheme, protocol, read * @dbxUtilRelated has-uri-scheme, read-website-protocol */ export declare function readUriScheme(input: string): Maybe; /** * URI schemes that can run script or expose local/browser content when opened: `javascript`, `vbscript`, `data`, `blob`, `file`, and `about`. * * These are never treated as custom-scheme URIs by {@link isCustomSchemeUri}. */ export declare const UNSAFE_URI_SCHEMES: ReadonlySet; /** * Regex that matches a URI whose scheme is followed by a path (`scheme:/...` or `scheme://...`) and captures the scheme. Whitespace is not allowed. */ export declare const CUSTOM_SCHEME_URI_REGEX: RegExp; /** * Returns true if the input is a custom-scheme URI, such as the link or OAuth callback URI of a native app. * * Examples where it will return true: * - cursor://anysphere.cursor-mcp/oauth/callback * - com.example.app:/oauth2redirect * * Non-examples: * - https://dereekb.com // http/https * - mailto:hello@dereekb.com // no path after the scheme * - localhost:8080/callback // host:port, not a scheme * - javascript://alert(1) // one of the UNSAFE_URI_SCHEMES * * @param input - The string to check. * @returns Whether the input is a custom-scheme URI. * * @dbxUtil * @dbxUtilCategory string * @dbxUtilTags string, url, uri, scheme, protocol, custom, app, native, deep link, redirect, predicate * @dbxUtilRelated has-uri-scheme, read-uri-scheme */ export declare function isCustomSchemeUri(input: string): boolean; /** * Regex that matches `http://` or `https://` at the start of a string. */ export declare const HTTP_OR_HTTPS_REGEX: RegExp; /** * Regex that captures any protocol prefix (e.g., `http`, `https`, `ftp`) before `://`. * * The scheme is matched with the RFC 3986 character set rather than a greedy `.+`, so a `://` appearing later in * the path cannot be swallowed into the protocol. */ export declare const WEB_PROTOCOL_PREFIX_REGEX: RegExp; /** * Reads the website protocol from the input string, if it exists. * Does not include the `://` separator. * * @param input - The URL string to extract the protocol from. * @returns The protocol string (e.g., `"https"`), or `undefined` if no protocol is present. */ export declare function readWebsiteProtocol(input: string): Maybe; /** * Replaces the existing protocol prefix with the specified one, or removes it if no protocol is provided. * * @param input - The URL string to modify. * @param protocol - The protocol to set (e.g., `"https"`), or `undefined`/`null` to remove the protocol. * @returns The URL with the updated protocol prefix. */ export declare function setWebProtocolPrefix(input: string, protocol?: Maybe): string; /** * Removes any protocol prefix (e.g., `http://`, `https://`, `ftp://`) from the input string. * * @param input - The URL string to strip the protocol from. * @returns The URL without the protocol prefix. */ export declare function removeWebProtocolPrefix(input: string): string; /** * Adds an HTTP or HTTPS protocol prefix to the URL, replacing any existing protocol. * * @param url - The URL or domain string to add the prefix to. * @param prefix - The HTTP protocol to use. Defaults to `"https"`. * @returns The URL with the specified HTTP protocol prefix. */ export declare function addHttpToUrl(url: BaseWebsiteUrl | WebsiteDomainAndPath | string, prefix?: KnownHttpWebsiteProtocol): BaseWebsiteUrl; /** * Removes `http://` or `https://` from the URL. Other protocols are not affected. * * @param url - The URL to strip the HTTP prefix from. * @returns The URL without the HTTP/HTTPS prefix. */ export declare function removeHttpFromUrl(url: BaseWebsiteUrl | string): WebsiteDomainAndPath; /** * Returns true if the input string starts with `http://` or `https://`. * * @param input - The string to check. * @returns Whether the input has an HTTP/HTTPS prefix. */ export declare function hasHttpPrefix(input: string): input is BaseWebsiteUrl; /** * Configuration for {@link websiteUrlRelativePathFunctions}. */ export interface WebsiteUrlRelativePathFunctionsConfig { /** * The base url that relative paths are relative to. * * A trailing slash is added if it is missing. * * Example: `https://linkedin.com/in/` */ readonly baseUrl: WebsiteUrlWithPrefix; /** * Whether or not an input with an `http://` prefix keeps the `http` protocol. * * When false, inputs with an `http://` prefix use the base url's protocol instead. Inputs with an `https://` prefix always keep the `https` protocol. * * Defaults to false. */ readonly allowHttp?: Maybe; } /** * The result of reading a relative path from an input using {@link WebsiteUrlRelativePathFunctions}. */ export interface WebsiteUrlRelativePathReading { /** * The relative path, without any query parameters, leading slash, or trailing slash. * * Is an empty string if the input only contained the base url, or only the start of the base url with a protocol (e.g. `https://`). */ readonly relativePath: string; /** * The protocol to use for the full url, if the input had a protocol. * * Is the input's protocol when it is allowed, otherwise it is the base url's protocol. Is undefined if the input had no protocol. */ readonly protocol?: Maybe; /** * Whether or not the input included the base url's domain, as opposed to only the relative path. */ readonly hadBaseUrl: boolean; } /** * Functions for converting between a website url that starts with a base url and the relative path that follows the base url. * * Created by {@link websiteUrlRelativePathFunctions}. */ export interface WebsiteUrlRelativePathFunctions { /** * The normalized base url. Always ends with a slash. */ readonly baseUrl: WebsiteUrlWithPrefix; /** * Reads the relative path from the input, which may be a relative path, a url without a protocol, or a full url. * * An input that is only the start of the base url with a protocol (e.g. `https://` or `https://www.linked`) reads as an empty relative path. * * Returns undefined if the input is a url that does not start with the base url. */ readonly readRelativePath: (input: string) => Maybe; /** * Returns true if the input is the start of the base url, up to and including the whole base url, with or without a protocol. * * Examples for the base url `https://linkedin.com/in/`: `http:`, `https://`, `https://www.linked`, `linkedin.com/i`, `linkedin.com/in/` */ readonly isPartialBaseUrl: (input: string) => boolean; /** * Returns the base url using the input protocol if it is allowed, otherwise the base url's protocol. */ readonly toBaseUrl: (protocol?: Maybe) => WebsiteUrlWithPrefix; /** * Converts the input relative path or url to a full website url. * * Returns undefined if the input is a url that does not start with the base url, or if the relative path is empty. */ readonly toWebsiteUrl: (input: string) => Maybe; /** * Converts the input relative path or url to the relative path. * * Returns undefined if the input is a url that does not start with the base url. */ readonly toRelativePath: (input: string) => Maybe; } /** * Creates {@link WebsiteUrlRelativePathFunctions} for the configured base url. * * Inputs may be the relative path (`dereekb`), a url without a protocol (`linkedin.com/in/dereekb`), or a full url (`https://www.linkedin.com/in/dereekb/?trk=abc`). * Domains are compared case-insensitively and a leading `www.` is ignored. Query parameters and trailing slashes are removed from the relative path. * * @param config - The base url and protocol configuration. * @returns Functions for reading relative paths and building full website urls. * * @dbxUtil * @dbxUtilCategory string * @dbxUtilKind factory * @dbxUtilTags string, url, path, relative, base, slug, username, profile, factory * @dbxUtilRelated isolate-website-path-function, website-url-details * * @example * ```ts * const linkedIn = websiteUrlRelativePathFunctions({ baseUrl: 'https://linkedin.com/in/' }); * * linkedIn.toRelativePath('linkedin.com/in/dereekb'); // 'dereekb' * linkedIn.toWebsiteUrl('dereekb'); // 'https://linkedin.com/in/dereekb' * linkedIn.toWebsiteUrl('https://twitter.com/dereekb'); // undefined * ``` * * @__NO_SIDE_EFFECTS__ */ export declare function websiteUrlRelativePathFunctions(config: WebsiteUrlRelativePathFunctionsConfig): WebsiteUrlRelativePathFunctions; /** * Object representation of a `mailto:` URL. */ export interface MailToUrl { /** * The email address for the mailto link. */ email: string; } /** * Input for creating a mailto URL string. Can be an email address string or a {@link MailToUrl} object. */ export type MailToUrlInput = EmailAddress | MailToUrl; /** * Creates a `mailto:` URL string from the input email address or object. * * @param input - An email address or MailToUrl object. * @returns A `mailto:` URL string. */ export declare function mailToUrlString(input: MailToUrlInput): string; /** * Creates a `tel:` URL string from a phone number, handling E.164 format and extensions. * * @param phone - The phone number to create a tel URL for. * @returns A `tel:` URL string, with extension appended if present. */ export declare function telUrlString(phone: PhoneNumber | E164PhoneNumberWithOptionalExtension): string; /** * Creates a `tel:` URL string for an E.164 phone number with an optional extension. * * @param pair - The phone number and extension pair. * @returns A `tel:` URL string with the extension appended using `;` if present. */ export declare function telUrlStringForE164PhoneNumberPair(pair: E164PhoneNumberExtensionPair): string;