or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.mdpath-manipulation.mdpath-parsing.mdpath-resolution.mdplatform-operations.md
tile.json

tessl/npm-path

Node.js path module providing utilities for working with file and directory paths in a cross-platform manner

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/path@0.12.x

To install, run

npx @tessl/cli install tessl/npm-path@0.12.0

index.mddocs/

Path

Path is an exact copy of Node.js's built-in path module published as a standalone npm package. It provides comprehensive utilities for working with file and directory paths in a cross-platform manner, handling platform-specific differences between Windows and POSIX systems including path separators, drive letters, and UNC paths.

Package Information

  • Package Name: path
  • Package Type: npm
  • Language: JavaScript
  • Installation: npm install path

Core Imports

const path = require("path");

ES6 imports:

import * as path from "path";

Individual function imports:

const { resolve, join, dirname, basename, extname } = require("path");

TypeScript imports (when using @types/node):

import * as path from "path";
import { resolve, join, dirname, basename, extname } from "path";

Basic Usage

const path = require("path");

// Join paths
const fullPath = path.join("/users", "john", "documents", "file.txt");
// Result: "/users/john/documents/file.txt" (on POSIX)
// Result: "\\users\\john\\documents\\file.txt" (on Windows)

// Resolve absolute path
const absolutePath = path.resolve("../docs", "readme.md");
// Result: absolute path based on current working directory

// Extract path components
const filePath = "/home/user/project/index.js";
console.log(path.dirname(filePath));  // "/home/user/project"
console.log(path.basename(filePath)); // "index.js"
console.log(path.extname(filePath));  // ".js"

// Parse path into components
const parsed = path.parse(filePath);
// Result: { root: "/", dir: "/home/user/project", base: "index.js", ext: ".js", name: "index" }

Architecture

The path module provides platform-aware path utilities through a conditional export system:

  • Platform Detection: Automatically exports Windows or POSIX implementation based on process.platform
  • Cross-Platform Access: Both path.win32 and path.posix are always available regardless of platform
  • String Manipulation: Pure string operations with no filesystem access
  • Consistent API: Identical function signatures across both Windows and POSIX implementations

Capabilities

Path Resolution

Core path resolution functionality for converting relative paths to absolute paths and normalizing path structures.

function resolve(...paths: string[]): string;
function normalize(path: string): string;
function isAbsolute(path: string): boolean;

Path Resolution

Path Manipulation

Essential path manipulation operations for joining paths and computing relative paths between locations.

function join(...paths: string[]): string;
function relative(from: string, to: string): string;

Path Manipulation

Path Parsing

Path parsing utilities for extracting components from file paths and reconstructing paths from components.

function dirname(path: string): string;
function basename(path: string, ext?: string): string;
function extname(path: string): string;
function parse(pathString: string): ParsedPath;
function format(pathObject: PathObject): string;

Path Parsing

Platform-Specific Operations

Platform-specific path operations and constants for Windows and POSIX systems.

function _makeLong(path: string): string;
const sep: string;
const delimiter: string;

Platform Operations

Cross-Platform Usage

// Access platform-specific implementations
const posix: typeof path;
const win32: typeof path;

Access both Windows and POSIX implementations regardless of current platform:

const path = require("path");

// Force POSIX behavior on any platform
const posixPath = path.posix.join("/usr", "local", "bin");
// Always results in: "/usr/local/bin"

// Force Windows behavior on any platform  
const windowsPath = path.win32.join("C:", "Users", "John");
// Always results in: "C:\\Users\\John"

Types

interface ParsedPath {
  /** Root portion of path (e.g., '/', 'C:\\') */
  root: string;
  /** Directory portion of path */
  dir: string;
  /** File name including extension */
  base: string;
  /** File extension including leading dot */
  ext: string;
  /** File name without extension */
  name: string;
}

interface PathObject {
  /** Root portion of path */
  root?: string;
  /** Directory portion of path */
  dir?: string;
  /** File name including extension */
  base?: string;
}