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

coda-file-system

v1.0.1

Published

Plugin to add a pseudo file system to terminal-in-react

Downloads

4

Readme

Pseudo File System Plugin

Downloads Downloads NPM Version Dependencies Dev Dependencies License

Plugin to add a pseudo file system to terminal-in-react

Install

npm i -S terminal-in-react-pseudo-file-system-plugin
yarn add terminal-in-react-pseudo-file-system-plugin

Usage

The default export is a function the returns the plugin class. The function takes on argument the pathSeporator this is defaulted to '\' so it is not required.

You can also specify the storage type for the filesystem. There are two types basic or db. basic is the default type and just uses client side json object and as such will not keep files from one session to another. db uses indexedDb and as such only works in browsers where it is supported but has the benefit of keeping files from session to session.

If you use the db storage type there is a third parameter that can be passed in for if you would like to clear the db on start, by default it is false.

import pseudoFileSystemPlugin from 'terminal-in-react-pseudo-file-system-plugin';
const FileSystemPlugin = pseudoFileSystemPlugin();

...
<Terminal
  plugins={[
    FileSystemPlugin
  ]}
/>
...

Commands

The commands it adds are:

  • cd
  • ls
  • rm
  • mkdir
  • touch
  • cat
  • echo

Plugin public methods

The methods available to other plugins

  • parsePath
  • isValidPath
  • createDir
  • createFile
  • removeDir
  • removeFile
  • readDir
  • readFile
  • writeFile
  • pathToString
  • types

Details

The Path Object

Path objects are core to most of the functions. It has a few parts.

  • parts: an array of the string parts of the path that would be separated by the path separator
  • isDir: if this path points to a directory
  • isRoot: if the given path string when parsed was a full path or not

The way to create these objects is via the parsePath method. This function will take a string path and return a path object. This object is just a representation of a path it does not mean that anything exist at that path.

Validating if a path exists

To check that a given path object points to something in the filesystem you need to use the isValidPath method. This function take a path object and a callback as its parameters. If the path is valid will be returned to the callback as a parameter.

isValidPath(pathObj, (valid) => {
  if (valid) {
    // Do thing
  }
});

Path back into a string

To take a path object and turn it back into a string just pass it into the method pathToString.

Reading files

To read a file's contents use the readFile method. This function takes a path object and a callback function. The callback will receive the string contents of the file or null if there was some issue reading the file.

readFile(pathObj, (content) => {
  if (content !== null) {
    // Do thing
  }
});

Reading directories

To read a directory's contents use the readDir method. This function takes a path object and a callback function. The callback will receive an array of objects refrencing the files and folders that are children of the folder or null if there was an issue getting the contents.

readDir(pathObj, (content) => {
  if (content !== null) {
    // Do thing
  }
});