npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fs-pro

v3.12.0

Published

working with files easily

Downloads

25

Readme

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