Load
Loads a configuration file.
Installation
$ npm install app-etc-load
Usage
var load = ;
load( filename[, fmt] )
Loads a configuration file.
var config = ;// returns {...}
If provided a relative path, the filename is resolved relative to the current working directory.
var config = ;// returns {...}
The following configuration file formats (extensions) are supported (see the ./test/fixtures
directory for file examples):
- TOML:
*.toml
- YAML:
*.yaml
or*.yml
- JSON:
*.json
- CJSON:
*.cjson
- HJSON:
*.hjson
- JSON5:
*.json5
- ALCE:
*.alce
- INI:
*.ini
- .properties:
*.properties
- js:
*.js
By default, the method infers the file format from the filename extension. To explicitly specify the file format, provide a fmt
argument.
var config = ;// returns {...}
Specifying the file format as a filename extension is also supported.
var config = ;// returns {...}
load.exts()
Returns a list of supported filename extensions.
var exts = load;// returns ['.json','.toml',...]
load.parser( extname[, parser] )
Returns a parser for the specified extension.
var parser = load;
Including the .
when specifying an extension is optional.
var parser = load;
To extend the main load
function or to override a parser, provide a parser
function for an associated extension.
var parser = ;load;
Once a parser is set, the main load
function will parse provided files accordingly.
var config = ;
Note: the only parser which cannot be overridden is for .js
configuration files.
Examples
var load = ;var config = ;consoledir config ;
To run the example code from the top-level application directory,
$ node ./examples/index.js
Tests
Unit
Unit tests use the Mocha test framework with Chai assertions. To run the tests, execute the following command in the top-level application directory:
$ make test
All new feature development should have corresponding unit tests to validate correct functionality.
Test Coverage
This repository uses Istanbul as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:
$ make test-cov
Istanbul creates a ./reports/coverage
directory. To access an HTML version of the report,
$ make view-cov
License
Copyright
Copyright © 2015. Athan Reines.