<commit_before># require-yml

[![NPM Version][npm-image]][npm-url]
[![NPM Downloads][downloads-image]][downloads-url]
[![Build Status][travis-image]][travis-url]
[![Test Coverage][coveralls-image]][coveralls-url]

[中文文档](README.zh-CN.md)

## Why?

It's instead of [require-yaml](https://www.npmjs.com/package/require-yaml) because of [this reason](http://nodejs.org/api/globals.html#globals_require_extensions).

And, it can require a yml/yaml/json file/whole directory, or with iterator, or use async callback.

## Install

```bash
npm install require-yml
```

## Usage

configs directory:
```bash
configs/
 |- foo/
    |- bar/
      |- a.yml
      |- b.yaml
      |- c.json
    |- empty/
```
```javascript
var req = require('require-yml')
```

### require a file (yml/yaml/json)

```javascript
var yml = req('./configs/foo/bar/a.yml')
var yaml = req('./configs/foo/bar/b')	// b.yaml
var json = req('./configs/foo/bar/c.json')
console.log(yml, yaml, json)
// >> {}, {}, {}
```

### require a directory

```javascript
var all = req('./configs')
console.log(all)
// >> json object {"foo":{"bar":[Object Object]}
```

### require an empty file/directory

```javascript
var empty = req('./configs/empty')
console.log(empty)
// >> undefined
```

### require with iterator

```javascript
var iterator = function(json) {
	json.inject = 'everywhere'
	return json
}
var yml = req('./configs', iterator)
console.log(yml.foo.bar.a.inject)
// >> 'everywhere'
```

### async require

```javascript
req('./configs', null, function(yml){
	console.log(yml.foo.bar.a)
})
// >> {}
```

## Test
<commit_msg>Updated README.md - but can't update README-zh-CN<commit_after># require-yml

[![NPM Version][npm-image]][npm-url]
[![NPM Downloads][downloads-image]][downloads-url]
[![Build Status][travis-image]][travis-url]
[![Test Coverage][coveralls-image]][coveralls-url]

[中文文档](README.zh-CN.md)

## Why?

It's instead of [require-yaml](https://www.npmjs.com/package/require-yaml) because of [this reason](http://nodejs.org/api/globals.html#globals_require_extensions).

And, it can require a yml/yaml/json file/whole directory, or with iterator, or use async callback.

## Install

```bash
npm install require-yml
```

## Usage

configs directory:
```bash
configs/
 |- foo/
    |- bar/
      |- a.yml
      |- b.yaml
      |- c.json
    |- empty/
```
```javascript
var req = require('require-yml')
```

### require a file (yml/yaml/json)

```javascript
var yml = req('./configs/foo/bar/a.yml')
var yaml = req('./configs/foo/bar/b')	// b.yaml
var json = req('./configs/foo/bar/c.json')
console.log(yml, yaml, json)
// >> {}, {}, {}
```

### require a directory

```javascript
var all = req('./configs')
console.log(all)
// >> json object {"foo":{"bar":[Object Object]}
```

### require an empty file/directory

```javascript
var empty = req('./configs/empty')
console.log(empty)
// >> undefined
```

### require with iterator

```javascript
var iterator = function(json) {
	json.inject = 'everywhere'
	return json
}
var yml = req('./configs', iterator)
console.log(yml.foo.bar.a.inject)
// >> 'everywhere'
```

### handle require or iterator errors

```javascript

var yml = req('./configs', function brokenIterator(json) { 
   a = b // -> throws `a is undefined`
})
req.onLoadError = function(err) {
   //handle your errors here
   switch(e.CODE) { 
      ...
   }
}
```

### async require

```javascript
req('./configs', null, function(yml){
	console.log(yml.foo.bar.a)
})
// >> {}
```

## Test

{'fraction_non_alphanumeric': 0.20972382048331414, 'fraction_numerical': 0.0, 'mean_word_length': 3.7892561983471076, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 24, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2417193', 'n_tokens_mistral': 1306, 'n_tokens_neox': 1216, 'n_words': 269}