https://github.com/svetozarmateev/fs-assistant
fs-assistant npm package
https://github.com/svetozarmateev/fs-assistant
fs javascript-library nodejs npm npm-package recursive typescript typescript-library
Last synced: about 1 year ago
JSON representation
fs-assistant npm package
- Host: GitHub
- URL: https://github.com/svetozarmateev/fs-assistant
- Owner: SvetozarMateev
- License: mit
- Created: 2018-11-23T14:09:29.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2024-02-25T13:01:36.000Z (about 2 years ago)
- Last Synced: 2025-03-04T05:04:31.164Z (about 1 year ago)
- Topics: fs, javascript-library, nodejs, npm, npm-package, recursive, typescript, typescript-library
- Language: TypeScript
- Homepage:
- Size: 209 KB
- Stars: 3
- Watchers: 2
- Forks: 2
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fs-assistant





fs-assistant is a simple library that gives you recursive folder copying, simplified file overrides and promisified fs functions.
```javascript
replaceStringInFile (pathToFile: string, stringPattern: RegExp | string, newString: string) => Promise
```
Replaces a string in a file that matches the pattern with the new given string.
```javascript
copyDir (pathToDir: string, pathToNewDir: string) => Promise
```
Recursively copies all files from a directory to another.
```javascript
readFile (fileLocation: string) => Promise
```
Promisified version of fs readFile.
```javascript
writeFile (newFileLocation: string, contents:any) => Promise
```
Promisified version of fs writeFile.
```javascript
copyFile (from: string, to: string) => Promise
```
Promisified version of fs copyFile.
```javascript
makeDir (location: string) => Promise
```
Promisified version of fs makeDir.
```javascript
deleteFile (location: string) => Promise
```
Deletes the specified file.
```javascript
renameFile (fileLocation: string, newFileName: string) => Promise
```
Renames the specified file
```javascript
isPath (stringToCheck: string) => boolean
```
Checks if the given string is a valid path. You can check all covered cases [here](https://github.com/SvetozarMateev/fs-assistant/blob/master/test/integration/isPath.spec.ts).
```javascript
flattenDir (dirLocation: string, newLocation: string) => Promise
```
Moves all files from a directory (recursively) to a new directory.
For example if you have the directory `./myFiles` with a file `./myFiles/myFile.txt` and a nested directory `./myFiles/nestedFiles` which contains `./myFiles/nestedFiles/nestedFile.txt` the flattenDir function will move both files to the same level in a new output directory.
```javascript
getFilesInDir(dirLocation: string) => Promise
```
Returns an array with all file names and locations in a directory (recursively). Note that the location property in FileDetails represents the path + the name of the file.
```javascript
readDir(dir: string) => Promise
```
The promisified version of fs.readdir.
```javascript
getDirsInDir(dirLocation: string) => Promise
```
Returns an array with all sub directories of a directory.
```javascript
getFilesInDir(dirLocation: string) => Promise
```
Returns an array with all items represented either as FileDetails or as DirectoryDetails.
```javascript
getFileSizeInBytes: (location: string) => Promise;
```
Returns the file size in bytes.
```javascript
getDirSizeInBytes: (location: string) => Promise;
```
Returns the directory size in bytes.
```javascript
delDir: (location: string) => Promise;
```
Deletes the directory recursively.
```javascript
existsSync: (location: string) => boolean;
```
Equivalent to `fs.existsSync()`.