path-resolver utility functions for node
Pathre
consists of validation and get functions which make dealing with path super simple and easy 👌
Usage
Validation functions
Get functions
Other
Getting Started
clone the repo:
git clone git@github.com:jimmy02020/pathre.gitcd pathre
Using npm:
$ npm install pathre
Validation:
const check =
isPathValid(path)
Validate given path. If path is valid returns true, otherwise returns false.
Example
check // falsecheck // true
isPathDir(path)
If path is for directory (not file) returns true, otherwise returns false.
Example
check // truecheck // false
isPathFile(path)
If path is for file (not directory) returns true, otherwise returns false.
Example
check // true
isExist(path, callback)
If path is valid/existent returns true, otherwise returns false.
NOTE: Path can be valid path but not for existence path. If you check for existence use isExist
if you validate the path before create it use isValid
.
Example
isFileZeroSize(path, callback)
If file is valid and zero size then true, otherwise returns false.
Example
Get functions:
const get =
directory(path)
Returns string has directory name, whether the path is with file name or without it.
Example
get // '/path/here
fileName(path)
Returns string has file name.
Example
get // .env.test
fileExt(path)
Returns string has file extension.
Example
get // envget // txt
fileStat(path, callback)
Gets text statistics from file. The function is implementation of textics-stream
The callback gets two arguments (err, stat)
.
stat
object consists of:
lines
words
chars
spaces
Example
get;
pathType(path)
Gets path type, file or directory.
returns {isDir, isFile}
.
Example
const type = getconsole;// isDir: false isFile: true//
pathStat(path, callback)
Gets the main properties from path.
The callback gets two arguments (err, stat)
.
stat
object consists of:
isValid
isDir
isFile
size
Example
get;
Tests
$ npm test
License
This project is licensed under the MIT License