# js-dir-into-json

> Recursively loads content of found JavaScript and JSON files in given directory into a single structured object

Latest version **2.7.1** (published 2021-02-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install js-dir-into-json
pnpm add js-dir-into-json
yarn add js-dir-into-json
bun add js-dir-into-json
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.7.1 |
| Published | 2021-02-07 |
| First published | 2020-06-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 4 |
| Unpacked size | 26.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Martin Rafael Gonzalez |
| Maintainers | tin_r |
| Keywords | deep, deeply, recursive, recursively, load, list, javascript, json, file, folder, structure |

## Links

- npm: https://www.npmjs.com/package/js-dir-into-json
- Repository: https://github.com/devtin/js-dir-into-json
- Homepage: https://github.com/devtin/js-dir-into-json#readme
- Issues: https://github.com/devtin/js-dir-into-json/issues
- npm.io page: https://npm.io/package/js-dir-into-json

## Dependencies (4)

- [lodash](https://npm.io/package/lodash.md) ^4.17.20
- [deepmerge](https://npm.io/package/deepmerge.md) ^4.2.2
- [deep-list-dir](https://npm.io/package/deep-list-dir.md) ^1.4.4
- [is-plain-object](https://npm.io/package/is-plain-object.md) ^5.0.0

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 2.7.1 (latest) — 2021-02-07
- 2.7.0 — 2021-01-27
- 2.6.0 — 2020-11-11
- 2.5.1 — 2020-09-03
- 2.5.0 — 2020-09-03
- 2.4.1 — 2020-08-24
- 2.3.0 — 2020-08-11
- 2.2.0 — 2020-08-11
- 2.1.0 — 2020-08-04
- 2.0.1 — 2020-07-29
- 2.0.0 — 2020-06-07
- 1.0.0 — 2020-06-07

## README

# js-dir-into-json
> Recursively loads content of found JavaScript and JSON files in given directory into a single structured object

<a href="https://www.npmjs.com/package/js-dir-into-json" target="_blank"><img src="https://img.shields.io/npm/v/js-dir-into-json.svg" alt="Version"></a>
[![tests](https://github.com/devtin/js-dir-into-json/workflows/test/badge.svg)](https://github.com/devtin/js-dir-into-json/actions)

This module recursively loads exported content of all `*.js` and `*.json` files (configurable via `extensions`) found in
given `directory` using given `fileLoader` (defaults to `require`) creating a single object that preservers the file
structure of the loaded content as the property path, transforming the file and folder names using given
`pathTransformer` function (defaults to
lodash→<a href="https://lodash.com/docs/4.17.15#camelCase" target="_blank">camelCase</a>).

Useful to split what could be a big configuration object into a file / folder structure.

## Example

Take the following file structure:

```
<directory>
├── users/
│   ├── index.js
│   ├── maria.json
│   ├── martin.js
│   └── maria.json
└── some-config.json
```

**users/index.js**
```js
module.exports = {
  'some-guy': 'Un-altered'
}
```

**users/maria.json**
```json
{
  "name": "Maria",
  "email": "maria@hotmail.com"
}
```

**users/martin.js**
```js
module.exports = {
  name: "Martin",
  email: "tin@devtin.io"
}
```

**some-config.js** (see esm support below)
```js
export default {
  plugins: [
    'plugin-1',
    'plugin-2'
  ]
}
```

And the following script:

```js
const { jsDirIntoJson } = require('js-dir-into-json')

jsDirIntoJson('<directory>',
  {
    // extensions: ['*.js', '*.json'], // minimatch or RegExp
    // pathTransformer: default to lodash camelCase
    // fileLoader: default to require (or fileLoader = require('esm')(module) for esm support)
  }
).then(obj => {
  t.deepEquals(obj, {
    "users": {
      "maria": {
        "name": "Maria",
        "email": "maria@hotmail.com"
      },
      "martin": {
        "name": "Martin",
        "email": "tin@devtin.io"
      },
      "olivia": "thats me!",
      "some-guy": "Un-altered"
    },
    "someConfig": {
      "plugins": [
        "plugin-1",
        "plugin-2"
      ]
    }
  });
});
```

* * *

### License

[MIT](https://opensource.org/licenses/MIT)

&copy; 2020-present Martin Rafael Gonzalez
<tin@devtin.io>

---
_Source: https://npm.io/package/js-dir-into-json · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
