0.1.2 • Published 7 years ago

require-dir-object v0.1.2

Weekly downloads
591
License
MIT
Repository
github
Last release
7 years ago

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

NameDescriptionTypeExampleDefault
caseConverts file naming methodstring{case: "camel"}null
depthLimit sub-directory search depthint{depth: 3}Number.MAX_VALUE
excludeExclude files at a specific pathstring or array{exclude: "fish.js"}[]
extSearch for a specific extensionstring{ext: ".xml"}".js"
funcCall a function on found filefunction{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