Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/binocarlos/cli-path-resolve
resolve/normalize a filepath using the cwd as the basepath if relative
https://github.com/binocarlos/cli-path-resolve
Last synced: 11 days ago
JSON representation
resolve/normalize a filepath using the cwd as the basepath if relative
- Host: GitHub
- URL: https://github.com/binocarlos/cli-path-resolve
- Owner: binocarlos
- License: mit
- Created: 2014-06-28T15:33:34.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-11-14T18:23:16.000Z (about 10 years ago)
- Last Synced: 2024-10-07T17:10:12.313Z (about 1 month ago)
- Language: JavaScript
- Size: 137 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
cli-path-resolve
================resolve/normalize a filepath using the cwd as the basepath if relative
## installation
```
$ npm install cli-path-resolve
```## usage
If an argument is passed to your cli script that points to the file system, it can be absolute or relative.
If it's relative - this module will use the current working directory (process.cwd) as the basedir.
globalscript.js
```js
var args = require('minimist').parse(process.argv, {
alias:{
f:'filepath'
}
})
var resolve = require('cli-path-resolve')
var filepath = resolve(args.filepath)// filepath is now normalized and absolute
console.log(filepath)
```If we have installed globalscript.js globally - we can run it from anywhere.
```
$ cd /home/myfolder
$ globalscript.js --filepath imgs/balloons.jpg
/home/myfolder/imgs/balloons.jpg
```## api
### `var resolved = resolve(path)`
Will return path if it is absolute or will resolve it against process.cwd if its relative.
### license
MIT