Browser-safe path utilities with no runtime-native dependencies.
Installation#
bash
npm install @rcompat/pathbash
pnpm add @rcompat/pathbash
yarn add @rcompat/pathbash
bun add @rcompat/pathUsage#
js
import path from "@rcompat/path";
path.posix.normalize("a//b/../c/"); // "a/c/"
path.posix.isAbsolute("/app/routes"); // true
path.relative("C:\\app\\routes", "C:\\app\\assets\\logo.svg");
// "../assets/logo.svg"relative accepts POSIX and Windows paths and always returns / separators.
When the inputs use unrelated roots—such as mixed absolute and relative paths,
different Windows drives, or different UNC shares—it returns the normalized
target rather than manufacturing a relative path between them.