Options
All
  • Public
  • Public/Protected
  • All
Menu

Various utility methods for URLs.

Index

Functions

cloneUrl

  • cloneUrl(url: URL): URL
  • Clone an existing URL object.

    Parameters

    • url: URL

    Returns URL

getOrigin

  • getOrigin(url: URL): string
  • Get the URLs origin including scheme, host, and possibly username, password and port if available. In contrast to the default URL.origin property, this method returns the origin for custom schemes, for example 'com.colibrio://'.

    Parameters

    • url: URL

      The URL to get the origin for.

    Returns string

getOriginAndPath

  • getOriginAndPath(url: URL): string
  • Get the origin + path of the given URL. That is, the full url minus the 'query' and 'hash' parts.

    Parameters

    • url: URL

    Returns string

getSubpath

  • getSubpath(url: URL, baseUrl: URL): string | undefined
  • Get the relative path to url from baseUrl, only if url is a subpath to baseUrl.

    Example:

    const url = new URL('http://a.com/basePath/images/cover.jpg');
    const baseUrl = new URL('http://a.com/basePath/');
    const subpath = URLUtils.getSubpath(url, baseUrl);

    // subpath is: 'images/cover.jpg'

    Parameters

    • url: URL
    • baseUrl: URL

    Returns string | undefined

getUrlWithoutHash

  • getUrlWithoutHash(url: URL): string
  • Get the URL as a string but without the 'hash' part if any.

    Parameters

    • url: URL

    Returns string

isSubpath

  • isSubpath(url: URL, baseUrl: URL): boolean
  • Compares two URLs and returns true if they have a common scheme, host, port and that the url's path starts with the path specified in the baseUrl.

    It does not consider username/password, query or fragment.

    Parameters

    • url: URL
    • baseUrl: URL

    Returns boolean

isValidUrl

  • isValidUrl(url: string): boolean
  • Checks if the string can be parsed as an URL.

    Parameters

    • url: string

    Returns boolean

normalizePathnameEncoding

  • normalizePathnameEncoding(url: URL): URL
  • Returns a new URL where the percent encoding of URL.pathname has been normalized. In contrast to decodeURIComponent, this method does not throw an error if an invalid percent encoding is found.

    Parameters

    • url: URL

    Returns URL

normalizePathnamePercentEncoding

  • normalizePathnamePercentEncoding(url: URL): void
  • Normalize percent encoding for the URL.pathname. In contrast to decodeURIComponent, this method does not throw an error if an invalid percent encoding is found.

    deprecated
    • Will be removed in 4.0.0. Please use normalizePathnameEncoding instead.

    Parameters

    • url: URL

    Returns void

Generated using TypeDoc