-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
26 lines (20 loc) · 842 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
'use strict'
const create = require('synchronous-autocomplete')
const tokenize = require('./tokenize')
const tokens = require('./data/tokens.json')
const scores = require('./data/scores.json')
const weights = require('./data/weights.json')
const nrOfTokens = require('./data/nr-of-tokens.json')
const originalIds = require('./data/original-ids.json')
const names = require('./data/names.json')
const _autocomplete = create(tokens, scores, weights, nrOfTokens, originalIds, tokenize)
const autocomplete = (query, limit = 6, fuzzy = false, completion = true) => {
const results = _autocomplete(query, limit, fuzzy, completion)
for (let res of results) {
res.type = res.id[0] === 'r' ? 'region' : 'station'
res.id = res.id.slice(1)
res.name = names[res[_autocomplete.internalId]]
}
return results
}
module.exports = autocomplete