# @github-docs/data-directory

> Recursively load a directory of YAML, JSON, and Markdown files into a JavaScript object.

Latest version **1.2.0** (published 2020-02-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install @github-docs/data-directory
pnpm add @github-docs/data-directory
yarn add @github-docs/data-directory
bun add @github-docs/data-directory
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2020-02-14 |
| First published | 2019-11-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 9.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | sarahs, zeke |

## Links

- npm: https://www.npmjs.com/package/@github-docs/data-directory
- Repository: https://github.com/docs/data-directory
- Homepage: https://github.com/docs/data-directory#readme
- Issues: https://github.com/docs/data-directory/issues
- npm.io page: https://npm.io/package/@github-docs/data-directory

## Dependencies (2)

- [lodash](https://npm.io/package/lodash.md) ^4.17.15
- [walk-sync](https://npm.io/package/walk-sync.md) ^2.0.2

## Recent versions

- 1.2.0 (latest) — 2020-02-14
- 1.1.1 — 2020-02-01
- 1.0.0 — 2019-11-17

## README

# 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-directory
```

## Usage

Given the following file tree:

```
$ tree data
data
├── bar.yaml
├── foo.json
└── nested
    └── baz.md
```

and 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:

```js
const path = require('path')
const dataDirectory = require('@github-docs/data-directory')
const data = dataDirectory(path.join(__dirname, 'data'))
```

will return this object:

```js
{
  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])`

- `directory` String (required) - Full path to the directory to read.
- `options` Object
  - `extensions` Array - A case-insensitive array of filenames to load. Defaults to `['.json', '.md', '.markdown', '.yaml', '.yml']`
  - `ignorePatterns` Array - Filename patterns to ignore. Every value in the array must be a regular expression. Defaults to `[/README\.md$/i]`. To include `README.md` files in your data object, specify an empty array: `[]`.
  - `preprocess` Function - 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 }`

---
_Source: https://npm.io/package/@github-docs/data-directory · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
