<commit_before>broccoli-tree-to-json
====================

Roll up a directory tree into a JSON document.

The directory structure:
```
root
|--key1.txt #123
|--key2.txt #val2
+--subdir
   |--key3.txt #true
   |--key4.txt #val4
```

Will result in the following json:
```javascript
//root.json
{
  "key1":123,
  "key2":"val2",
  "subdir":{
    "key3":true,
    "key4":"val4"
  }
}
```

The file extension is ignored. The JSON key is determined by the portion of the file to the left of the first dot.

File contents are parsed by `JSON.parse`, and if that fails the contents of the file is treated like a string.

## TODO

* Better Array support

## Example use

### In a Brocfile:
```javascript
//Brocfile.js
var Tree2Json = require('broccoli-tree-to-json');

var visitor = {
  visit:function(path){
    console.log('visiting', path);  
  }
};

module.exports = traverser('interesting/path', visitor);

```

### Within another plugin
```javascript
//index.js
var traverser = require('broccoli-tree-traverser');


function MyPlugin(inputTree){
  this.traverser = traverser(inputTree, this);
}

MyPlugin.prototype.visit = function(path){
  //do something interesting with the path
};

MyPlugin.prototype.read = function(readTree){
  return readTree(this.traverser);
};

<commit_msg>update examples<commit_after>broccoli-tree-to-json
====================

Roll up a directory tree into a JSON document.

The directory structure:
```
root
|--key1.txt #123
|--key2.txt #val2
+--subdir
   |--key3.txt #true
   |--key4.txt #val4
```

Will result in the following json:
```javascript
//root.json
{
  "key1":123,
  "key2":"val2",
  "subdir":{
    "key3":true,
    "key4":"val4"
  }
}
```

The file extension is ignored. The JSON key is determined by the portion of the file to the left of the first dot.

File contents are parsed by `JSON.parse`, and if that fails the contents of the file is treated like a string.

## TODO

* Better Array support

## Example use

### In a Brocfile:
```javascript
//Brocfile.js
var tree2Json = require('broccoli-tree-to-json');

module.exports = tree2Json('interesting/path');

```

### Within another plugin
```javascript
//index.js
var tree2Json = require('broccoli-tree-to-json'),
  path = require('path');

function MyPlugin(inputTree){
  this.jsonTree = tree2Json(path.join(inputTree, 'json');
}

MyPlugin.prototype.read = function(readTree){
  return readTree(this.jsonTree)
    .then(function(){
      //...
    });
};

{'fraction_non_alphanumeric': 0.1622503057480636, 'fraction_numerical': 0.016714227476559314, 'mean_word_length': 3.8982035928143715, 'pattern_counts': {'":': 10, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '1234176', 'n_tokens_mistral': 846, 'n_tokens_neox': 807, 'n_words': 242}