directory-to-object
v1.1.1
Published
Analyze a directory structure and return a `json` representation.
Downloads
13
Maintainers
Readme
directory-to-object
Analyze a directory structure and return a json
representation. Expects a flat
folder structure with either files or directories.
Installation
$ npm install directory-to-object
Usage
const dto = require('directory-to-object')
const path = require('path')
dto(path.resolve('./test'), (err, res) => console.log(res))
// {
// fooDir: [file1, file2, file3],
// barDir: [file4, file5, file6]
// }
API
dto(opts|path, callback)
dto(path.resolve('./test'), (err, res) => console.log(res))
// `noDot` ignores files which have a leading `.`
// in the filename.
const opts = {noDot: true, path: path.resolve('./test')}
dto(opts, (err, res) => console.log(res))
Why?
When parsing several directories of files it's nice to just have to provide a path rather than creating an index object manually. This is useful for creating static sites out of markdown files.
See Also
- directory-to-json - write a directory to a JSON file