@stryke/fs
Version:
A package containing various file system utilities that expand the functionality of NodeJs's built-in `fs` module.
52 lines (50 loc) • 2.3 kB
JavaScript
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
let node_fs = require("node:fs");
let _stryke_path_join_paths = require("@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((0, node_fs.statSync)(additionalPath ? (0, _stryke_path_join_paths.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((0, node_fs.statSync)(additionalPath ? (0, _stryke_path_join_paths.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((0, node_fs.lstatSync)(additionalPath ? (0, _stryke_path_join_paths.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((0, node_fs.lstatSync)(additionalPath ? (0, _stryke_path_join_paths.joinPaths)(additionalPath, path) : path, { throwIfNoEntry: false })?.isDirectory());
};
//#endregion
exports.isDirectory = isDirectory;
exports.isDirectorySymlink = isDirectorySymlink;
exports.isFile = isFile;
exports.isFileSymlink = isFileSymlink;