@iohub/pathinfo
Version:
Efficient Node.js utilities for path manipulation, analysis, and validation with support for name, extension, and directory operations
55 lines (37 loc) • 1.6 kB
Markdown
# @iohub/pathinfo
Powerful path manipulation utilities for Node.js with zero dependencies.
[](https://npmjs.org/package/@iohub/pathinfo)
[](https://npmjs.org/package/@iohub/pathinfo)
[](https://npmjs.org/package/@iohub/pathinfo)
[](https://github.com/gadge/iohub)
## Features
- Extract file names, extensions, and directory information
- Asynchronous file existence checking
- Zero dependencies
- Modern ES modules support
- Node.js >=22.0.0
## Installation
```bash
# npm
npm install @iohub/pathinfo
# yarn
yarn add @iohub/pathinfo
# pnpm
pnpm add @iohub/pathinfo
```
## Usage
```js
import { pathToName, pathToNameExt, pathToEntry, pathToInfo, exists } from '@iohub/pathinfo'
// Extract file name without extension
pathToName('path/to/file.txt') // => 'file'
// Get file name with extension
pathToNameExt('path/to/file.txt') // => 'file.txt'
// Get file name and extension as array
pathToEntry('path/to/file.txt') // => ['file', '.txt']
// Get complete path information
pathToInfo('path/to/file.txt') // => { dir: 'path/to', doc: 'file', ext: '.txt' }
// Check if path exists
await exists('path/to/file.txt') // => true/false
```
## License
[MIT](LICENSE) © Hoyeung Wong