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

fs-utilities

v1.1.1

Published

utility module for interacting with the file system e.g. asynchronously retreiving list of folders

Downloads

23

Readme

Installation

$ npm install fs-utilities

Usage

var fs_utils = require('fs-utilities')

    fs_utils.getSubfolders( __dirname, function ( err, folders ){
    if( err ) throw err;

    folders.forEach( folder, ... );
});

API Overview

checkIfIsDirectory( directoryPath, callback )

Asynchronously tests if the specified file is a directory.

Arguments

  • directoryPath - fullpath to file which should be tested
  • callback(err, directoryPath) - will be executed after test finished. If directoryPath is not a folder, second callback argument will be undefined.

Example

fs_utils.checkIfIsDirectory( "fullFilePath" , function ( err, directory ){
    if( err ) {
        // "fullFilePath" is not a directory
    } else {
        console.log( "'" + directory + "' is a directory" );
    }
});

checkIfIsDirectorySync( directoryPath )

Synchron function to test if the specified file is a directory.

Arguments

  • directoryPath - fullpath to file which should be tested

Example

if( fs_utils.checkIfIsDirectorySync( "fullFilePath" ) ){
    console.log( "'fullFilePath' is a directory" );
}

getSubfolders( directoryPath, callback )

Asynchron function which will pass an array containing all subfolders of the given directory to the also passed callback function.

Arguments

  • directoryPath - path to look for subfolders
  • callback(err, subFolderList) - will be executed after all subfolders have been detected. If case of an error, the search will be aborted and the second argument of the callback function will be undefined.

Example

fs_utils.getSubfolders( __dirname , function ( err, folders ){
    if( err ) throw err;

    console.log( "found following subfolders: " + folders );
});

getSubfoldersSync( directoryPath )

Synchronously generates and returns an array containing all subfolders of the given directory.

Arguments

  • directoryPath - path to look for subfolders

Example

var folders = fs_utils.getSubfoldersSync( __dirname );
console.log( "found following subfolders: " + folders );

traverseAllSubFolders( directoryPath, callback, [opt_excludedDirectories, [opt_finishedCallback]] )

Asynchron function which will recursively traverse all subfolers.

Arguments

  • directoryPath - path from where to start traversing
  • callback(subFolder) - will be called for each traversed subfolder
  • opt_excludedDirectories - list of folders that will be skiped
  • opt_finishedCallback - function that is called after all subfolders have been traversed or an error occured

Example

function callForEachSubfolder( folder ){
    console.log( "currently traversing folder '" + folder + "'" );
}

function callOnFinishedTraversing( err ){
    if( err ) throw err;

    console.log( "finished traversing all subfolders" );
}

var excludedFolders = ["excludedFolder0", "excludedFolder1", ...];
fs_utils.traverseAllSubFolders( __dirname,
                                callForEachSubfolder,
                                excludedFolders,
                                callOnFinishedTraversing );

traverseAllSubFoldersSync( directoryPath, callback, [opt_excludedDirectories] )

Synchronous function which will recursively traverse all subfolers.

Arguments

  • directoryPath - path from where to start traversing
  • callback(subFolder) - will be called for each traversed folder
  • opt_excludedDirectories - list of folders that will be skiped

Example

function callForEachSubfolder( folder ){
    console.log( "currently traversing folder '" + folder + "'" );
}

var excludedFolders = ["excludedFolder0", "excludedFolder1", ...];
fs_utils.traverseAllSubFoldersSync( __dirname,
                                    callForEachSubfolder,
                                    excludedFolders );
console.log( "finished traversing all subfolders" );

Tests

To run the test suite, first install the dependencies, then run npm test:

$ npm install
$ npm test

Coverage

To run a code coverage analysis execute following commands:

$ npm install
$ npm run coverage

JSDoc

To generate a complete API documentation using JSDoc execute following commands:

$ npm install
$ npm run jsdoc