Function canonicalUrl

  • Creates a canonical URL by combining a base URL and an optional pathname.

    Example

    const url = 'https://example.com';
    const path = '/welcome';
    canonicalUrl(url, path)
    // => { ok: true, value: 'https://example.com/welcome' }

    Example

    Handle an invalid input:

    canonicalUrl("/welcome")
    // => { ok: false, error: Error('[urls.canonicalUrl] Expected a valid URL') }

    Parameters

    • baseURL: string

      The base URL to be used for creating the canonical URL.

    • pathname: string = ''

      An optional pathname to be appended to the base URL. Defaults to an empty string.

    Returns Result<URL, Error>

    A Result object containing a URL instance if the URL is valid, or an Error object if the base URL is not valid.

Generated using TypeDoc v0.24.7