isAbsolutePath()function
Is a string path an absolute path?
isAbsolutePath(path: PossiblePath): path is AbsolutePath
Typed helpers for working with filesystem and URL paths. Used throughout the router to represent and manipulate AbsolutePath values — strings that always start with /.
Things to know:
AbsolutePath is a template-literal type (/${string}). TypeScript enforces it at compile time.//, convert \ Windows separators, and strip trailing slashes.getPath() returns undefined on invalid input; requirePath() throws RequiredError instead.splitPath("/") returns [] — the root has no segments.import { isAbsolutePath, isRelativePath, getPath, requirePath } from "shelving/util";
isAbsolutePath("/foo/bar"); // true
isAbsolutePath("./foo"); // false
isRelativePath("./foo"); // true
getPath("/a//b/./c/"); // "/a/b/c"
getPath("./child", "/parent"); // "/parent/child"
getPath(null); // undefined
requirePath("not-a-path"); // throws RequiredErrorimport { joinPath, splitPath, cleanPath } from "shelving/util";
joinPath("/foo", "bar", "baz"); // "/foo/bar/baz"
joinPath("/foo", ["bar", "baz"]); // "/foo/bar/baz"
joinPath("/a//", "/b/"); // "/a/b"
splitPath("/foo/bar/baz"); // ["foo", "bar", "baz"]
splitPath("/"); // []
cleanPath("/a//./b/"); // "/a/b"import { matchPathPrefix, isPathActive, isPathProud } from "shelving/util";
matchPathPrefix("/app/settings/profile", "/app"); // "/settings/profile"
matchPathPrefix("/app", "/app"); // "/"
matchPathPrefix("/other", "/app"); // undefined
isPathActive("/app", "/app"); // true (exact match)
isPathProud("/app/sub", "/app"); // true (current is ancestor)
isPathProud("/app", "/app/sub"); // falseIs a string path an absolute path?
isAbsolutePath(path: PossiblePath): path is AbsolutePath
Is a string path a relative path?
isRelativePath(path: PossiblePath): path is RelativePath
Resolve a relative or absolute path and return the absolute path, or undefined if not a valid path.
getPath(inputPath: Nullish<PossiblePath>, inputBase: AbsolutePath = "/"): AbsolutePath | undefined
Normalise a path.
cleanPath(path: AbsolutePath): AbsolutePath
cleanPath(path: string): string
Resolve a relative or absolute path and return the path, or throw RequiredError if not a valid path.
requirePath(path: PossiblePath, base?: AbsolutePath, caller: AnyCaller = requirePath): AbsolutePath
Match and strip a base path prefix from a path using segment-aware pathname rules.
matchPathPrefix(target: PossiblePath, base: PossiblePath, caller: AnyCaller = matchPathPrefix): AbsolutePath | undefined
Is a target path active relative to the current path?
isPathActive(target: AbsolutePath, current: AbsolutePath): boolean
Is a target path proud relative to the current path?
isPathProud(target: AbsolutePath, current: AbsolutePath): boolean
Get the "segments" in an absolute path.
splitPath(path: PossiblePath): readonly string[]
Join one or more path parts into a single path string.
joinPath(first: AbsolutePath, ...rest: PathPart[]): AbsolutePath
joinPath(...parts: PathPart[]): string
Absolute path string starting with a / slash.
`/` | `/${string}`Relative path string that is . dot, or starts with ./ dot slash.
`.` | `./` | `./${string}`Either an absolute or relative path.
AbsolutePath | RelativePath
Things that can be converted to a path.
string | readonly string[]
A single argument accepted by joinPath() — either a string (full path or single segment) or an array of segments.
string | readonly string[]