@lou.codes/test
Version:
✅ Equality test with enforced readability
18 lines (17 loc) • 537 B
JavaScript
import { cwd } from "node:process";
import { pathToFileURL } from "node:url";
/** Cached CWD URL's href. */
const { href: currentWorkingDirectory } = pathToFileURL(cwd());
/**
* Given a path, replace the CWD with a `"."` to make it relative.
*
* @category Output
* @example
* ```typescript
* // If CWD is `"/projects"`
* relativePath("/projects/tests/"); // "./tests/"
* ```
* @param path Path to make relative.
* @returns Relative path.
*/
export const relativePath = (url) => url.href.replace(currentWorkingDirectory, ".");