Skip to content

Function: urlBuilder()

urlBuilder(): UrlBuilderImpl

With no argument, resolves to the base origin (never null).

UrlBuilderImpl

urlBuilder(input?): UrlBuilderImpl | undefined

Coerce a UrlLike into a chainable UrlBuilder, or null when the input cannot be parsed into a URL. Never throws.

  • A URL instance or { url } wrapper is adopted as-is.
  • A bare hostname ("example.com") is upgraded to https://; an explicit scheme is preserved.
  • A path / query / hash fragment ("/api", "?q=1", "#x") is resolved against defaultUrl (the browser origin, else http://localhost).
  • An empty / blank string or omitted input resolves to the base origin.

UrlLike

UrlBuilderImpl | undefined

urlBuilder("example.com"); // https://example.com/
urlBuilder("http://x/path"); // http://x/path
urlBuilder("/api/v2"); // http://localhost/api/v2
urlBuilder({ url: "http://y" }); // http://y/
urlBuilder(); // http://localhost/