sussy-util
Version:
Util package made by me
25 lines (24 loc) • 994 B
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = __importDefault(require("fs"));
/**
* It takes a directory path as a string, and returns an object with the directory's contents as
* properties.
* @param {string} dir - string - The directory to read from
* @returns An object with the content of the directory.
*/
const getContentFromDirectory = (dir) => {
const result = {};
fs_1.default.readdirSync(dir).forEach((path) => {
if (fs_1.default.lstatSync(`${dir}/${path}`).isDirectory()) {
return (result[path] = getContentFromDirectory(`${dir}/${path}`));
}
// eslint-disable-next-line @typescript-eslint/no-require-imports
result[path.replace('.js', '')] = require(`${dir}/${path}`);
});
return result;
};
exports.default = getContentFromDirectory;