@stryke/fs
Version:
A package containing various file system utilities that expand the functionality of NodeJs's built-in `fs` module.
55 lines (53 loc) • 2.22 kB
JavaScript
import { __exportAll } from "./_virtual/_rolldown/runtime.mjs";
import { lstatSync, statSync } from "node:fs";
import { joinPaths } from "@stryke/path/join-paths";
//#region src/is-file.ts
var is_file_exports = /* @__PURE__ */ __exportAll({
isDirectory: () => isDirectory,
isDirectorySymlink: () => isDirectorySymlink,
isFile: () => isFile,
isFileSymlink: () => isFileSymlink
});
/**
* 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, is_file_exports };
//# sourceMappingURL=is-file.mjs.map