-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfind.js
41 lines (32 loc) · 1.15 KB
/
find.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const toPairs = require('ramda/src/toPairs');
const pipe = require('ramda/src/pipe');
const prop = require('ramda/src/prop');
const anyPass = require('ramda/src/anyPass');
const last = require('ramda/src/last');
const { Observable } = require('rxjs/Observable');
require('rxjs/add/observable/from');
require('rxjs/add/operator/filter');
require('rxjs/add/operator/map');
require('rxjs/add/operator/do');
require('rxjs/add/operator/toArray');
require('rxjs/add/operator/toPromise');
const asciilib = require('./index.js');
const lib = Observable.from(toPairs(asciilib.lib));
const nameMatches = searchTerm => ([k]) => k.includes(searchTerm);
const getKeywords = pipe(([k, v]) => v, prop('keywords'));
const keywordsMatch = searchTerm => x => {
return getKeywords(x).some(keyword => keyword.includes(searchTerm));
};
const getCategory = pipe(([k, v]) => v, prop('category'));
const categoryMatches = searchTerm => x => {
return getCategory(x).includes(searchTerm);
};
const find = searchTerm =>
lib
.filter(anyPass([
nameMatches(searchTerm),
keywordsMatch(searchTerm),
categoryMatches(searchTerm),
]))
.map(last);
module.exports = find;