Aims to standardize path representations across different operating systems, using Linux-style paths as the common format
npm install @nojaja/pathutilNodePathUtil is a utility class designed to standardize path representations across different operating systems. It uses Linux-style paths as the common format to ensure consistency when working with paths from various platforms.
- Path separator normalization
- Absolute path detection
- Conversion from relative to absolute paths
- Conversion from absolute to relative paths
- Support for both Windows and Unix-based systems
``bash`
npm install @nojaja/pathutil
`javascript
import { PathUtil } from '@nojaja/pathutil';
// Normalize path separators
const normalizedPath = PathUtil.normalizeSeparator('C:\\Users\\example\\Documents');
console.log(normalizedPath); // Output: C:/Users/example/Documents
// Check if path is absolute
const isAbsolute = PathUtil.isAbsolute('/home/user/documents');
console.log(isAbsolute); // Output: true
// Convert relative path to absolute path
const absolutePath = PathUtil.absolutePath('../documents', '/home/user');
console.log(absolutePath); // Output: /home/documents
// Convert absolute path to relative path
const relativePath = PathUtil.relativePath('/home/user/documents', '/home');
console.log(relativePath); // Output: user/documents
`
Normalizes path separators to Linux-style (forward slashes).
Determines whether the given path is absolute.
Converts a relative path to an absolute path. If currentDirectory is not specified, it uses the current working directory.
Converts an absolute path to a relative path. If currentDirectory is not specified, it uses the current working directory.
This project includes both unit tests and integration tests to ensure reliability and correctness.
Unit tests validate individual methods in isolation using TypeScript source files:
`bash`
npm test
- Location: tests/PathUtil/*.spec.js
- Files: jest.config.js
- Configuration:
- Purpose: Test source code logic with mocks and isolated test cases
Integration tests validate the bundled output that end users consume. These tests ensure that:
1. All public APIs are correctly exported from the bundle
2. No regression issues from the build process (e.g., missing exports)
3. Methods work correctly when accessed through the packaged library
`bash`
npm run test:integration
- Location: tests/integration/*.test.js
- Files: jest.integration.config.js
- Configuration: dist/PathUtil.bundle.js
- Purpose: Test the actual bundled file as users will consume it
To run both unit and integration tests:
`bash`
npm run test:all
`bash1. Make changes to source code
2. Run unit tests to validate logic
npm test
This project is released under the MIT License. See the LICENSE file for details.
Contributions of all kinds are welcome, including bug reports, feature requests, and pull requests. For major changes, please open an issue first to discuss what you would like to change.