UNPKG

crawlerzzz

Version:

37 lines (32 loc) 668 B
import * as R from 'ramda'; type PropValueSelectorType = | { [key: string]: (selector: any) => any; } | Function | string; const propArraySelector = R.curry(( //@ts-ignore $: CheerioSelector, contextArraySelector: any, propsConfig: PropValueSelectorType ) => $(contextArraySelector) .toArray() .map(context => { if (typeof propsConfig === 'string') { return $(propsConfig, context); } if (typeof propsConfig === 'function') { return propsConfig(context); } return R.keys(propsConfig).reduce( (acc, cur) => ({ ...acc, [cur]: propsConfig[cur](context) }), {} ); }) ); export { propArraySelector };