superfs

Better file system support

Usage no npm install needed!

<script type="module">
  import superfs from 'https://cdn.skypack.dev/superfs';
</script>

README

SuperFS

Build Status

Better filesystem support for Node.js

Dealing with files

const SuperFS = require('super-fs')
const fl = SuperFS.file('foo/bar.json')

// read a file content.then(file => {
  // Files is an array of files of `foo/`
});
const SuperFS = require('super-fs');
SuperFS.readDir('foo/').then(files => {
  // Files is an array of files of `foo/`
});

Read file

const SuperFS = require('super-fs');
SuperFS.readFile('foo/bar.js', 'FooBar').then(content => {
  // content is an buffer
});

// or

const fl = SuperFS.file('foo/bar.js');
await fl.write('FooBar');

Write file

const SuperFS = require('super-fs');
SuperFS.writeFile('foo/bar.js', 'FooBar').then(files => {
  // Files is an array of files of `foo/`
});

// or

const file = SuperFS.file('foo/bar.js');
await file.write('FooBar');

Copy dir

SuperFS.copyDir('foo/', 'bar/').then(files => {
  // Files is an array of files of `foo/`
});

Watch dir

const SuperFS = require('super-fs');
SuperFS.watch('foo/bar.js', handlerFn).then(files => {
  // Files is an array of files of `foo/`
});

// or

const file = SuperFS.file('foo/bar.js');
await file.watch(handlerFn);

file/dir exists

const SuperFS = require('super-fs');
await SuperFS.exists('foo/bar.js');

Options

ignore - Ignore files & dirs

The ignore flag is a pattern or an array of pattern. If any of the pattern matches a path, the item gets ignored.

* Matches anything exept a / ? matches any character once exept a / ** Matches any anything, including / [a-zA-Z] can be used to match a range of characters.

A pattern like *.js would match all .js files A pattern like test/**/*.js would match all .js files under test/ Patterns start matching from the root. test.js would match test.js but not a/test.js. Use */test.js or **/test.js instead.

Filepattern format

The slash / is used as the directory separator. Separators may occur at the beginning, middle or end of the .gitignore search pattern.

If there is a separator at the beginning or middle (or both) of the pattern, then the pattern is relative to the directory level of the particular .gitignore file itself. Otherwise the pattern may also match at any level below the .gitignore level.

If there is a separator at the end of the pattern then the pattern will only match directories, otherwise the pattern can match both files and directories.

For example, a pattern doc/frotz/ matches doc/frotz directory, but not a/doc/frotz directory; however frotz/ matches frotz and a/frotz that is a directory (all paths are relative from the .gitignore file).

An asterisk "*" matches anything except a slash. The character "?" matches any one character except "/". The range notation, e.g. [a-zA-Z], can be used to match one of the characters in a range. See fnmatch(3) and the FNM_PATHNAME flag for a more detailed description.

Two consecutive asterisks ("**") in patterns matched against full pathname may have special meaning:

A leading "**" followed by a slash means match in all directories. For example, "**/foo" matches file or directory "foo" anywhere, the same as pattern "foo". "**/foo/bar" matches file or directory "bar" anywhere that is directly under directory "foo".

A trailing "/**" matches everything inside. For example, "abc/**" matches all files inside directory "abc", relative to the location of the .gitignore file, with infinite depth.

A slash followed by two consecutive asterisks then a slash matches zero or more directories. For example, "a/**/b" matches "a/b", "a/x/b", "a/x/y/b" and so on.

Other consecutive asterisks are considered regular asterisks and will match according to the previous rules.