1.4.0 • Published 7 years ago

walkitout v1.4.0

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

walkitout

build status codecov Code Climate Build status

Run a callback, asynchronously, on all filepaths in a directory tree

Usage

var walkitout = require('walkitout');

console.log("START WALK");

/**
 * @param {string}    path      path to walk
 * @param {function}  callback  callback handler
 * @param {function}  finish    optional finish handler
 * @param (object}    scope     optional handler scope
 * @param {function}  control   optional descent controller
 *
 * @returns {function}  ends walk and invokes finish
 */
var cancelWalk = walkitout('.',
  processLog, processComplete, null, controlDescent)

console.log("WALK STARTED");

function processLog(err, filename, done) {
  if (err) throw err;

  // skip: dotfiles, coverage, node_modules
  if (!/^(\.|coverage|node_modules)/
    .test(filename)) {
    console.log('FILE:', filename);
  }

  done();
}

function processComplete(cancelled) {
  // "cancelled" is true if cancelWalk() was invoked
  var info = '(' + (cancelled ? '' : 'not ') + 'cancelled)';
  console.log('COMPLETE: wrap up processing ' + info);
}

function controlDescent(dirname, dirPath, descend, skip, depth) {
  // skip directories named test,
  // only walk a max-depth of 2 levels
  (dirname === 'test' || depth === 2) ?
    skip() : descend();
}

Output:

START WALK
WALK STARTED
FILE: package.json
FILE: index.js
FILE: README.md
COMPLETE: wrap up processing (not cancelled)
1.4.0

7 years ago

1.3.3

7 years ago

1.3.2

7 years ago

1.3.1

7 years ago

1.3.0

7 years ago

1.2.3

7 years ago

1.2.2

7 years ago

1.2.1

7 years ago

1.1.3

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.0-4

7 years ago

1.0.0-3

7 years ago

1.0.0-2

7 years ago