@stryke/fs
Version:
A package containing various file system utilities that expand the functionality of NodeJs's built-in `fs` module.
48 lines (46 loc) • 1.94 kB
JavaScript
import { lstatSync, statSync } from "node:fs";
import { joinPaths } from "@stryke/path/join-paths";
//#region src/is-file.ts
/**
* Check if the given path is a file.
*
* @param path - The location to check
* @param additionalPath - An optional additional path to add to the start of the path
* @returns An indicator specifying if the path is a file
*/
function isFile(path, additionalPath) {
return Boolean(statSync(additionalPath ? joinPaths(additionalPath, path) : path, { throwIfNoEntry: false })?.isFile());
}
/**
* Check if the given path is a directory.
*
* @param path - The location to check
* @param additionalPath - An optional additional path to add to the start of the path
* @returns An indicator specifying if the path is a directory
*/
function isDirectory(path, additionalPath) {
return Boolean(statSync(additionalPath ? joinPaths(additionalPath, path) : path, { throwIfNoEntry: false })?.isDirectory());
}
/**
* Check if the given path is a file . Does not dereference symbolic links.
*
* @param path - The location to check
* @param additionalPath - An optional additional path to add to the start of the path
* @returns An indicator specifying if the path is a file
*/
const isFileSymlink = (path, additionalPath) => {
return Boolean(lstatSync(additionalPath ? joinPaths(additionalPath, path) : path, { throwIfNoEntry: false })?.isFile());
};
/**
* Check if the given path is a directory. Does not dereference symbolic links.
*
* @param path - The location to check
* @param additionalPath - An optional additional path to add to the start of the path
* @returns An indicator specifying if the path is a directory
*/
const isDirectorySymlink = (path, additionalPath) => {
return Boolean(lstatSync(additionalPath ? joinPaths(additionalPath, path) : path, { throwIfNoEntry: false })?.isDirectory());
};
//#endregion
export { isDirectory, isDirectorySymlink, isFile, isFileSymlink };
//# sourceMappingURL=is-file.mjs.map