Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ディレクトリ内のモジュールをパスカルケースでエクスポートする。
'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
You can’t perform that action at this time.