<commit_before># modular-config

A simplistic library for synchronously loading read-only configurations from
a variety of file formats.

For many projects, the [config](https://github.com/lorenwest/node-config)
library is sufficient for all configuration needs.  But if you like other
formats beyond JSON, or prefer less automatic loading behavior, this
package offers another path.  Initially supporting TOML and JSON, other
formats can be added by just registering a parser.


## Usage

```
npm install modular-config
```

```
// Without an absolute path, process.cwd() + '/config' assumed
var configA = require('modular-config').load('configA.toml');

// Absolute paths may also be used
var configB = require('modular-config').load('/path/to/configC');

// Or you can set another configuration search directory
var conf = require('modular-config');
conf.directory('/var/tmp');
var configC = conf.load('oddly_placed.toml');
```


## How It Works

This library is structured on the idea that all configurations will be read from disk
synchronously at application start time.  Most of the time this is an acceptable
assumption, since many things won't happen until configuration information is
available.

When a configuration is successfully loaded, it is turned into an object tree, made read-only,
cached, then returned.  Subsequent requests for the same file will returned the previously
parsed configuration.  This means that configurations cannot be reloaded without restarting
the application.

Configuration files may be loaded with an absolute file path or by file name in a lookup
in a configurable directory (which defaults to `process.cwd() + '/config'`).

All errors throw exceptions.  Though this is a bit extreme, it fits with the use case
of upfront loading.  If configuration information isn't available, it is assumed that
either defaults will manually be supplied or that the application cannot reasonably
start.

Out of the box only TOML (`.toml`) and JSON ('.json', '.js') configuration formats are
supported.  Other formats may easily be added via the `register()` function.  An
extension and parser function must be supplied, with the latter returning the parsed
object (from raw string input).<commit_msg>More README updates, for clarity.<commit_after># modular-config

A simplistic library for synchronously loading read-only configurations from
a variety of file formats.

For many projects, the [config](https://github.com/lorenwest/node-config)
library is sufficient for all configuration needs.  But if you like other
formats beyond JSON, or prefer less automatic loading behavior, this
package offers another path.


## Usage

```
npm install modular-config
```

```
// With just a file name, lookups will occur at process.cwd() + '/config'
var configA = require('modular-config').load('application.toml');


// Absolute paths are supported
var configB = require('modular-config').load('/path/to/file.json');


// Or you can set another configuration search directory
var conf = require('modular-config');
conf.directory('/var/tmp');
var configC = conf.load('oddly_placed.toml');


// File extensions are required unless you specify a parser
var configD = require('modular-config').load('generic', 'toml');
```


## How It Works

This library is structured on the idea that all configurations will be read from disk
synchronously at application start time.  This is often an acceptable assumption, since many 
things won't happen until configuration information is available.

When a configuration is successfully loaded, it is turned into an object tree, made read-only,
cached, then returned.  Subsequent requests for the same file will returned the previously
parsed configuration.  This means that configurations cannot be reloaded without restarting
the application.

Configuration files may be loaded with an absolute file path or by file name in a
configurable lookup directory (which defaults to `process.cwd() + '/config'`).

All errors throw exceptions.  Though this is a bit extreme, it fits with the use-case
of upfront loading.  If configuration information isn't available, it is assumed that
the application cannot reasonably start.

Out of the box, TOML (`.toml`) and JSON (`.json`, `.js`) configuration formats are
supported.  Other formats may easily be added via the `register()` function.  An
extension and parser function must be supplied, with the latter returning the parsed
object (from raw string input).
{'fraction_non_alphanumeric': 0.07668161434977579, 'fraction_numerical': 0.0, 'mean_word_length': 4.778497409326425, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3238538', 'n_tokens_mistral': 1110, 'n_tokens_neox': 1075, 'n_words': 580}