<commit_before>FlatFile [![Build Status](https://travis-ci.org/brendanashworth/flatfile.svg?branch=master)](https://travis-ci.org/brendanashworth/flatfile)
=====

![FlatFile NPM](https://nodei.co/npm/flatfile.png)

> FlatFile is a very simple library for storing, retrieving, and setting JSON data in a flatfile. The library focuses on ease of use and simplicity. Getting up and running is extremely simple and does not require installing any database software.

## Install
```bash
$ npm install flatfile
```

## Usage
```javascript
var flatfile = require('flatfile');

// Load a flatfile database based on file: myfile.json
flatfile.db('myfile.json', function(err, data) {
	if (err)
		console.log('Error occurred: ' + err);

	// Load a value. This acts EXACTLY as a Javascript object!
	console.log(data.firstValue);

	// Set a value. Again, exactly as a JS object.
	data.secondValue = "myVarValue";

	// Save to the file.
	data.save(function(err) {
		if (err)
			console.log('Error occurred while saving: ' + err);
	});
});
```

## Documentation

### Init database
```javascript
flatfile.db(filename, function(err, data))
```
This is a very simple, asynchronous function for initiating the database. After reading the file and parsing to an object, it will return the object via the callback data paramater. If an error occurs while reading the file, it will be passed to the callback and *null* will be returned as data.<commit_msg>make the readme beautiful<commit_after>flatfile [![Build Status](https://travis-ci.org/brendanashworth/flatfile.svg?branch=master)](https://travis-ci.org/brendanashworth/flatfile)
=====

> flatfile is a very simple library for storing, retrieving, and setting JSON data in a flatfile. The library focuses on ease of use and simplicity. Getting up and running is extremely simple and does not require installing any database software.

## Install
```bash
$ npm i flatfile --save
```

## Usage
This example uses ES6 (see [io.js](https://iojs.org/en/index.html)), though the module is compatible up to node v0.10.
```javascript
const flatfile = require('flatfile');

// Load a flatfile database based on file: myfile.json
flatfile.db('data.json', function(err, data) {
    if (err) throw err;

    // Manipulate data like a JS Object
    data.numbers.filter(function(x) {
        return x % 3 == 1;
    }).map(Math.pow).forEach(function(x) {
       data.output[x] = (Math.sin(x) > 0.5); 
    });

    // Save to the file.
    data.save(function(err) {
        if (err) throw err;
    });
});
```

## Documentation

### Init database
```javascript
flatfile.db(filename, function(err, data))
```
This is a very simple, asynchronous function for initiating the database. After reading the file and parsing to an object, it will return the object via the callback data paramater. If an error occurs while reading the file, it will be passed to the callback and *null* will be returned as data.
{'fraction_non_alphanumeric': 0.11917808219178082, 'fraction_numerical': 0.0027397260273972603, 'mean_word_length': 4.142605633802817, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 6, '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': '4679081', 'n_tokens_mistral': 893, 'n_tokens_neox': 837, 'n_words': 333}