Read JSON
Reads the entire contents of a JSON file.
Installation
$ npm install utils-fs-read-json
Usage
var readJSON = ;
readJSON( path, [ options,] clbk )
Reads the entire contents of a JSON file.
;{if errorconsole;elseconsole;}
The function accepts the same options as fs.readFile()
, but encoding
is always set to utf8
. In addition, a JSON reviver may be provided.
var opts ='reviver': reviver;;{if errorconsole;elseconsole;}{if key === 'beep'return 'boop';return value;}
readJSON.sync( path[, options] )
Synchronously reads the contents of an entire JSON file.
var out = readJSON;if out instanceof Errorthrow out;console;
The function accepts the same options as fs.readFileSync()
and the asynchronous readJSON
method above.
Examples
var path =readJSON = ;var file = path;// Sync:var data = readJSON;// returns <object>console;// returns falsedata = readJSON;// returns <error>console;// returns true// Async:;;{if errorif errorcode === 'ENOENT'console;elsethrow error;elseconsole;}
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.