Skip to content

Instantly share code, notes, and snippets.

@renancouto
Created August 15, 2014 19:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save renancouto/ffd65e96a016133d9eb1 to your computer and use it in GitHub Desktop.
Save renancouto/ffd65e96a016133d9eb1 to your computer and use it in GitHub Desktop.
Read all json files on the current dir and return an object with their content, using their filenames (in camelCase) as keys.
/*jslint node:true, nomen:true, stupid:true*/
'use strict';
/**
* dependencies
*/
var fs = require('fs');
var path = require('path');
var s = require('string');
/**
* settings
*/
var data = {};
/**
* get dir files
*/
fs.readdirSync(__dirname).forEach(function (item) {
if (path.extname(item) === '.json') {
data[s(path.basename(item, '.json')).camelize().s] = require('./' + item);
}
});
/**
* public
*/
module.exports = data;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment