2.0.0 • Published 9 years ago
data-directory v2.0.0
data-directory
This is a Node module for loading structured data from a directory in the style of Jekyll's _data. Install it with:
npm install data-directoryDirectory Structure
Your directory should contain one or more files with the following extensions:
.csvfor comma-separated values.jsonfor JSON.yamlor.ymlfor YAML
You can read them all into a single data structure like this:
var loadData = require('data-directory');
loadData('_data', function(error, data) {
if (error) return console.error('error:', error);
console.log('data:', JSON.stringify(data, null, ' '));
});Nested Directories
Nested directories will introduce new levels in the data structure. For instance, if you data directory looks like this:
├─ bar.json
└─ baz
└─ qux.csvThen it should parse into a JSON structure that looks like:
{
"bar": {
// contents of bar.json
},
"baz": {
"qux": [
// rows in baz/qux.csv
]
}
}