db-vendo-client/lib/profile-hooks.js

24 lines
684 B
JavaScript
Raw Permalink Normal View History

2019-10-20 00:19:52 +02:00
// For any type of "thing to parse", there's >=1 parse functions.
// By composing custom parse function(s) with the default ones, one
// can customize the behaviour of hafas-client. Profiles extensively
// use this mechanism.
// Each parse function has the following signature:
// ({opt, profile, common, res}, ...raw) => newParsed
// Compose a new/custom parse function with the old/existing parse
// function, so that the new fn will be called with the output of the
// old fn.
const parseHook = (oldParse, newParse) => {
return (ctx, ...args) => {
return newParse({
...ctx,
parsed: oldParse({...ctx, parsed: {}}, ...args),
}, ...args);
};
};
2019-10-20 00:19:52 +02:00
2022-05-07 16:17:37 +02:00
export {
parseHook,
};