Create a new AbsolutePath from a string or another AbsolutePath.
The path is normalized and guaranteed to be absolute. Any trailing separator is removed.
Throws an error if the provided path is not absolute.
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
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
Test whether this path is a descendant of the given ancestor path.
An AbsolutePath or string to check against.
Optionalopts: { includeSelf?: boolean }OptionalincludeSelf?: booleanIf true, return true when the paths are identical.
True if this path descends from the ancestor, otherwise false.
Returns true if this path equals the other path or path string.
Join additional path segments to this path.
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.
Any null, undefined, or empty segments are ignored.
A new instance with the segments appended and resulting path normalized.
Compute the relative path from the given base path to this path.
The base absolute path.
A RelativePath that goes from base to this.
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.
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.
Replace the filename stem, keeping the extension the same
A new instance with the filename stem replaced.
Resolve additional paths or components against this absolute path.
Similar to join(), except that if any argument is absolute, the current
path is discarded and resolution starts from that argument.
A new instance of this type, representing the resolved path.
Returns the string representation of this path.
Represents an absolute filesystem path (i.e. a path starting at the root, i.e. has a leading separator), and provides methods for path resolution, manipulation and queries. AbsolutePath instances are normalized and immutable.
AbsolutePath has the same functionality as RelativePath but with additional methods that are only valid for absolute paths:
resolve(),relativeTo(), anddescendsFrom().Note that AbsolutePath provides pure path manipulation, it does not access the filesystem in any way. (If you want to work with the filesystem, you can use the
@thingts/fs-pathlibrary which extends AbsolutePath with filestem operations.)Example