file-routing-expressjs
Version:
A dependency-free, flexible, system-based file routing for Express.
30 lines • 1.01 kB
JavaScript
import fs from "fs";
import { JAVASCRIPT_FILES_EXTENSION_REGEX } from "../constants/regex";
import { EXPRESS_METHODS_ARRAY } from "../constants";
function functionIsRequestHandler(handler) {
return typeof handler === "function" && [2, 3].includes(handler.length);
}
function functionIsExceptionHandler(handler) {
return typeof handler === "function" && handler.length === 4;
}
function filenameIsJSorTS(filename) {
return !!filename.match(JAVASCRIPT_FILES_EXTENSION_REGEX);
}
function pathExistsAndIsFile(path) {
return fs.existsSync(path) && fs.statSync(path).isFile();
}
function fileExistsAndIsJSorTS(filePath) {
return !!filePath.match(JAVASCRIPT_FILES_EXTENSION_REGEX) && pathExistsAndIsFile(filePath);
}
function methodIsExpressMethod(method) {
return EXPRESS_METHODS_ARRAY.includes(method);
}
export {
fileExistsAndIsJSorTS,
filenameIsJSorTS,
functionIsExceptionHandler,
functionIsRequestHandler,
methodIsExpressMethod,
pathExistsAndIsFile
};
//# sourceMappingURL=validators.mjs.map