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: ReadonlyObjectDeep<PartialWithUndefined<{
          hash?: string;
          hostname?: string;
          password?: string;
          pathname?: string;
          paths?: string[];
          port?: string | number;
          protocol?: string;
          search?: string | SearchParamsInput;
          username?: string;
      }>>
    • Optionaloptions: Readonly<PartialWithUndefined<{
          encoding: UrlEncoding;
          searchParamStrategy: SearchParamStrategy;
      }>>

    Returns UrlParts

    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
    • override: ReadonlyObjectDeep<PartialWithUndefined<{
          hash?: string;
          hostname?: string;
          password?: string;
          pathname?: string;
          paths?: string[];
          port?: string | number;
          protocol?: string;
          search?: string | SearchParamsInput;
          username?: string;
      }>>
    • Optionaloptions: ReadonlyObjectDeep<PartialWithUndefined<{
          encoding: UrlEncoding;
          searchParamStrategy: SearchParamStrategy;
      }>>

    Returns UrlParts

    import {buildUrl} from 'url-vir';

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

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