Filesystem utils, usable in all environments
npm install @dazl/fs-utils
@dazl/fs-utils on Github
| Function | Description |
| ------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
| addRelativePrefix(path) | |
| createImportPath({ importedFilePath, targetFilePath, targetPackageJsonPath, fs, }) | Returns relative import path if imported and target files are in the same package, otherwise returns a bare import specifier. |
| formatToOSpaths(str) | |
| getBareImportSpecifier(absoluteImportPath, packageJsonPath, packageJsonName) | Creates bare import specifier for an absolute import path, stripping extension from JS/TS files. |
| getDTSPath(filePath) | |
| getFullExtname(filePath) | Returns file extension from the first occurrence of the ".", unlike path.extname() which returns from the last occurrence. |
| getImportPath(filePath) | |
| getPackageJsonPath(filePath, fs) | Gets path to package.json file closest to the given file path. |
| getPackageName(dirPath, fs) | Gets package name. |
| getPackagePath(filePath, fs) | Gets path to package directory, closest to the given file path. |
| getRelativeImportPath(sourceFilePath, filePathToImport) | Creates relative import path for a file, stripping extension from JS/TS files. |
| getRelativeModulePath(sourceAbsFilePath, targetAbsFilePath) | |
| isDirPath(filePath) | |
| isJavaScriptFile(filePath) | |
| isJsonFile(filePath) | |
| isPathIncludesDir(filePath, directoryName) | Safely checks if a path contains a directory name. |
| isRelativeModulePath(path) | |
| isRelativeModuleRequest(request) | |
| isSubPath(path, basePath, fs) | Checks if a path is equal to or subpath of a given base path. |
| isTsOrJS(filePath) | |
| isTypeAffectingFileOrDir(filePath) | |
| isTypeScriptFile(filePath) | |
| isWindowsStyleAbsolutePath(fsPath) | |
| pathChainToRoot(currentPath) | |
| pathToTrueCase(fs, path) | Returns case-exact absolute form of the path, similar to fs.realpathSync.native() Trailing segments of the path that don't exist are left unchanged. |
| readPackageJson(dirPath, fs) | Read and parse a directory's package.json |
| rebaseRelativeModulePath(filePath, modulePath) | |
| replaceWinSlashes(str) | |
| Interface | Description |
| ------------------------------------------------------------------------------------------------------------ | ----------- |
| AdjustRelativeImportPathArgs | |
| CreateImportPathArgs | |
| Variable | Description |
| -------------------------------------------------------------------------------------- | ---------------------------------------------------- |
| fileRequestPrefix | prefix for file requests in Language server protocol |