@ende/path/posix

ende add jsr:@ende/path

Version 2026.10.15 on JSR.

Utilities for working with POSIX-formatted paths.

This module also provides some functions that help when working with URLs. See the documentation for examples.

Codes in the examples uses POSIX path but it automatically use Windows path on Windows. Use methods under posix or win32 object instead to handle non platform specific path like:

import { fromFileUrl } from "@ende/path/posix/from-file-url";
import { assertEquals } from "@ende/assert";

assertEquals(fromFileUrl("file:///home/foo"), "/home/foo");

Exports

  • basename — Return the last portion of a `path`. Trailing directory separators are ignored, and optional suffix is removed.
  • common — Determines the common path from a set of paths for POSIX systems.
  • DELIMITER — The character used to separate entries in the PATH environment variable.
  • dirname — Return the directory path of a `path`.
  • extname — Return the extension of the `path` with leading period.
  • format — Generate a path from `ParsedPath` object.
  • fromFileUrl — Converts a file URL to a path string.
  • GlobOptions — Options for globToRegExp, joinGlobs, normalizeGlob and expandGlob.
  • globToRegExp — Convert a glob string to a regular expression.
  • isAbsolute — Verifies whether provided path is absolute.
  • isGlob — Test whether the given string is a glob.
  • join — Join all given a sequence of `paths`,then normalizes the resulting path.
  • joinGlobs — Like join(), but doesn't collapse "**\/.." when `globstar` is true.
  • normalize — Normalize the `path`, resolving `'..'` and `'.'` segments. Note that resolving these segments does not necessarily mean that all will be eliminated. A `'..'` at the top-level will be preserved, and an empty path is canonically `'.'`.
  • normalizeGlob — Like normalize(), but doesn't collapse "**\/.." when `globstar` is true.
  • parse — Return a `ParsedPath` object of the `path`.
  • ParsedPath — A parsed path object generated by path.parse() or consumed by path.format().
  • relative — Return the relative path from `from` to `to` based on current working directory.
  • resolve — Resolves path segments into a `path`.
  • SEPARATOR — The character used to separate components of a file path.
  • SEPARATOR_PATTERN — A regular expression that matches one or more path separators.
  • toFileUrl — Converts a path string to a file URL.
  • toNamespacedPath — Converts a path to a namespaced path. This function returns the path as is on posix.