UNPKG

random

Version:

Seedable random number generator supporting many common distributions.

39 lines 1.24 kB
export function numberValidator(num) { return new NumberValidator(num); } export class NumberValidator { constructor(num) { this.isInt = () => { if (Number.isInteger(this.n)) { return this; } throw new Error(`Expected number to be an integer, got ${this.n}`); }; this.isPositive = () => { if (this.n > 0) { return this; } throw new Error(`Expected number to be positive, got ${this.n}`); }; this.lessThan = (v) => { if (this.n < v) { return this; } throw new Error(`Expected number to be less than ${v}, got ${this.n}`); }; this.greaterThanOrEqual = (v) => { if (this.n >= v) { return this; } throw new Error(`Expected number to be greater than or equal to ${v}, got ${this.n}`); }; this.greaterThan = (v) => { if (this.n > v) { return this; } throw new Error(`Expected number to be greater than ${v}, got ${this.n}`); }; this.n = num; } } //# sourceMappingURL=validation.js.map