UNPKG

764 BJavaScriptView Raw
1import OBJ from 'dot-prop';
2import { newValue } from './utils';
3
4/**
5 * Take `Object` containing results of ISTEX API, and returns `hits` value
6 * (documents).
7 *
8 * This should be placed after ISTEXScroll.
9 *
10 * @see ISTEXScroll
11 * @param {string} [source=data]
12 * @param {string} [target=feed]
13 * @returns {Array<Object>}
14 */
15function ISTEXResult(data, feed) {
16 if (this.isLast()) {
17 return feed.close();
18 }
19 const source = this.getParam('source');
20 const target = this.getParam('target');
21 const handle = source ? OBJ.get(data, source) : data;
22
23 const result = handle.hits || [];
24 result.forEach((hitObj) => {
25 feed.write(newValue({ ...hitObj }, target, data));
26 });
27 feed.end();
28}
29
30export default {
31 ISTEXResult,
32};