Skip to content

Instantly share code, notes, and snippets.

@nukosuke
Created May 29, 2016 18:27
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 nukosuke/50526787714a1ddd152084dbd4f2fdf9 to your computer and use it in GitHub Desktop.
Save nukosuke/50526787714a1ddd152084dbd4f2fdf9 to your computer and use it in GitHub Desktop.
ディレクトリ内のモジュールをパスカルケースでエクスポートする。
'use strict';
module.exports = function(dirname) {
var modules = {};
require('fs').readdirSync(dirname + '/').forEach(file => {
if (file.match(/\.js$/) !== null && file !== 'index.js') {
var name = file
.replace('.js', '')
.split('-')
.map(term => term[0].toUpperCase() + term.slice(1))
.join('');
modules[name] = require(dirname + '/' + file);
}
});
return modules;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment