What is path-type?
The path-type npm package is a simple utility that provides functions to check the type of a filesystem path. It can determine whether a path is a file, directory, symbolic link, etc. It is useful for validating paths and handling them conditionally based on their type.
What are path-type's main functionalities?
isFile
Checks if a path is a file.
const pathType = require('path-type');
pathType.isFile('source.js').then(isFile => {
console.log(isFile); //=> true or false
});
isDirectory
Checks if a path is a directory.
const pathType = require('path-type');
pathType.isDirectory('source').then(isDirectory => {
console.log(isDirectory); //=> true or false
});
isSymlink
Checks if a path is a symbolic link.
const pathType = require('path-type');
pathType.isSymlink('link').then(isSymlink => {
console.log(isSymlink); //=> true or false
});
Other packages similar to path-type
fs-extra
fs-extra is a package that extends the built-in fs module, providing additional methods and also includes the functionality to check path types. It is more comprehensive than path-type as it includes file system operations beyond type checking.
fs-promise
fs-promise is a package that promisifies the Node.js fs module and adds support for promises to file system operations, including checking if a path is a file or directory. It is similar to path-type but is integrated with the fs module's other functionalities.
path-type
Check if a path is a file, directory, or symlink
Install
$ npm install --save path-type
Usage
var pathType = require('path-type');
pathType.file('package.json').then(function (isFile) {
console.log(isFile);
})
API
.file(path)
.dir(path)
.symlink(path)
Returns a promise that resolves to a boolean of whether the path is the checked type.
.fileSync(path)
.dirSync(path)
.symlinkSync(path)
Returns a boolean of whether the path is the checked type.
License
MIT © Sindre Sorhus