Skip to content

Instantly share code, notes, and snippets.

@joshholt
Created March 11, 2010 05:07
Show Gist options
  • Save joshholt/328845 to your computer and use it in GitHub Desktop.
Save joshholt/328845 to your computer and use it in GitHub Desktop.
/*#!/usr/bin/env node*/
// ..........................................................
// REQUIRES
//
var Seed = require('seed');
var Co = Seed.require('seed:co');
// ..........................................................
// FUNCTIONS
//
Co.filteredGlob = function(path,filter,done) {
if (!filter || !path || typeof done !== "function") {
throw new Error('Invalid Parameters Passed' );
}
Co.fs.glob(path, function(err,results) {
//if(err) throw new Error(inspect(error));
if (err) return done(err);
var filteredFiles = results.filter(function(result) {
//if (err) throw new Error(inspect(error));
var regex = new RegExp(filter);
return regex.test(result);
});
return done(null,filteredFiles);
});
};
// ..........................................................
// TESTS
//
var filesPath = '/Users/someuser/.seeds/packages/underscore-0.6.0/';
var filterExp = '[^.js]$';
Co.filteredGlob(filesPath, filterExp, function(err,success){
if (err) throw new Error(Co.sys.inspect(err));
Co.sys.puts(Co.sys.inspect(success));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment