-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
40 lines (33 loc) · 973 Bytes
/
index.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
const getPinYinBookmark = require('./bookmark');
const debug = require('debug')('index.js');
// const alfy = require('alfy');
const Fuse = require('fuse.js');
const err = console.error;
const bookmarks = getPinYinBookmark();
// err('bookmarks', bookmarks)
const fuse = new Fuse(bookmarks, {
keys: ['pinyin', 'url']
});
function formatBookmark (bookmark) {
return {
title: bookmark.name,
subtitle: bookmark.url,
arg: bookmark.url
};
}
const generateOutputArray = input => fuse.search(input).map(formatBookmark);
const generateOutput = input => {
err(generateOutputArray(input));
return JSON.stringify({
items: generateOutputArray(input)
});
}
// err('fuse is ', fuse);
const inputStr = process.argv[2];
err('input is', inputStr);
err(process.argv)
err('fuse result', fuse.search(inputStr));
// alfy.output(fuse(inputStr));
console.log(generateOutput(inputStr));
// console.log(JSON.stringify(t2));
// alfy.output(generateOutput(inputStr));