Returns 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
Test whether this path is a descendant of the given ancestor path.
An absolute path or string to check against.
Optionalopts: { includeSelf?: boolean }True if this path descends from the ancestor, otherwise false.
Returns true if this URL is equal to the given URL instance or URL string, where equality is defined as equality of their string representations.
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().
Compute the relative path from the given base path to this path.
The base absolute path.
A relative path that goes from base to this.
The returned RelativePathUrl has the same query and fragment as this
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.
Replace the entire directory path through the parent, while keeping the current filename.
Parent directory as string or another path
A new path rooted at newParent with the same filename.
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.
Similar to join(), but as the args are processed, if a root-relative (i.e.
absolute) pathname is encountered, the current pathname, query and fragment are
discarded and are replaced by those of that argument.
@see join
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)
A rooted URL instance, i.e. with a pathname that starts with '/', but without an origin.
Analogous to AbsolutePath, but for URLs; i.e. it may have query paramaters and a fragment, and has methods to work with them.
To convert to a full URL with an origin, see FullPathUrl#resolve
On construction, URL path classes normalize the path:
.and..components are resolved..isDirectory).When converting to a string, the result is encoded as needed: