UNPKG

@stryke/fs

Version:

A package containing various file system utilities that expand the functionality of NodeJs's built-in `fs` module.

1 lines 3.54 kB
{"version":3,"file":"is-file.mjs","names":[],"sources":["../src/is-file.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { joinPaths } from \"@stryke/path/join-paths\";\nimport { lstatSync, statSync } from \"node:fs\";\n\n/**\n * Check if the given path is a file.\n *\n * @param path - The location to check\n * @param additionalPath - An optional additional path to add to the start of the path\n * @returns An indicator specifying if the path is a file\n */\nexport function isFile(path: string, additionalPath?: string): boolean {\n return Boolean(\n statSync(additionalPath ? joinPaths(additionalPath, path) : path, {\n throwIfNoEntry: false\n })?.isFile()\n );\n}\n\n/**\n * Check if the given path is a directory.\n *\n * @param path - The location to check\n * @param additionalPath - An optional additional path to add to the start of the path\n * @returns An indicator specifying if the path is a directory\n */\nexport function isDirectory(path: string, additionalPath?: string): boolean {\n return Boolean(\n statSync(additionalPath ? joinPaths(additionalPath, path) : path, {\n throwIfNoEntry: false\n })?.isDirectory()\n );\n}\n\n/**\n * Check if the given path is a file . Does not dereference symbolic links.\n *\n * @param path - The location to check\n * @param additionalPath - An optional additional path to add to the start of the path\n * @returns An indicator specifying if the path is a file\n */\nexport const isFileSymlink = (\n path: string,\n additionalPath?: string\n): boolean => {\n return Boolean(\n lstatSync(additionalPath ? joinPaths(additionalPath, path) : path, {\n throwIfNoEntry: false\n })?.isFile()\n );\n};\n\n/**\n * Check if the given path is a directory. Does not dereference symbolic links.\n *\n * @param path - The location to check\n * @param additionalPath - An optional additional path to add to the start of the path\n * @returns An indicator specifying if the path is a directory\n */\nexport const isDirectorySymlink = (\n path: string,\n additionalPath?: string\n): boolean => {\n return Boolean(\n lstatSync(additionalPath ? joinPaths(additionalPath, path) : path, {\n throwIfNoEntry: false\n })?.isDirectory()\n );\n};\n"],"mappings":";;;;;;;;;;;AA4BA,SAAgB,OAAO,MAAc,gBAAkC;AACrE,QAAO,QACL,SAAS,iBAAiB,UAAU,gBAAgB,KAAK,GAAG,MAAM,EAChE,gBAAgB,OACjB,CAAC,EAAE,QAAQ,CACb;;;;;;;;;AAUH,SAAgB,YAAY,MAAc,gBAAkC;AAC1E,QAAO,QACL,SAAS,iBAAiB,UAAU,gBAAgB,KAAK,GAAG,MAAM,EAChE,gBAAgB,OACjB,CAAC,EAAE,aAAa,CAClB;;;;;;;;;AAUH,MAAa,iBACX,MACA,mBACY;AACZ,QAAO,QACL,UAAU,iBAAiB,UAAU,gBAAgB,KAAK,GAAG,MAAM,EACjE,gBAAgB,OACjB,CAAC,EAAE,QAAQ,CACb;;;;;;;;;AAUH,MAAa,sBACX,MACA,mBACY;AACZ,QAAO,QACL,UAAU,iBAAiB,UAAU,gBAAgB,KAAK,GAAG,MAAM,EACjE,gBAAgB,OACjB,CAAC,EAAE,aAAa,CAClB"}