CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-path

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

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

path-resolution.mddocs/

Path Resolution

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

Capabilities

Resolve

Resolves a sequence of paths or path segments into an absolute path. The path is built by processing each path segment from right to left, prepending each subsequent path until an absolute path is constructed.

/**
 * Resolves a sequence of paths to an absolute path
 * @param {...string} paths - Path segments to resolve (processed right to left)
 * @returns {string} Absolute path resolved from current working directory
 * @throws {TypeError} If any argument is not a string
 */
function resolve(...paths: string[]): string;

Usage Examples:

const path = require("path");

// Resolve from current working directory
path.resolve("docs", "readme.md");
// If cwd is /home/user: "/home/user/docs/readme.md"

// Resolve with absolute path segment
path.resolve("/users", "john", "../jane", "file.txt");
// Result: "/users/jane/file.txt"

// Multiple relative segments
path.resolve("..", "src", "index.js");
// Resolves relative to parent directory

// Empty path defaults to current directory
path.resolve("");
// Same as process.cwd()

Platform Differences:

// Windows
path.win32.resolve("C:", "temp", "file.txt");
// Result: "C:\\temp\\file.txt" 

// POSIX
path.posix.resolve("/usr", "local", "bin");
// Result: "/usr/local/bin"

Normalize

Normalizes a path by resolving .. and . segments. When multiple path separators are found, they are replaced with a single separator. Trailing separators are preserved.

/**
 * Normalizes a path by resolving . and .. segments
 * @param {string} path - Path to normalize
 * @returns {string} Normalized path
 */
function normalize(path: string): string;

Usage Examples:

const path = require("path");

// Remove redundant separators and resolve . and ..
path.normalize("/users//john/../jane/./docs");
// Result: "/users/jane/docs"

path.normalize("../docs/./readme.md");
// Result: "../docs/readme.md"

// Preserve trailing slash
path.normalize("/users/john/");
// Result: "/users/john/"

// Handle empty path
path.normalize("");
// Result: "."

Platform Differences:

// Windows normalization
path.win32.normalize("C:/users\\john/..\\jane");
// Result: "C:\\users\\jane"

// POSIX normalization  
path.posix.normalize("/users//john/../jane");
// Result: "/users/jane"

Is Absolute

Determines if a path is absolute. On POSIX systems, a path is absolute if it starts with /. On Windows, a path is absolute if it starts with a drive letter and colon, or a UNC path.

/**
 * Determines if a path is absolute
 * @param {string} path - Path to test
 * @returns {boolean} True if path is absolute
 */
function isAbsolute(path: string): boolean;

Usage Examples:

const path = require("path");

// POSIX absolute paths
path.posix.isAbsolute("/home/user");     // true
path.posix.isAbsolute("home/user");      // false
path.posix.isAbsolute("../docs");        // false

// Windows absolute paths
path.win32.isAbsolute("C:\\Users\\John"); // true
path.win32.isAbsolute("\\\\server\\share"); // true (UNC path)
path.win32.isAbsolute("Users\\John");      // false
path.win32.isAbsolute("C:file.txt");       // false (drive-relative)

Cross-Platform Testing:

// Test on current platform
path.isAbsolute("/usr/local");
// true on POSIX, false on Windows

path.isAbsolute("C:\\Windows");
// true on Windows, false on POSIX

// Force platform-specific behavior
path.posix.isAbsolute("C:\\Windows");  // false
path.win32.isAbsolute("/usr/local");   // false

Install with Tessl CLI

npx tessl i tessl/npm-path

docs

index.md

path-manipulation.md

path-parsing.md

path-resolution.md

platform-operations.md

tile.json