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

filetrek

v1.0.0

Published

Walk files asynchronously

Downloads

4

Readme

filetrek

install

npm install filetrek

Usage

var filetrek = require("filetrek");

var p = filetrek('./', function(name, stats, root){
    //do stuff
});

p.then(function(info){
    //info is an Array
    //info = [{name: "filename", stats: object, root: "root directory"}]
});

With options

var filetrek = require("filetrek"),
    options = {
        ignore: ["*script.js", /\mark.xml$/, "filename.html"],
        find: ["*.js", /\.xml$/, "filename.html"]
    };

var p = filetrek('./', options, function(name, stats, root, sub){
    //do stuff
});

p.then(function(info){
    //info is an Array
    //info = [{name: "filename", stats: object, root: "root directory"}]
});

Find and Ignore

options.find is used before options.ignore.

The find, and ignore options should be arrays of glob strings, instances of RegExp, or plain strings.

The glob string patterns are the same used in the minimatch module.

Plain strings will match up to the end of file names.

options.find

Returns all matched files.

options.ignore

Excludes matched files in the return.

Callback Parameters

name

The name of the file, or directory.

stats

A stats object as returned from fs.stats.

root

The original directory to be scanned.

sub

The whole name of the file path not including the root.

Recursion Recipe

var files = [],
    filetrek = require("filetrek");

function walkFiles(folder){

    return filetrek(folder, function(name, stats, root, sub){

        if(stats.isDirectory()){
            //The directory path is used to continue walking files.
            return path.join(root, name);
        }
        //Work with the files.
    });
}

walkFiles('./').then(function(info){
    console.log('done');
});

Note on the callback

You can also return a promise in the callback like this:

function walkFiles(folder){

    return filetrek(folder, function(name, stats, root){
        return promiseFactory();
    });
}

walkFiles('./').then(function(resultsOfAllPromiseFactoryPromises){});

~~The promises returned like this are passed to Promise.all.~~

Promises are done in series so operation order is preserved.

If there are other operations on the file name you want to do, and that operation returns a promise returning a promise in the callback might be what you want to do.

All values that aren't strings, or promises returned in the callback are no-ops.

Strings returned in the callback that aren't a directory will cause an error.

About

Walk directory contents.

filetrek returns a promise. After all files are walked the promise resolves.