ooafs
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:
;;for of themes
Setup
Download
npm install ooafs
Import / Require
; // Create a file wrapperconst file: File = "./path/file.txt";
Entry
is a class, whileFile
andDirectory
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
; ; // const picturesDir: Directory = new Entry("pictures");// is the same as:;;
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:
; ; // This shows an error: File doesn't have a `list` methodfile.list;
Instead of manually casting your Entry
instance to one of the two interfaces, you can also use a specifically made getter:
; // Add `.f` behind the constructor expression// file is now typed as `File`; // This shows an error: File doesn't have a `list` methodfile.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.