NPM Smell 🍑💨

trivial and outdated NPM packages

path-type outdated npm logo

Utility functions to check if a path is a file, directory, or symlink

Weekly Downloads
35,544,116
Dependencies
0
Latest Release
a year ago
Switch to the native implementation.
Outdated
First version with native support
Node.js 10.0.0
added to Node.js
8 years ago

This library provides utility functions to check if a path is a file, directory, or symlink. It provides sync and async versions. e.g.:

import { isFile } from "path-type";

console.log(await isFile("package.json"));
//=> true

Node.js can do this natively via lstat:

import fs from "node:fs";
const stats = fs.lstatSync(filePath);

if (stats.isFile()) {
    // path is a file
}
if (stats.isDirectory()) {
    // path is a directory
}
if (stats.isSymbolicLink()) {
    // path is a symlink
}

or asynchronously:

import fs from "node:fs";
const stats = fs.lstatSync(filePath);

if (stats.isFile()) {
    // path is a file
}
if (stats.isDirectory()) {
    // path is a directory
}
if (stats.isSymbolicLink()) {
    // path is a symlink
}