Giter Site home page Giter Site logo

therayvoice / ray-fs Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 33 KB

A library with easy to use, mind blowing file-system tools for NodeJS. Based on FS! with chainable methods, sync first approach, and amazing UX.

License: MIT License

JavaScript 100.00%
fs nodejs chainable-methods synchronous filesystem hacktoberfest

ray-fs's Introduction

ray-fs

A library with easy to use, mind blowing file-system tools for NodeJS. Based on FS! with chainable methods, sync first approach, and amazing UX.

Installation

To install with NPM use:

npm i ray-fs --save

Then attach it to your file using:

const fs = require('ray-fs');

// use code here

Usage

The ray-fs library has the following methods and properties:

  1. .value: To return the output of the previous method in the chain.

For example:-

fs
  .lsDir() // gets the list of Directories
  .value // returns the list of Directories
  1. .logVal(): To console.log() the output of the previous method in chain. For example:-
fs
  .lsFile() // gets the list of Files
  .logVal() // logs the list of Files
  1. .cd(dirName): To change the "working-directory" to dirName. A virtual version of shell's cd, it does not allow a movement to directories deeper then depth=1.

  2. .ls(): To get a list of all the Files in the "working-directory".

  3. .exists(fileURL): To check if a FS item (like a File) exists at fileURL.

  4. .isFile(fileURL): To check if fileURL is a File or not! (a Directory maybe)

  5. .isDir(dirURL): To check if dirURL is a Direcotry or not!

  6. .lsMatches(filterFunction): To get a list of all items in the "working-directory" that matches filterFunction.

fs
  // To get a list of all items in the "working-directory" that have names ending in ".js"
  .lsMatches(item => /.js$/.test(item))
  .value // To return that list

Better written as:

fs
  // To get a list of all Javascript Files in the "working-directory"
  .lsMatches(item => fs.isFile(item).value && /.js$/.test(item))
  .value // To return that list
  1. .lsDir(): To get a list of all Directories in the "working-directory".

  2. .lsFile(): To get a list of all Files in the "working-directory".

  3. .version(): To get the current version of ray-fs.

  4. .write(fileURL, content): To write the content into the file at fileURL.

  5. .read(fileURL).value: To read the content of the file at fileURL. The path used must be relative from the root directory of your project, e.g. "./README.md".

  6. .writeJSON(fileURL, json): To write the json into the file at fileURL.

  7. .readJSON(fileURL).value: To read/import the JSON content of the file at fileURL.

  8. .updateJSON(file, callback): TO update the json object in a .json file. For example:

const fs = require('ray-fs');

const file = "june.json";
fs
  .updateJSON(file, (json) => {
    json.oldProp = "replace old prop's value with new value"; 
    json.newProp = "adds a new prop with a new value";
    return json;	
  });
  1. .readArray(fileURL).value: To read/import the content of the file at fileURL as an Array of lines of content.

  2. .push(fileURL, content): To add the content below the existing content of the file at fileURL.

  3. .rm(url): To delete the item at url.

  4. .cp(url, destinationURL): To copy the item at url to destinationURL.

  5. .mv(url, destinationURL): To move the item at url to destinationURL.

  6. .mkdir(dirName): To create a new Directory named dirName.

  7. .logDir(): To log the name of the "working-directory".

  8. .validFileName(fileName): To check if a file name complies with the file naming rules. (beta version)

  9. .validDirName(dirName): To check if a directory name complies with the naming rules. (beta version)

  10. .stream(responseBody, filePath, errorCallback, sucessCallback): To pipe a response.body to a filePath.

  11. .initDir(dirName): To check if a directory exists, if no then create it.

  12. .initDirs(dirName1, dirName2, ...): To check if all of the provided directories exist, if any don't then create them.

  13. .initFile(fileName, fileContent): To check if a file exists, if no then create it, then add the provided fileContent to it. The fileContent paremeter can be passed a JSON object or a String.

Note: The documentation is incomplete, and will be completed soon.

Chaining Functions

Chain functions to make code more readable!

const fs = require('ray-fs');

fs
  .mkdir('myProject')
  .cd('myProject')
  .write('myFile.txt', 'Hello World!')
  .cp('myFile.txt', 'myGreeting.txt')
  .read('myFile.txt')
  .logVal()
  .read('myGreeting.txt')
  .logVal()

The .value prop and the .

Tips

  1. Absolute URL's aren't allowed, instead use .cd() to change the "working-directory" first!
  2. Chain for the betterment of code, don't chain where it dosen't make sense.
  3. This library is not meant to replace fs, it is meant to be an alternative way to write code that can also be written with fs. This library will allow you to write significaltly shorter and clearer code.

Comming Soon

  1. Async methods.
  2. color logs.

ray-fs's People

Contributors

therayvoice avatar

Stargazers

 avatar

Watchers

 avatar  avatar

ray-fs's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.