@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.
20 lines (19 loc) • 593 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Randomizer = void 0;
const errors_1 = require("../errors");
class Randomizer {
constructor(values) {
this.values = values;
if (values.length === 0) {
throw new errors_1.EmptyArrayError(Randomizer.name);
}
}
random() {
const arrayLength = this.values.length;
const randomFactor = Math.random();
const randomIndex = Math.floor(randomFactor * arrayLength);
return this.values[randomIndex];
}
}
exports.Randomizer = Randomizer;