AbstractReturns the extension of the filename including the leading dot, as a string. If the filename has no extension, returns an empty string.
Note that if the filename starts with a dot (e.g. .gitignore),
that dot is considered part of the stem. So .gitignore has
extension '' and .gitignore.bak has extension .bak
If the pathname ends with a slash (i.e. this.isDirectory === true)
there is no filename, and so this.extension returns undefined
The filename component (last path segment) as a Filename.
If the pathname ends with a slash (i.e. this.isDirectory === true)
there is no filename, so this.filename returns undefined.
The fragment (hash) component of the URL, without the leading #.
Note a distinction between an empty fragment and no fragment:
'' - The URL has a hash, but with nothing after itundefined - The URL has no hash at allIn URL strings a trailing slash is significant -- it nominally
signifies a directory (e.g. http://example.com/foo/bar/) vs. a file
or resource.
And so if a URL path's instances .pathname ends with a slash,
it is considered a directory, and its .filename is
undefined. If it does not end with a slash, its final segment is
considered the filename, same as for plain paths.
A pathname consisting of a single dot (.) is also considered a
directory.
To remove the directory designation (i.e. remove the trailing slash) from a URL path, use unDirectory();
to create a directory designation (i.e. add a trailing slash, use join('/').
Returns true if this URL's .pathname ends with a slash
Returns a new URL instance for parent directory of this URL. The new
instance always has .isDirectory true, and keeps the same
query and hash as this.
Returns the pathname component of the URL as a string
The query parameters (search) component of the URL, as a key/value map.
Note the distinction between an empty query and no query:
{} - The URL has a ? but no parameters after itundefined - The URL has no ? at allThe segments of this path as an array of strings.
If the pathname ends with a slash (i.e. this.isDirectory === true)
there is no filename, the last segment in the array will be the last
directory name.
Returns the stem of the filename, i.e. the part before the extension. If the filename has no extension, returns the entire filename
Note that if the filename starts with a dot (e.g. .gitignore),
that dot is considered part of the stem. So .gitignore and
.gitignore.bak both have stem .gitignore
If the pathname ends with a slash (i.e. this.isDirectory === true)
there is no filename, and so this.stem returns undefined
Join additional path segments to this URL's pathname.
Accepts relative path objects and Filename segment arguments for type safety, but you can also directly pass strings for convenience. All args are stringified and interpreted as segments to be joined, regardless of whether they start with a path separator or URL origin.
In addition to joining path segments, .join() also merges queries
and fragments from the given segments into the resulting URL: as the
args are processed, any query encountered will be merged into the
current query using the semantics of mergeQuery(), and any
fragment will replace the current fragment.
(It's not possible to remove an existing query parameter or the entire
query or an existing framgent using .join(), only to add/replace
them, although they can be replaced with '')
Any null, undefined, or empty segments are ignored.
A new instance with the segments appended and resulting pathname normalized, and queries and fragments merged.
Merges the given query parameters into the URL's existing query parameters, returning a new instance with the merged result.
The merge overwrite the values of the existing query for whichever
keys are given in the provided query. If there is no current query,
or if the current query is empty, this has the same effect as replaceQuery().
Returns a new instance with the fragment removed, i.e. the URL string
will have no # component.
Returns a new instance with the query parameters removed,
i.e. the URL string will have no ? component.
Replace the filename extension, keeping the stem the same. The passed string can include or omit the leading dot; if omitted, it will be added.
New extension, e.g. json or .json
A new instance with the filename extension replaced.
Replace the filename (last segment).
A new instance with the filename replaced.
Returns a new instance with the given fragment (hash) string, replacing the current fragment (if any).
For convenience, a single leading # in fragment will be stripped;
if you want a leading # to be part of the fragment, use ##
You can provide an empty string to create an empty fragment; to remove the fragment entirely, use removeFragment.
Returns a new instance with the given pathname replacing the current pathname; all other URL components remain the same.
Replace the filename stem, keeping the extension the same
A new instance with the filename stem replaced.
Returns the string representation of this URL.
Returns a new instance with the directory designation removed, i.e. the final slash (if any) is removed from the pathname.
Exception: For FullPathUrl and RootPathUrl, if the pathname is a
single slash (/), it is not removed, and the new instance will be
the same as the current instance (i.e. unDirectory is a no-op on a
root directory)
Base class for all URL-style path types. Provides query + fragment handling and immutable join/resolve utilities.