-
Notifications
You must be signed in to change notification settings - Fork 8
/
prefix.js
34 lines (29 loc) · 967 Bytes
/
prefix.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
const path = require('path')
const searches = require('./searches')
module.exports = (pluginContext) => {
return {
respondsTo: (query, env = {}) => {
const prefixSearches = env.prefixSearches || {}
const searchKeys = [...Object.keys(searches), ...Object.keys(prefixSearches)]
return searchKeys.find((prefix) => {
return query.indexOf(prefix + ' ') === 0
})
},
search: (query, env = {}) => {
const prefixSearches = env.prefixSearches || {}
const queryBits = query.split(' ')
const prefix = queryBits[0]
const term = queryBits.slice(1).join(' ')
const search = searches[prefix] || prefixSearches[prefix]
return Promise.resolve(
[
{
icon: search.icon || path.join('assets', prefix + '.png'),
title: 'Search ' + search.name + ' for ' + term,
value: search.url + encodeURIComponent(term)
}
]
)
},
}
}