refactor: gather

This commit is contained in:
cha0s 2024-07-23 10:10:03 -05:00
parent b9e3ac433b
commit 263cf37e27

View File

@ -4,16 +4,16 @@ function capitalize(string) {
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)
pathToKey = (path) => (
path.replace(/\.\/(.*)\.js/, '$1')
.split('-')
.map(capitalize)
.join('')
] = Component;
),
} = options;
const Gathered = {};
for (const [path, Component] of Object.entries(imports).sort(([l], [r]) => l < r ? -1 : 1)) {
Gathered[pathToKey(path)] = Component;
}
return Gathered;
}