3.12.0 • Published 2 years ago

fs-pro v3.12.0

Weekly downloads
1
License
MIT
Repository
github
Last release
2 years ago

fs pro

A small package to manage your files and folders easily

nest badge Codacy Badge npm npm npm bundle size GitHub Workflow Status codecov

see the API documentation here


Table of Contents

Features

  • works on both node and deno
  • you don't have to get the path of the file or directory every single time you want to do something with it
  • Strong typed and documented in the code
  • provides a method to parse json files .json()
  • object will be automatically be stringified to json when you use the write method
  • have a file structure system see Shape
  • will delete the whole dir when you use the delete method
  • provide advanced watching methods see Dir.watch method and File.watch method
  • you could add any method you like on any class you like via plugins see how to create plugins and addPlugin

Installation

via npm:

npm i fs-pro

via yarn:

yarn add fs-pro

via deno.land

import * as fsPro from "http://deno.land/x/fs_pro@version/mod.ts";

via nest.land

import * as fsPro from "https://x.nest.land/fs-pro@version/mod.ts";

Usage

import { File, Dir, Shape } from "fs-pro";

// creating a file object
const file = new File(__dirname, "hello_world.txt");
// creating a directory object
const dir = new Dir(__dirname, "some_dir");

file
  // writing to the file
  .write("hello ");
  // append content to the file
  .append("world");

console.log(file.read().toString()) // => "hello world"
// and there's much more in the docs

dir
  // create the directory (in the actual hard disk aka file system)
  .create()
  // creating a directory in the directory
  .createDir("sub_dir");
  // creating a file in the directory (this create a file object)
  .createFile("text.txt")
// and there's much more in the docs

// imagine that you want to check if a folder
// 1. has an folder named "something"
// 2. has an folder named "js_ts_files" that only contains js and ts files
// 3. has a text file name "hello world.txt" and by default this file contains "hello world"
// 4. any thing else in this folder must be a txt file
// you can do that easily with Shape

// (1) Create the Shape
const shape = new Shape({
  // Shape.File means that hello_world is a file
  // the second arg is the default content
  hello_world: Shape.File("hello world.txt", "hello world"),
  // Shape.Dir means that "something" is a folder
  // Shape.Pattern tells the types of files that can be in the folder
  // (like, .txt, .js, ...etc) here *.* means any thing
  something: Shape.Dir("something", Shape.Pattern("*.*")),
  // Notice js_ts_files is the name that you can reference in your code
  // but "js_ts_files" passed in Shape.Dir in the actual name in the files system
  js_ts_files: Shape.Dir("js_ts_files", Shape.Pattern("*.js|*.ts")),
  // __rest means any thing else in the folder
  __rest: Shape.Pattern("*.txt")
});

// (2) Check the folder
// returns an array of errors
const errs = shape.validate(folder_path);

if (errs.length === 0) console.log("no errors");

// or..
// when you pass true shape.validate will throw an error
// if the folder doesn't match the shape
shape.validate(folder_path, true);

Api

Creating plugins

import { Plugin } from "fs-pro/types";
import { addPlugin } from "fs-pro";

const myPlugin: Plugin = {
  name: "your-plugin-name",
  required: [anyRequiredPlugin] // optional
  plugin: [
    {
      methodName: "myMethod",
      className: "File", // could be the name of any class in the library (File or Dir or Shape)
      isStatic: false, // if true the method you add will be static
      func(...myArgs: any[]){
        // your code...
      }
    }
  ]
}

export default myPlugin

Using Plugins

import { addPlugin } from "fs-pro";
import myPlugin from "./my-plugin";

addPlugin(myPlugin);

Change Log

see our Change Log

we don't leave our change log here cause it's quite long

License

Copyright (c) AliBasicCoder 2020

3.12.0

2 years ago

3.7.3

2 years ago

3.7.2

2 years ago

3.9.1

2 years ago

3.9.0

2 years ago

3.10.1

2 years ago

3.8.0

2 years ago

3.10.0

2 years ago

3.8.1

2 years ago

3.11.0

2 years ago

3.7.1

3 years ago

3.7.0

3 years ago

3.6.0

4 years ago

3.4.3

4 years ago

3.4.2

4 years ago

3.4.1

4 years ago

3.4.0

4 years ago

3.3.1

4 years ago

3.3.0

4 years ago

3.2.1

4 years ago

3.2.0

4 years ago

3.1.0

4 years ago

3.0.0

4 years ago

2.6.0

4 years ago

2.5.0

4 years ago

2.4.5

4 years ago

2.4.4

4 years ago

2.4.3

4 years ago

2.4.2

4 years ago

2.4.1

4 years ago

2.4.0

4 years ago

2.3.9

4 years ago

2.3.8

4 years ago

2.3.7

4 years ago

2.3.6

4 years ago

2.3.5

4 years ago

2.3.4

4 years ago

2.0.8

4 years ago

2.0.5

4 years ago

2.0.7

4 years ago

2.0.6

4 years ago

2.0.4

4 years ago

2.0.3

4 years ago

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.5.2

4 years ago

1.5.1

4 years ago

1.5.0

4 years ago

1.4.9

4 years ago

1.4.8

4 years ago

1.4.7

4 years ago

1.4.6

4 years ago

1.4.5

4 years ago

1.4.4

4 years ago

1.4.3

4 years ago

1.4.2

4 years ago

1.4.1

4 years ago

1.4.0

4 years ago

1.3.9

4 years ago

1.3.8

4 years ago

1.3.7

4 years ago

1.3.6

5 years ago

1.3.5

4 years ago

1.3.4

4 years ago

1.3.3

4 years ago

1.3.2

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.9

4 years ago

1.2.8

4 years ago

1.2.7

4 years ago

1.2.6

4 years ago

1.2.5

4 years ago

1.2.4

4 years ago

1.2.3

4 years ago

1.2.2

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.9

4 years ago

1.1.8

4 years ago

1.1.7

4 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.0

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago