20 lines
505 B
JavaScript
20 lines
505 B
JavaScript
function capitalize(string) {
|
|
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
}
|
|
|
|
export default function gather(imports, options = {}) {
|
|
const {
|
|
mapperForPath = (path) => path.replace(/\.\/(.*)\.js/, '$1'),
|
|
} = options;
|
|
const Gathered = {};
|
|
for (const [path, Component] of Object.entries(imports).sort(([l], [r]) => l < r ? -1 : 1)) {
|
|
Gathered[
|
|
mapperForPath(path)
|
|
.split('-')
|
|
.map(capitalize)
|
|
.join('')
|
|
] = Component;
|
|
}
|
|
return Gathered;
|
|
}
|