@xcrap/core
Version:
Xcrap Core is the core package of the Xcrap framework for web scraping, offering tools such as HttpClient, BaseClient, Randomizer, Rotator, and support for proxies and pagination.
22 lines (21 loc) • 602 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Rotator = void 0;
const errors_1 = require("../errors");
class Rotator {
constructor(values) {
this.values = values;
this.currentIndex = 0;
if (values.length === 0) {
throw new errors_1.EmptyArrayError(Rotator.name);
}
}
get current() {
return this.values[this.currentIndex];
}
rotate() {
this.currentIndex = (this.currentIndex + 1) % this.values.length;
return this.values[this.currentIndex];
}
}
exports.Rotator = Rotator;