Filesystem Utils Sync
Streamline synchronous file system interactions in your Node.js projects with the lightweight fs-utils-sync
package. It provides a collection of well-defined utility functions that enforce consistency across projects, ensuring an unified approach to file system operations.
Getting Started
Install the package:
$ npm install -S fs-utils-sync
Usage Examples
project
│
some-dir/
│ └───...
│
some-file.json
import { pathExist, getPathElement } from 'fs-utils-sync';
pathExists('project/some-dir');
pathExists('project/some-file.json');
pathExists('project/other-file.json');
getPathElement('project/other-file.json');
getPathElement('project/some-file.json');
API
General Actions
Directory Actions
-
isDirectory(path: string): boolean
-
deleteDirectory(path: string): void
-
createDirectory(path: string, deleteIfExists?: boolean): void
-
copyDirectory(srcPath: string, destPath: string): void
-
createDirectorySymLink(target: string, path: string): void
-
readDirectory(path: string, recursive?: boolean): string[]
-
getDirectoryElements(path: string, options?: Partial<IDirectoryElementsOptions>): IDirectoryPathElements
File Actions
-
isFile(path: string): boolean
-
writeFile(path: string, data: string | NodeJS.ArrayBufferView, options?: WriteFileOptions): void
-
writeTextFile(path: string, data: string): void
-
writeJSONFile(path: string, data: object | string, space?: number): void
-
writeBufferFile(path: string, data: Buffer): void
-
readFile(path: string, options?: IReadFileOptions): string | Buffer
-
readTextFile(path: string): string
-
readJSONFile(path: string): object
-
readBufferFile(path: string): Buffer
-
copyFile(srcPath: string, destPath: string): void
-
deleteFile(path: string): void
-
createFileSymLink(target: string, path: string)
Built With
Running the Tests
$ npm run test:unit
$ npm run test:integration
License
MIT
Acknowledgments
@TODOS
Deployment
Install dependencies:
$ npm install
Build the library:
$ npm start
Publish to npm
:
$ npm publish