dir-obj
Create an object from a directory tree.
dir-obj
creates an object with keys for each directory (by name).
All files within a directory that can be required (.js
or .json
) are added to the directory object, using the base filename as the key and require('file.js')
as the value.
This is useful for things like loading test fixture data.
API
You can also customize how dir-obj
processes the directory tree
const fixtures = dirObj;
Example
Using the default options:
/*directory structure: fixtures ok success.json responses success.json*/ const path = ;const dirObj = ;const fixtures = dirObj; ;
Loading SQL files:
// Get an object where the value of each key is a string loaded from each SQL file const fixtures = dirObj;