https://github.com/seangarner/slurpdir
require-dir for all file types
https://github.com/seangarner/slurpdir
Last synced: about 2 months ago
JSON representation
require-dir for all file types
- Host: GitHub
- URL: https://github.com/seangarner/slurpdir
- Owner: seangarner
- License: mit
- Created: 2016-02-16T22:45:51.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-12-20T23:51:09.000Z (over 7 years ago)
- Last Synced: 2025-03-22T03:48:12.638Z (2 months ago)
- Language: JavaScript
- Size: 26.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# slurpdir
[](https://travis-ci.org/seangarner/slurpdir)
Read a directory tree structure and parse contents of files into js object. Think require-dir for
all file types (bring your own parser).## example
```js
const ini = require('ini');
const yaml = require('yaml');
const slurpdir = require('slurpdir');let args = {
dir: __dirname,
recursive: true,
parsers: {
ini: (input) => ini.parse(input.data.toString()),
yaml: (input) => yaml.eval(input.data.toString())
}
};
new slurpdir.Slurp({dir, recursive: true})
.on('file', (name, data, path) => {
console.log(name, Object.keys(data));
})
.once('end', () => console.log('done!'););
```## callback
There's also a callback interface.
```js
slurpdir(__dirname, {recursive: true}, (err, tree) => {
console.log(Object.keys(tree));
});
```## sync
Need sync? Ok.
```js
let tree = slurpdir.sync(__dirname, {recursive: true});
console.dir(tree);
```## a note on the js parser
When running in async mode and parsing javascript files slurp will actually use node's `require` to
parse which means that it's not actually async. If you check the source for `parsers.js` you will
find a couple of commented parsers for js which do enable async parsing of js, however both methods
have caveats.