jest-metadata
Version:
🦸♂️ Superhero power for your Jest reporters! 🦸♀️
44 lines • 1.01 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Rotator = void 0;
class Rotator {
#items = [];
#offset = 0;
get size() {
return this.items.length;
}
get offset() {
return this.#offset;
}
get items() {
return [...this.#items.slice(this.offset), ...this.#items.slice(0, this.offset)];
}
find(predicate) {
let i = this.size;
while (i--) {
const item = this.next();
if (predicate(item)) {
return item;
}
}
return;
}
peek() {
return this.#items[this.#offset];
}
reset() {
this.#offset = 0;
return this;
}
add(...items) {
this.#items.push(...items);
return this;
}
next() {
const item = this.peek();
this.#offset = (this.offset + 1) % this.items.length;
return item;
}
}
exports.Rotator = Rotator;
//# sourceMappingURL=Rotator.js.map