-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathindex.js
40 lines (35 loc) · 937 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
import alfy from 'alfy';
import cmdSubtitle from './source/cmd-subtitle.js';
// Do not boost exact matches by default, unless specified by the input
const q = /boost-exact:\S+/.test(alfy.input) ? alfy.input : `${alfy.input} boost-exact:false`;
const data = await alfy.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`,
};
});
alfy.output(items);