Skip to content

pearlshare/require-dir-object

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

require-dir-object

circleci

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •