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

walk-folder-tree

v1.0.1

Published

Recursively walk file system tree and callback on every file

Downloads

71

Readme

walk-folder-tree.js

Recursively walk file system tree and callback on every file

Current status

NPM version Build Status Dependency Status Dev dependency Status Coverage Status

API is stable.

Usage

Installation

npm install walk-folder-tree

Loading

var walk = require('walk-folder-tree');

walk(path [, options] [, fn])

Recursively walks through the directory tree from path downwards, calling fn on every file and directory.

fn is called with the single argument params. params is of the form:

{
    path: /* path relative to root path */,
    fullPath: /* full path of file */,
    name: /* filename of file */,
    directory: /* true if is a directory */,
    stat: /* stat object for the file (as returned from `fs.stat()`) */
}

walk() returns a promise.

walk('/path/to/folder', function(params, cb) {
    console.log('Found file: ', params.path);
    cb();
}).then(function() {
    // do something else
});

walk(options)

path and fn can also be provided as attributes of options

walk({
    path: '/path/to/folder',
    fn: function(params, cb) {
        console.log('Found file: ', params.path);
        cb();
    }
});

fn

fn can alternatively be a promise-returning function. Just leave off the callback argument.

walk('/path/to/folder', function(params) {
    return Promise.resolve().then(function() {
        console.log('Found file: ', params.path);
    });
})

fn can also be a generator. If so, it is wrapped using co so you can yield promises.

walk('/path/to/folder', function*(params) {
    yield Promise.resolve();
    console.log('Found file: ', params.path);
})

Options

recurse

When true, recurses through subfolders and sub-subfolders, examining an entire tree. Set to false to ignore subfolders. Defaults to true.

walk('/path/to/folder', { recurse: false }, fn);

filterFiles

A regular expression for what files to include. Defaults to /^[^.]/ (i.e. ignore files starting with .)

// include all files
walk('/path/to/folder', { filterFiles: /^.*$/ }, fn);

filterFolders

A regular expression for what folders to iterate into. Defaults to /^[^.]/ (i.e. process all folders except those beginning with .)

// Process all folders except those starting with `.` or `_`
walk('/path/to/folder', { filterFolders: /^[^\._]/ }, fn);

return

If set to true, returns an array of all files and folders found. Defaults to false.

walk('/path/to/folder', { return: true }).then(function(files) {
    // files is array of params object for each file
});

sort

Function to sort files in each folder before processing.

walk('/path/to/folder', {
    sort: function(a, b) {
        if (a > b) return -1;
        if (a < b) return 1;
        return 0;
    }
}, fn);

Tests

Use npm test to run the tests. Use npm run cover to check coverage.

Changelog

See changelog.md

Issues

If you discover a bug, please raise an issue on Github. https://github.com/overlookmotel/walk-folder-tree/issues

Contribution

Pull requests are very welcome. Please:

  • ensure all tests pass before submitting PR
  • add an entry to changelog
  • add tests for new features
  • document new functionality/API additions in README