-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
45 lines (40 loc) · 1.01 KB
/
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
41
42
43
44
45
"use strict";
const arvish = require("arvish");
const cmdSubtitle = require("./source/cmd-subtitle");
(async function() {
// Do not boost exact matches by default, unless specified by the input
const q = /boost-exact:[^\s]+/.test(arvish.input)
? arvish.input
: `${arvish.input} boost-exact:false`;
const data = await arvish.fetch("https://api.npms.io/v2/search", {
query: {
q,
size: 20
}
});
const items = data.results
.filter(result => result.package.name.length > 1)
.map(result => {
const pkg = result.package;
return {
title: pkg.name,
subtitle: pkg.description,
arg: pkg.links.repository || pkg.links.npm,
mods: {
alt: {
arg: pkg.links.npm,
subtitle: "Open the npm page instead of the GitHub repo"
},
cmd: {
subtitle: cmdSubtitle(pkg)
},
ctrl: {
arg: pkg.name,
subtitle: "Copy package name"
}
},
quicklookurl: pkg.links.repository && `${pkg.links.repository}#readme`
};
});
arvish.output(items);
})();