mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 15:19:35 +02:00
23 lines
684 B
JavaScript
23 lines
684 B
JavaScript
// 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);
|
|
};
|
|
};
|
|
|
|
export {
|
|
parseHook,
|
|
};
|