1.2.0 • Published 6 years ago
@github-docs/data-directory v1.2.0
data-directory
A Node.js module to recursively load a directory of YAML, JSON, and Markdown files into a JavaScript object.
Installation
npm install @github-docs/data-directoryUsage
Given the following file tree:
$ tree data
data
├── bar.yaml
├── foo.json
└── nested
└── baz.mdand the following content in each file:
$ cat foo.json
{"meaningOfLife": 42}
$ cat bar.yaml
another_markup_language: 'yes'
$ cat nested/baz.md
I am markdown!then running this code:
const path = require('path')
const dataDirectory = require('@github-docs/data-directory')
const data = dataDirectory(path.join(__dirname, 'data'))will return this object:
{
bar: { another_markup_language: 'yes' },
foo: { meaningOfLife: 42 },
nested: { baz: 'I am markdown!' }
}API
This module exports a single synchronous function dataDirectory that returns
an Object.
dataDirectory(directory, [options])
directoryString (required) - Full path to the directory to read.optionsObjectextensionsArray - A case-insensitive array of filenames to load. Defaults to['.json', '.md', '.markdown', '.yaml', '.yml']ignorePatternsArray - Filename patterns to ignore. Every value in the array must be a regular expression. Defaults to[/README\.md$/i]. To includeREADME.mdfiles in your data object, specify an empty array:[].preprocessFunction - A function that can be used to modify each loaded file's content before it's added to the data object. Default is a no-op function that return the unmodified content:(content) => { return content }