-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
example.js
39 lines (31 loc) · 802 Bytes
/
example.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
'use strict'
const allStations = require('vbb-stations/simple')
const prompt = require('cli-autocomplete')
const autocomplete = require('.')
const stationsById = Object.create(null)
for (let station of allStations) stationsById[station.id] = station
const suggest = (input) => {
const results = autocomplete(input, 5)
const choices = []
for (let result of results) {
const station = stationsById[result.id]
if (!station) continue
choices.push({
title: [
station.name,
'–',
'score:', result.score.toFixed(3),
'relevance:', result.relevance.toFixed(3)
].join(' '),
value: station.id
})
}
return Promise.resolve(choices)
}
prompt('Type a station name!', suggest)
.once('abort', () => {
process.exitCode = 1
})
.once('submit', (id) => {
console.log(id)
})