@untools/ip-url
Version:
Get local IP address and format URLs with it
22 lines (21 loc) • 1.1 kB
TypeScript
/**
* Gets the local IP address(es) of the machine.
* @param family - The IP version family to use (IPv4 or IPv6). Default is 'IPv4'.
* @param skipInternal - Whether to skip internal interfaces (like loopback). Default is true.
* @returns An array of IP addresses.
*/
export declare function getLocalIPs(family?: "IPv4" | "IPv6", skipInternal?: boolean): string[];
/**
* Gets the primary local IP address.
* @param family - The IP version family to use (IPv4 or IPv6). Default is 'IPv4'.
* @returns The primary IP address or undefined if not found.
*/
export declare function getPrimaryIP(family?: "IPv4" | "IPv6"): string | undefined;
/**
* Formats a URL with the IP address instead of localhost.
* @param port - The port number to use.
* @param protocol - The protocol to use (http or https). Default is 'http'.
* @param family - The IP version family to use (IPv4 or IPv6). Default is 'IPv4'.
* @returns The formatted URL or undefined if IP not found.
*/
export declare function formatIPUrl(port: number, protocol?: "http" | "https", family?: "IPv4" | "IPv6"): string | undefined;