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

    Function buildUrl

    Builds a URL either from an object of URL parts or from overriding a base URL string.

    • Build a URL straight from overrides.

      Parameters

      • override:
            | string
            | ReadonlyObjectDeep<
                {
                    hash?: string;
                    hostname?: string;
                    password?: string;
                    pathname?: string;
                    paths?: string[];
                    port?: string
                    | number;
                    protocol?: string;
                    search?:
                        | string
                        | Record<
                            string,
                            | undefined
                            | null
                            | string
                            | number
                            | bigint
                            | boolean
                            | (undefined | null | string | number | bigint | boolean)[],
                        >;
                    username?: string;
                },
            >
            | URL
      • Optionaloptions: ReadonlyObjectDeep<
            {
                encoding?: Encode
                | Decode
                | None;
                searchParamStrategy?: Clear | Replace | Append;
            },
        >

      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 {buildUrl} from 'url-vir';

      buildUrl({
      hostname: 'example.com',
      search: {
      hello: 'there',
      },
      });

      buildUrl.href; // `'example.com/?hello=there'`
    • Build a URL by overriding an existing base URL string.

      Parameters

      • baseUrl:
            | string
            | URL
            | ReadonlyObjectDeep<
                {
                    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;
                },
            >
      • override:
            | string
            | ReadonlyObjectDeep<
                {
                    hash?: string;
                    hostname?: string;
                    password?: string;
                    pathname?: string;
                    paths?: string[];
                    port?: string
                    | number;
                    protocol?: string;
                    search?:
                        | string
                        | Record<
                            string,
                            | undefined
                            | null
                            | string
                            | number
                            | bigint
                            | boolean
                            | (undefined | null | string | number | bigint | boolean)[],
                        >;
                    username?: string;
                },
            >
            | URL
      • Optionaloptions: ReadonlyObjectDeep<
            {
                encoding?: Encode
                | Decode
                | None;
                searchParamStrategy?: Clear | Replace | Append;
            },
        >

      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 {buildUrl} from 'url-vir';

      buildUrl('github.com/?hello=there', {
      hostname: 'example.com',
      });

      buildUrl.href; // `'example.com/?hello=there'`