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

fso

v2.7.0

Published

fso - FileSystemObject is a objective fs interface like Pathname(ruby)

Downloads

45

Readme

fso - FileSystemObject

npm npm license npm download total npm download by month dependencies Status devDependencies Status

Travis Build Status AppVeyor Build Status codecov.io Code Climate Codacy Badge Greenkeeper badge

fso - FileSystemObject is a objective fs interface like Pathname(ruby).

Installation

npm install fso

Usage

node.js:

var fso = require('fso').default;
var FileSystemObject = require('fso').FileSystemObject;

ES2015:

import fso, {FileSystemObject} from 'fso';

API

API Documents (with type annotations)

objective methods

constructor

var abc = new FileSystemObject("a", "b", "c");
abc.toString() === "a/b/c"

new / join

dir = fso.new('dir');
a = dir.new('a.txt');
a.writeFileSync('aaaaaa');

parent

dir = fso.new('dir');
p = dir.parent();
dir = p.new('dir');

children, childrenSync

dir = fso.new('dir');
files = dir.childrenSync();

childrenAll, childrenAllSync

dir = fso.new('dir');
files = dir.childrenAllSync();

filteredChildren, filteredChildrenSync, filteredChildrenAll, filteredChildrenAllSync

excepts = ["ignore_file", "path/to/ignore_directory"];
entries = target.filteredChildrenAllSync(excepts);
// Sync
excepts = (entry) => entry.isDirectorySync();
files = target.filteredChildrenAllSync(excepts); // childrenSync() minus directories
// Promise form condition also OK when Promise form call
excepts = (entry) => entry.isDirectory();
files = await target.filteredChildrenAll(excepts);
// callback form also OK when callback form call
excepts = (entry, callback) =>
  entry.isDirectory(
    (error, isDirectory) => callback(error, isDirectory)
  );
target.filteredChildrenAll(excepts, (error, files) => console.log(files.toString()));

path

path / toString

fooPath = fso.new('foo').path;
fooPath = fso.new('foo').toString();

'fs' API

Supports all the node.js 'fs' APIs that needs no first path argument.

method(...args, callback), methodSync(...args) and promise = method(...args)

one file args

fs.truncateSync('/path/to/file', 0);
// is
file = fso.new('/path/to/file');
file.truncateSync(0);

two file args

fs.rename('/path/to/file', 'newfile', callback);
// is
file = fso.new('/path/to/file');
file.remane('newfile', callback);

fd args

fd = fs.openSync('/path/to/file');
fs.ftruncateSync(fd, 0);
fs.close(fd);
// is
file = fso.new('/path/to/file');
file.openSync();
file.ftruncateSync(0);
file.close();

convenient additional

mkdirAll

fso.new('long/deep/path/to').mkdirAll().then(...);

mkdirp (= mkdirAll)

mkpath (= mkdirAll)

readdirAll

dir.readdirAllSync()
// results
['a.txt', 'aa', 'aa/a.txt', 'aa/b', 'aa/b/c.txt']

rmAll

await dir.rmAll('junk');

rmtree (= rmAll)

mergeDirectory

target.mergeDirectory(source);

copy:

target.rmAllSync();
target.mergeDirectorySync(source);

filteredMergeDirectory

excepts = ["ignore_file", "path/to/ignore_directory"];
target.filteredMergeDirectorySync(source, excepts);
excepts = (entry) => entry.path === "ignore_file" || entry.path === "path/to/ignore_directory";
target.filteredMergeDirectorySync(source, excepts);

isChildOf

dir.new("foo/bar").isChildOf(dir)

isParentOf

dir.isParentOf(dir.new("foo/bar"))

path methods

(property) delimiter

fso.delimiter; // ":" or ";"

(property) sep

fso.sep; // "/" or "\\"

(static) format

var entry = FileSystemObject.format({...});

parse

var parsedObject = fso.new("a").parse();

normalize

fso.new("a").normalize(); // same as fso.new("a")

basename

fso.new("a/b/c").basename(); // same as new FileSystemObject("c")

dirname

same as parent()

extname

fso.new("a/b/c.txt").extname(); // ".txt"

isAbsolute

fso.new("a/b/c.txt").isAbsolute() === true

relative

fso.new("a/b/c").relative(fso.new("a/d")); // same as new FileSystemObject("../d")
fso.new("/a/b/c").relative("/a/d"); // same as new FileSystemObject("../d")

resolve

fso.new("a/b/c").resolve("/") // same as new FileSystemObject("/a/b/c")

License

This is released under Zlib License.