feat(iso): add isomorphic path module with cross-platform utilities
This commit is contained in:
31
readme.md
31
readme.md
@@ -18,6 +18,37 @@ To begin utilizing `smartpath` in your project, start by importing it in your Ty
|
||||
import * as smartpath from '@push.rocks/smartpath';
|
||||
```
|
||||
|
||||
### Isomorphic Path Module
|
||||
For cross-platform path operations that work in any JavaScript environment (Node.js, browsers, Deno, etc.), use the isomorphic module:
|
||||
|
||||
```typescript
|
||||
import * as isoPath from '@push.rocks/smartpath/iso';
|
||||
|
||||
// Join paths with automatic platform detection
|
||||
const joinedPath = isoPath.pathJoin('/home/user', 'documents', 'file.txt');
|
||||
// Unix: /home/user/documents/file.txt
|
||||
// Windows: C:\Users\documents\file.txt
|
||||
|
||||
// Convert file:// URLs to system paths
|
||||
const systemPath = isoPath.fileUrlToPath('file:///home/user/file.txt');
|
||||
// Unix: /home/user/file.txt
|
||||
// Windows: C:\home\user\file.txt
|
||||
|
||||
// Convert system paths to file:// URLs
|
||||
const fileUrl = isoPath.pathToFileUrl('/home/user/file.txt');
|
||||
// Result: file:///home/user/file.txt
|
||||
|
||||
// Get directory from path or file URL
|
||||
const dir = isoPath.dirname('/home/user/documents/file.txt');
|
||||
// Result: /home/user/documents
|
||||
```
|
||||
|
||||
The isomorphic module automatically detects the path style (Windows vs POSIX) and handles:
|
||||
- file:// URL conversions
|
||||
- Mixed path separators
|
||||
- Cross-platform compatibility
|
||||
- Proper handling of Windows drive letters and UNC paths
|
||||
|
||||
### Creating a Smartpath Instance
|
||||
Instantiating a `Smartpath` object allows for the enrichment of path strings with additional context and manipulation capabilities:
|
||||
|
||||
|
Reference in New Issue
Block a user