diginext-utils
Version:
README.md
50 lines (49 loc) • 1.72 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.findFileByExt = exports.forEachFileByExt = void 0;
var path = require("path");
var fs = require("fs");
/**
* This is an alias of "findFileByExt()"
*/
const forEachFileByExt = (base, ext, cb) => {
var walk = function (directoryName) {
try {
fs.readdir(directoryName, function (e, files) {
if (e) {
console.log("Error: ", e);
return;
}
files.forEach(function (file) {
var fullPath = path.join(directoryName, file);
fs.stat(fullPath, function (e, f) {
if (e) {
console.log("Error: ", e);
return;
}
if (f.isDirectory()) {
walk(fullPath);
}
else {
if (fullPath.toLowerCase().indexOf(ext.toLowerCase()) > -1) {
if (cb)
cb(fullPath);
}
}
});
});
});
}
catch (error) {
console.log("error", error);
}
};
walk(base);
};
exports.forEachFileByExt = forEachFileByExt;
/**
* This is an alias of "forEachFileByExt()"
*/
exports.findFileByExt = exports.forEachFileByExt;
const fileExt = { findFileByExt: exports.findFileByExt, forEachFileByExt: exports.forEachFileByExt };
exports.default = fileExt;