blob: 4c69afb1f3da9a775494a1c45c706214515b3419 (
plain) (
blame)
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
|
export default class Completion {
constructor(completions) {
if (typeof completions.length !== 'number') {
throw new TypeError('completions does not have a length in number');
}
this.completions = completions;
this.index = 0;
}
prev() {
let length = this.completions.length;
if (length === 0) {
return null;
}
this.index = (this.index + length - 1) % length;
return this.completions[this.index];
}
next() {
if (this.completions.length === 0) {
return null;
}
let item = this.completions[this.index];
this.index = (this.index + 1) % this.completions.length;
return item;
}
}
|