From c9a0a3fff9da8399e8786b4e847c958d88efbf52 Mon Sep 17 00:00:00 2001 From: cha0s Date: Tue, 12 Jan 2021 22:34:55 -0600 Subject: [PATCH] feat: gatherWithLatus --- packages/core/src/gather.js | 9 +++++++++ packages/core/src/index.js | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/core/src/gather.js b/packages/core/src/gather.js index 518a529..3185906 100644 --- a/packages/core/src/gather.js +++ b/packages/core/src/gather.js @@ -1,5 +1,14 @@ +import {basename, extname} from 'path'; + const capitalize = (token) => token.substring(0, 1).toUpperCase() + token.substring(1); +export const gatherWithLatus = (context) => (latus) => ( + Object.fromEntries(context.keys().map((path) => [ + capitalize(basename(path, extname(path))), + context(path).default(latus), + ])) +); + export default (latus, type, idAttribute, typeAttribute, check = () => {}) => { const gathered = latus.invokeReduce(type); check(gathered, type); diff --git a/packages/core/src/index.js b/packages/core/src/index.js index e40d9b0..a43ace7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -8,7 +8,7 @@ export {default as ensureUniqueReduction} from './ensure-unique-reduction'; export {default as EventEmitter} from './event-emitter'; export {deflate, inflate} from './flate'; export {compose, fastApply} from './function'; -export {default as gather} from './gather'; +export {gatherWithLatus, default as gather} from './gather'; export {default as Middleware} from './middleware'; export {default as Latus} from './latus';