0.1.2 • Published 7 years ago
require-dir-object v0.1.2
require-dir-object
Turn a directory into a tree of objects with the required version of each file.
Example
Given a directory of JavaScript files:
.
├── fish.js
├── folder_with_index
│ ├── index.js
│ └── other_file.js
├── index.js
├── other_file.js
└── other_folder
├── badger.js
└── badger_fish.js
index.js
module.exports = require("require-dir-object")(__dirname, {case: "camel"});
Would be equivalent to:
module.exports = {
fish: require("./fish"),
otherFile: require("./other_file"),
otherFolder: {
badger: require("./other_folder/badger"),
badgerFish: require("./other_folder/badger_fish")
},
folderWithIndex: require("./folder_with_index")
};
Options
Name | Description | Type | Example | Default |
---|---|---|---|---|
case | Converts file naming method | string | {case: "camel"} | null |
depth | Limit sub-directory search depth | int | {depth: 3} | Number.MAX_VALUE |
exclude | Exclude files at a specific path | string or array | {exclude: "fish.js"} | [] |
ext | Search for a specific extension | string | {ext: ".xml"} | ".js" |
func | Call a function on found file | function | {ext: fs.readFileSync} | require |
Available case conversions are camel
, snake
, kebab
, capitalize
.
Notes
- Every folder is turned into a sub-object.
- If a folder has an
index
it will load that in favor of folder contents.
License
MIT