Overview
The URL Builder provides a fluent, chainable API for constructing URLs with path segments, query parameters, and hash fragments. It simplifies URL construction and handles proper encoding automatically.Class: UrlBuilder
Constructor
Create a new URL builder instance.baseUrl- The base URL to build upon
Methods
path
Add path segments to the URL. Automatically handles leading and trailing slashes.segments- Path segments to append
query
Add query parameters to the URL. Automatically filters outundefined and null values.
params- Object containing query parameters
queryArray
Add array query parameters. Each array element becomes a separate parameter with the same name.params- Object containing array-valued query parameters
hash
Set the URL fragment (hash).fragment- The hash fragment (without the ’#’ prefix)
build
Build the final URL as a string.toURL
Get the URL as a native URL object.getPathname
Get only the pathname portion of the URL.getSearch
Get only the search/query string portion of the URL (including the ’?’ prefix).getHash
Get only the hash/fragment portion of the URL (including the ’#’ prefix).clone
Create a copy of the builder with the same configuration.Helper Function: createUrlBuilder
Convenience function to create a new URL builder.baseUrl- The base URL to build upon