# merge-files-content

> Node.JS utility function for loading multiple files as one. Useful for project-wide configuration files

Latest version **0.1.5** (published 2020-07-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install merge-files-content
pnpm add merge-files-content
yarn add merge-files-content
bun add merge-files-content
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 0.1.5 |
| Published | 2020-07-10 |
| First published | 2020-05-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 12.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Federico Vazquez |
| Maintainers | frondor |
| Keywords | load-config, config, multiple, files, read, dir |

## Links

- npm: https://www.npmjs.com/package/merge-files-content
- Repository: https://github.com/Frondor/merge-files-content
- Homepage: https://github.com/Frondor/merge-files-content#readme
- Issues: https://github.com/Frondor/merge-files-content/issues
- npm.io page: https://npm.io/package/merge-files-content

## Dependencies (2)

- [jest](https://npm.io/package/jest.md) ^25.5.4
- [lodash](https://npm.io/package/lodash.md) ^4.17.16

## Alternatives

- [unionfs](https://npm.io/package/unionfs.md) — 2.2M weekly downloads
- [path-starts-with](https://npm.io/package/path-starts-with.md) — 35.9K weekly downloads
- [redzip](https://npm.io/package/redzip.md) — 1.2K weekly downloads
- [vscode-anymatch](https://npm.io/package/vscode-anymatch.md) — 848 weekly downloads
- [@ledgerhq/coin-filecoin](https://npm.io/package/@ledgerhq/coin-filecoin.md) — 793 weekly downloads

## Recent versions

- 0.1.5 (latest) — 2020-07-10
- 0.1.3 — 2020-05-03
- 0.0.2 — 2020-05-02

## README

# merge-files-content [![Build Status](https://travis-ci.com/Frondor/merge-files-content.svg?branch=master)](https://travis-ci.com/Frondor/merge-files-content) [![codecov](https://codecov.io/gh/Frondor/merge-files-content/branch/master/graph/badge.svg)](https://codecov.io/gh/Frondor/merge-files-content)

Node.JS utility function to recursively load multiple directories and files as one. Useful for project-wide configuration files

## Table of contents

1. [Installation](#installation)
2. [Usage](#usage)
2. [API](#api)

## Installation

```
npm i merge-files-content
```
or

```
yarn add merge-files-content
```

## Usage

This module exports a single function which receives two arguments: the file(s) and/or directories full paths, and a (optional) settings object.

### Example

Let's say we have a `src/config` directory with 3 files exporting objects:
  - /database.js
  - /storage.json
  - /nested/file.js

> **Note:** In this case we have `.js` and `.json` files, but you can use any file extension as long as its supported by `require()`.
>
> If the directory contains unsupported module types, the program shall crash.

```js
/**
 * /src/config/database.js
 */
module.exports = {
  PORT: 3000
}
```
_/src/config/storage.json_
```json
{
  "driver": "s3"
}
```

```js
/**
 * /src/config/database.js
 */
module.exports = 'Hello World!'
```

```js
/**
 * /index.js
 */
const mfc = require('merge-files-content');
const path = require('path');

const config = mfc(path.resolve('src/config'));

config.database.PORT // 3000
config.storage.driver // s3
config.nested.file // Hello World!
```

## API

```ts
mfc(AbsolutePaths, MfcSettings?): Object
```

### AbsolutePaths

Either a single or an array of absolute paths. They can point either to a file, a dir, or a mix of boths.

### MfcSettings

An optional object of settings

#### MfcSettings.useFilenames (default: true)

When `true`, the file exported contents will live under a key (namespace) equal to the camelCased version of the file name (without its extension).

> **Note**: this option is ignored if you're loading a single **file** instead of a directory. In that case, mfc behaves just like `require()`.

#### MfcSettings.maxDepth (default: 3)

The max level of deepness you want the script to look for files.

---
_Source: https://npm.io/package/merge-files-content · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
