forked from cryptoinhero/peatio_tradingview
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsearcher.js
28 lines (24 loc) · 800 Bytes
/
searcher.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
module.exports = class Searcher {
constructor(symbols) {
this.symbols = symbols.sort((a, b) => a.symbol.localeCompare(b.symbol) )
}
search(query, type, exchange, limit) {
query = (query || '').toUpperCase()
type = type || ''
exchange = exchange || ''
limit = parseInt(limit) || this.symbols.length
let result = []
for (let symbol of this.symbols) {
if (type.length > 0 && type != symbol.type) {
continue
}
if (exchange.length > 0 && exchange != symbol.exchange) {
continue
}
if (symbol.symbol.toUpperCase().indexOf(query) >= 0) {
result.push(symbol)
}
}
return result.slice(0, limit)
}
}