silphius/app/util/gather.js

20 lines
499 B
JavaScript
Raw Normal View History

2024-06-10 22:42:30 -05:00
function capitalize(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
export default function gather(imports, options = {}) {
const {
2024-07-23 10:10:03 -05:00
pathToKey = (path) => (
path.replace(/\.\/(.*)\.js/, '$1')
2024-06-22 22:33:34 -05:00
.split('-')
.map(capitalize)
.join('')
2024-07-23 10:10:03 -05:00
),
} = options;
const Gathered = {};
for (const [path, Component] of Object.entries(imports).sort(([l], [r]) => l < r ? -1 : 1)) {
Gathered[pathToKey(path)] = Component;
2024-06-10 22:42:30 -05:00
}
return Gathered;
}