Skip to main content

Utilities for working with file system paths

This package works with Cloudflare Workers, Deno, Browsers
This package works with Cloudflare Workers
This package works with Deno
This package works with Browsers
JSR Score
94%
Published
5 months ago (1.0.8)

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 "@std/path/posix/from-file-url";
import { assertEquals } from "@std/assert";

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

Functions

f
basename

Return the last portion of a path. Trailing directory separators are ignored, and optional suffix is removed.

f
common

Determines the common path from a set of paths for POSIX systems.

f
dirname

Return the directory path of a path.

f
extname

Return the extension of the path with leading period.

f
format

Generate a path from ParsedPath object.

f
fromFileUrl

Converts a file URL to a path string.

f
globToRegExp

Convert a glob string to a regular expression.

f
isAbsolute

Verifies whether provided path is absolute.

f
isGlob

Test whether the given string is a glob.

f
join

Join all given a sequence of paths,then normalizes the resulting path.

f
joinGlobs

Like join(), but doesn't collapse "**/.." when globstar is true.

f
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 '.'.

f
normalizeGlob

Like normalize(), but doesn't collapse "**/.." when globstar is true.

f
parse

Return a ParsedPath object of the path.

f
relative

Return the relative path from from to to based on current working directory.

f
resolve

Resolves path segments into a path.

f
toFileUrl

Converts a path string to a file URL.

f
toNamespacedPath

Converts a path to a namespaced path. This function returns the path as is on posix.

Interfaces

I
ParsedPath

A parsed path object generated by path.parse() or consumed by path.format().

Variables

v
DELIMITER

The character used to separate entries in the PATH environment variable.

v
SEPARATOR

The character used to separate components of a file path.

v
SEPARATOR_PATTERN

A regular expression that matches one or more path separators.

Add Package

deno add jsr:@std/path

Import symbol

import * as mod from "@std/path/posix";

---- OR ----

Import directly with a jsr specifier

import * as mod from "jsr:@std/path/posix";