Bare Path Manipulation

3.0.0 · active · verified Sun Apr 19

bare-path is a JavaScript library designed for cross-platform path manipulation, focusing on string-based operations rather than interacting with the underlying file system. It provides utilities for joining, normalizing, resolving, and dissecting file paths, similar to Node.js's built-in `path` module. The current stable version is 3.0.0. Its primary differentiator is its minimalist approach and explicit separation of POSIX and Windows path logic via subpath exports, making it highly portable and suitable for environments where `node:path` might not be available or desired due to its implicit OS-specific behavior. It maintains a steady release cadence for core utility packages, prioritizing stability and broad compatibility.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates basic path manipulation functions like joining, normalizing, and extracting parts of a path using `bare-path`.

import path from 'bare-path';

// Join path segments, handling separators automatically
const fullPath = path.join('users', 'admin', 'documents', 'report.txt');
console.log(`Joined path: ${fullPath}`); // Expected: users/admin/documents/report.txt (on POSIX)

// Normalize a path, resolving '..' and '.' segments
const normalizedPath = path.normalize('/foo/bar//../baz/.');
console.log(`Normalized path: ${normalizedPath}`); // Expected: /foo/baz

// Get the directory name of a path
const dirname = path.dirname('/home/user/file.js');
console.log(`Directory name: ${dirname}`); // Expected: /home/user

// Get the base name of a path (filename)
const basename = path.basename('/home/user/file.js');
console.log(`Base name: ${basename}`); // Expected: file.js

// Get the base name without extension
const basenameNoExt = path.basename('/home/user/file.js', '.js');
console.log(`Base name without extension: ${basenameNoExt}`); // Expected: file

// Get the extension of a path
const extname = path.extname('/home/user/archive.tar.gz');
console.log(`Extension name: ${extname}`); // Expected: .gz

view raw JSON →