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

ooafs

v1.1.3

Published

Type-safe Object-Oriented Async FileSystem

Downloads

124

Readme

ooafs

GitHub license David

OOAFS allows you to manipulate the FileSystem in an object-oriented fashion, by using objects to represent FS entries (like Java's File class) and promises instead of the old callbacks. This way, you don't have to spend your time concatenating paths and manually filtering files. Here's a little preview of what can be done:

let themesFolder = new Entry("./plugins/").d;
let themes = await themesFolder.list({ type: EntryType.DIRECTORY });

for (let themeFolder of themes) {
  const manifestFile = themeFolder.child('manifest.json');
  
  if (!await manifestFile.exists()) continue;

  const manifest = JSON.parse(await manifestFile.read('utf8'));
  const iconStream = themeFolder.child('icon.png').createReadStream();
  
  loadTheme(manifest.name, iconStream, themeFolder);
}

Setup

Download

npm install ooafs

Import / Require

import { Entry, File, Directory } from 'ooafs';

// Create a file wrapper
const file: File = new Entry("./path/file.txt");

Entry is a class, while File and Directory are interfaces implemented by this class. These interfaces can be used for a better type-safety

Usage

The library is completely typed, so as long as you use a relatively good editor like VSCode, you shouldn't have much problems finding the available methods and properties.

Examples

function backupNodeProject(project: Directory, backupFolder: Directory) {
    // `name` is the basename of the project folder
    const backup = backupFolder.child(project.name);

    project.copy(backup);

    // Delete 20Gb of useless data !
    backup.child("node_modules").remove();
}
import { Directory, EntryFilter } from 'ooafs';

const filter: EntryFilter = {
    extensions: ['.png', '.jpeg', '.jpg', '.bmp'],

    // Custom filtering function
    async filter(image) {
        return (await image.size()) > 1023;
    }
};

// const picturesDir: Directory = new Entry("pictures");
// is the same as:
const picturesDir = new Entry("pictures").d;
const images = await picturesDir.listRecursively(filter);

TypeScript support

ooafs in entirely written in TypeScript and thus, is completely typed. In addition to that, when you import the module, you can use two interfaces, File and Directory to mask out methods that are not related to files and directories, respectively:

import { Entry, File, Directory } from 'ooafs';

const file: File = new Entry("/path");

// This shows an error: File doesn't have a `list` method
file.list();

Instead of manually casting your Entry instance to one of the two interfaces, you can also use a specifically made getter:

import { Entry } from 'ooafs';

// Add `.f` behind the constructor expression
// file is now typed as `File`
const file = new Entry("/path").f;

// This shows an error: File doesn't have a `list` method
file.list();

Three are available: .e, .d and .f.

Bugs & Suggestions

If you notice any bug or have a suggestion, please tell me about it in the issues, it will help everyone!

Tests

Tests are created with mocha and asserted with chai.expect.

You can run the suite using

npm test

License

ooafs is licensed under the very permissive MIT License. You may use it for commercial projects if you comply to the license.