Created
May 29, 2016 18:27
-
-
Save nukosuke/50526787714a1ddd152084dbd4f2fdf9 to your computer and use it in GitHub Desktop.
ディレクトリ内のモジュールをパスカルケースでエクスポートする。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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