url-vir - v2.1.6
    Preparing search index...

    Function parseUrl

    • Converts a string or URL instance into UrlParts.

      • Partial URLs are valid. Whatever you don't provide will be empty in the returned object.
      • Encoding options are only applied to pathname, search, and hash url parts.

      Parameters

      • url: string | URL
      • Optionaloptions: Readonly<
            Pick<
                {
                    encoding?: Encode
                    | Decode
                    | None;
                    searchParamStrategy?: Clear | Replace | Append;
                },
                "encoding",
            >,
        >

      Returns {
          fullPath: string;
          hash: string;
          host: string;
          hostname: string;
          href: string;
          origin: string;
          password: string;
          pathname: string;
          paths: string[];
          port: string;
          protocol: string;
          search: string;
          searchParams: Record<string, string[]>;
          username: string;
      }

      • fullPath: string

        Includes:

        • Pathname
        • Search
        • Hash
      • hash: string

        Everything after the hash (#), including the hash itself. If none exist, this will be an empty string.

        '#/my/hash/route'
        
      • host: string

        Includes:

        • Hostname
        • Port
      • hostname: string

        Domain, subdomains, and TLD (.com).

      • href: string

        The full url string.

      • origin: string

        Includes:

        • Protocol
        • Hostname
        • Port
      • password: string

        Infrequently used password part of a url.

        BuildUrl('https://anonymous:my-pass@developer.mozilla.org').password === 'my-pass';
        
      • pathname: string

        Everything between origin and search/hash with a leading slash. If none exist, this will be simply '/'.

      • paths: string[]

        Each path part of the pathname.

      • port: string

        Port part of the URL. If none exist, this will be an empty string.

      • protocol: string

        Http, https, wss, etc.

      • search: string

        Everything after a ?, excluding the hash, including ?, as a string. If none exist, this will be an empty string.

      • searchParams: Record<string, string[]>

        An object representation of the parameters contained within the search string. If none exist, it will be an empty object.

      • username: string

        Infrequently used username part of a url.

        BuildUrl('https://anonymous:my-pass@developer.mozilla.org').username ===
        'anonymous';
      import {parseUrl} from 'url-vir';

      let result = parseUrl('https://example.com:123/hello/there');

      // output
      result = {
      protocol: 'https',
      username: '',
      password: '',
      host: 'example.com:123',
      hostname: 'example.com',
      port: '123',
      origin: 'https://example.com:123',
      pathname: '/hello/there',
      paths: [
      'hello',
      'there',
      ],
      search: '',
      searchParams: {},
      hash: '',
      fullPath: '/hello/there',
      href: 'https://example.com:123/hello/there',
      };