close
Skip to main content
This release is versions behind 1.1.5 — the latest version of @std/path.
Works with
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 Score100%
Downloads84,618/wk
Published3 years ago (0.210.0)

Utilities for working with file system paths

Utilities for working with OS-specific file paths.

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 { posix, win32 } from "@std/path";
const p1 = posix.fromFileUrl("file:///home/foo");
const p2 = win32.fromFileUrl("file:///home/foo");
console.log(p1); // "/home/foo"
console.log(p2); // "\\home\\foo"

This module is browser compatible.

Functions

f
basename(
path: string,
suffix?
): string

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

f
common(
paths: string[],
sep?: SEP
): string

Determines the common path from a set of paths, using an optional separator, which defaults to the OS default separator.

f
dirname(path: string): string

Return the directory path of a path.

f
extname(path: string): string

Return the extension of the path with leading period.

f
format(pathObject: FormatInputPathObject): string

Generate a path from FormatInputPathObject object.

f
fromFileUrl(url: URL | string): string

Converts a file URL to a path string.

f
globToRegExp(
glob: string,
options?: GlobToRegExpOptions
): RegExp

Convert a glob string to a regular expression.

f
isAbsolute(path: string): boolean

Verifies whether provided path is absolute

f
isGlob(str: string): boolean

Test whether the given string is a glob

f
join(...paths: string[]): string

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

f
joinGlobs(
globs: string[],
unnamed 1?: GlobOptions
): string

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

f
normalize(path: string): string

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(
glob: string,
unnamed 1?: GlobOptions
): string

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

f
parse(path: string): ParsedPath

Return a ParsedPath object of the path.

f
relative(
from: string,
to: string
): string

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

f
resolve(...pathSegments: string[]): string

Resolves path segments into a path

f
toFileUrl(path: string): URL

Converts a path string to a file URL.

f
toNamespacedPath(path: string): string

Resolves path to a namespace path

Interfaces

I

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

  • base: string

    The file name including extension (if any) such as 'index.html'

  • dir: string

    The full directory path such as '/home/user/dir' or 'c:\path\dir'

  • ext: string

    The file extension (if any) such as '.html'

  • name: string

    The file name without extension (if any) such as 'index'

  • root: string

    The root of the path such as '/' or 'c:'

Type Aliases

T
FormatInputPathObject = Partial<ParsedPath>
No documentation available

Variables

v
No documentation available
v
SEP: "\\"
No documentation available
v
sep: "\\"

Utilities for working with OS-specific file paths.

v
SEP_PATTERN: RegExp
No documentation available

Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@std/path

Import symbol

import * as mod from "@std/path/windows";
or

Import directly with a jsr specifier

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