lib/js/PagesProbe.js
function(dirs, callback) {
      var t = this,
          numLeft = dirs.length,
          fileRegexp = /.json$/,
          trimmed = [];

      // Already trimmed
      if (numLeft === 0) {
        return callback(null, dirs);
      }

      // Process each directory
      dirs.forEach(function(dir) {
        t.hasContents(dir.path, fileRegexp, function(error, hasContents) {
          if (error) {
            numLeft = 0;
            return callback(error);
          }
          delete dir.path;
          if (hasContents) {
            trimmed.push(dir);
          }
          if (--numLeft === 0) {
            return callback(null, trimmed);
          }
        });
      });
    }
function(dirs, callback) {
      var t = this,
          numLeft = dirs.length,
          fileRegexp = /.json$/,
          trimmed = [];

      // Already trimmed
      if (numLeft === 0) {
        return callback(null, dirs);
      }

      // Process each directory
      dirs.forEach(function(dir) {
        t.hasContents(dir.path, fileRegexp, function(error, hasContents) {
          if (error) {
            numLeft = 0;
            return callback(error);
          }
          delete dir.path;
          if (hasContents) {
            trimmed.push(dir);
          }
          if (--numLeft === 0) {
            return callback(null, trimmed);
          }
        });
      });
    }
function ( dirs , callback ) { var t = this , numLeft = dirs . length , fileRegexp = / .json$ / , trimmed = [ ] ; // Already trimmed if ( numLeft === 0 ) { return callback ( null , dirs ) ; } // Process each directory dirs . forEach ( function ( dir ) { t . hasContents ( dir . path , fileRegexp , function ( error , hasContents ) { if ( error ) { numLeft = 0 ; return callback ( error ) ; } delete dir . path ; if ( hasContents ) { trimmed . push ( dir ) ; } if ( -- numLeft === 0 ) { return callback ( null , trimmed ) ; } } ) ; } ) ; }
Trim directories that have no content

This accepts an array of objects, where each object must have a 'path' element.
If no content is at the path, the object will be trimmed from the array.

The path element will be removed after checking.

@method trimDirs
@param dirs {Object} An object that contains a 'path' element
@param callback {function(error, trimmed)} Called when complete (or error)
Trim directories that have no content