Skip to content

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.

License

Notifications You must be signed in to change notification settings

jesusgraterol/fs-utils-sync

Repository files navigation

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'); // true
pathExists('project/some-file.json'); // true
pathExists('project/other-file.json'); // false

getPathElement('project/other-file.json'); // null
getPathElement('project/some-file.json');
// {
//    path: 'project/some-file.json',
//    baseName: 'some-file.json',
//    extName: '.json',
//    isFile: true,
//    isDirectory: false,
//    isSymbolicLink: false,
//    size: 8647,
//    creation: 1715264137289,
// }

API

General Actions

  • pathExists(path: string): boolean

  • getPathElement(path: string): IPathElement | null

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

  • TypeScript

Running the Tests

# Unit Tests
$ npm run test:unit

# Integration Tests
$ npm run test:integration

License

MIT


Acknowledgments

  • ...

@TODOS

  • Upgrade the docs
  • Implement and test compressDirectory and decompressDirectory
  • Implement and test compressFile and decompressFile

Deployment

Install dependencies:

$ npm install

Build the library:

$ npm start

Publish to npm:

$ npm publish

About

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.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published