x-path - Node.js Path Module Extension

raw JSON →
0.0.2 verified Thu Apr 23 auth: no javascript abandoned

The `x-path` package extends Node.js's native `path` module, providing additional utilities for path manipulation and basic file system checks. It offers methods such as `isAbsolutePath`, `isRelativePath`, `isRootDirectory`, `unifyPathSeparate`, `normalizePathSeparate`, and functions to check if a path refers to a directory or file (`isDirectory`, `isFile`, `isDirectorySync`, `isFileSync`). It also includes functions for retrieving common system directories like `tempdir`, `homedir`, and `datadir`, which are sourced from the `path-extra` package. The current and only release is version 0.0.2, published in 2015. Given its age and complete lack of updates, the package is considered abandoned, with no active development or release cadence. Its initial purpose was to fill gaps in Node.js's built-in `path` module, many of which have since been addressed by the core Node.js `path`, `os`, and `fs` modules, or by widely adopted and maintained third-party alternatives.

error ReferenceError: require is not defined
cause Attempting to use `require()` in an ES module context or a browser environment where CommonJS is not supported.
fix
This package is CommonJS-only. If in an ESM project, rewrite the functionality using native Node.js modules (import { isAbsolute } from 'node:path';) or modern alternatives. If in a browser, use client-side path utilities or a bundler to transpile.
error TypeError: path.isAbsolutePath is not a function
cause Trying to destructure `isAbsolutePath` (e.g., `const { isAbsolutePath } = require('x-path');`) or calling it on an undefined `path` object.
fix
The package exports a single object containing all functions. Use const path = require('x-path'); and then access methods as path.isAbsolutePath(somePath);. Ensure require('x-path') successfully returns the module object.
error MODULE_NOT_FOUND: Cannot find package 'x-path' imported from ...
cause Using `import path from 'x-path';` in an ES module environment without proper CommonJS interoperability configuration, or the package is simply not installed.
fix
Ensure npm install x-path has been run. If in an ESM project, this package is not designed for direct import. Consider migrating to native Node.js path, os, and fs modules, which are ESM-compatible. Otherwise, if interoperability is configured, ensure correct path resolution.
breaking The package is effectively abandoned, with its last update in 2015 (version 0.0.2). It is not compatible with modern Node.js module systems (ESM) and its internal dependencies may contain unpatched vulnerabilities or rely on outdated APIs.
fix Migrate to native Node.js `path`, `os`, and `fs` modules (e.g., `path.isAbsolute`, `os.homedir`, `os.tmpdir`, `fs.stat`) or use actively maintained alternatives like `fs-extra` for extended file system operations.
gotcha This package is CommonJS-only. Attempting to use `import` statements directly in an ESM project will result in module resolution errors. It was published long before widespread ESM adoption in Node.js.
fix For CommonJS, use `const path = require('x-path');`. For ESM projects, rewrite functionality using native Node.js modules or modern, ESM-compatible libraries. If absolutely necessary, you might configure a bundler to transpile or wrap CommonJS modules.
deprecated Many of the utilities provided by `x-path`, such as `isAbsolutePath`, `homedir`, and `tempdir`, now have direct equivalents in Node.js's built-in `path` and `os` modules. The `fs.stat` methods provide robust, asynchronous file system checks.
fix Replace `path.isAbsolutePath` with `path.isAbsolute` (from `node:path`), `path.homedir` with `os.homedir()` (from `node:os`), `path.tempdir` with `os.tmpdir()` (from `node:os`). For file/directory checks, use `fs.stat` or `fs.promises.stat` for asynchronous, non-blocking operations.
gotcha The `isDirectorySync` and `isFileSync` methods perform synchronous file system operations. These block the Node.js event loop, leading to performance issues and unresponsiveness, especially in server applications or for large file operations.
fix Always prefer asynchronous file system methods. Use `fs.promises.stat(path)` or `fs.stat(path, callback)` and check the `stats` object (`stats.isDirectory()`, `stats.isFile()`) to determine file or directory type without blocking.
npm install x-path
yarn add x-path
pnpm add x-path

Demonstrates basic path checks (`isAbsolutePath`, `isRelativePath`), synchronous file system queries (`isDirectorySync`, `isFileSync`), and retrieval of system directories (`tempdir`, `homedir`).

const path = require('x-path');
const fs = require('fs');
const os = require('os');

// Create a dummy file and directory for testing file system checks
const testDirPath = './temp-test-dir';
const testFilePath = './temp-test-dir/test-file.txt';

if (!fs.existsSync(testDirPath)) {
  fs.mkdirSync(testDirPath);
}
fs.writeFileSync(testFilePath, 'Hello, x-path!');

console.log('--- x-path Usage Examples ---');

// Path checks
console.log(`Is '/usr/local/bin' an absolute path? ${path.isAbsolutePath('/usr/local/bin')}`);
console.log(`Is 'relative/path' a relative path? ${path.isRelativePath('relative/path')}`);

// File system checks (synchronous, generally discouraged)
console.log(`Is '${testDirPath}' a directory? ${path.isDirectorySync(testDirPath)}`);
console.log(`Is '${testFilePath}' a file? ${path.isFileSync(testFilePath)}`);
console.log(`Is './nonexistent' a directory? ${path.isDirectorySync('./nonexistent')}`);

// System directories
console.log(`Temporary directory: ${path.tempdir()}`);
console.log(`Home directory: ${path.homedir()}`);

// Clean up dummy files/directories
fs.unlinkSync(testFilePath);
fs.rmdirSync(testDirPath);
console.log('\nCleaned up temporary test files.');