Skip to content

Instantly share code, notes, and snippets.

@cuipengfei
Last active December 31, 2015 03:39
Show Gist options
  • Save cuipengfei/7929452 to your computer and use it in GitHub Desktop.
Save cuipengfei/7929452 to your computer and use it in GitHub Desktop.
MAKE IT MODULAR
var filterListModule = require('./filterListModule');
var dir = process.argv[2];
var postFix = process.argv[3];
filterListModule(dir, postFix, function (err, filteredList) {
filteredList.forEach(function (fileName) {
console.log(fileName);
});
});
var fs = require('fs');
module.exports = function (dir, postFix, callBack) {
String.prototype.endsWith = function (suffix) {
return this.indexOf(suffix, this.length - suffix.length) !== -1;
};
fs.readdir(dir, function (err, list) {
if (err) {
return callBack(err);
}
var filteredList = list.filter(function (fileName) {
return fileName.endsWith("." + postFix);
});
callBack(null, filteredList);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment