forked from wayneashleyberry/wunderline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wunderline-list.js
executable file
·43 lines (35 loc) · 952 Bytes
/
wunderline-list.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
42
43
#!/usr/bin/env node
var app = require("commander");
var fuzzysearch = require("fuzzysearch");
var getLists = require("./lib/get-lists");
var printList = require("./lib/print-list");
var auth = require("./lib/auth");
app
.description("Display a list")
.usage("[query]")
.parse(process.argv);
function main() {
var terms = app.args;
if (terms.length < 1) {
process.exit();
}
getLists(function(err, data) {
if (err) process.exit(1);
var lists = data.filter(function(item) {
var match = false;
terms.forEach(function(term) {
// Case sensitive matching if smartcase found.
if (term.toLowerCase() !== term) {
if (fuzzysearch(term, item.title)) {
match = true;
}
} else if (fuzzysearch(term.toLowerCase(), item.title.toLowerCase())) {
match = true;
}
});
return match;
});
lists.forEach(printList);
});
}
auth(main);