Skip to main content

getUrlFromString

Callable

  • getUrlFromString(str: string): undefined | null | string

  • Converts a string to a URL and returns its string representation. If the string is not a valid URL, attempts to prepend "https://" before converting.

    @example
    getUrlFromString('example.com'); // 'https://example.com'
    getUrlFromString('https://example.com'); // 'https://example.com'
    getUrlFromString('not a url'); // null