avocado/packages/math/src/range.js
2020-12-28 21:18:54 -06:00

24 lines
505 B
JavaScript

import {randomNumber} from './math';
export default class Range {
constructor(jsonOrValue) {
if ('undefined' === typeof jsonOrValue.min) {
this.min = jsonOrValue;
}
else {
this.min = jsonOrValue.min;
this.max = jsonOrValue.max;
}
}
static value(rangeOrOther) {
return rangeOrOther instanceof Range ? rangeOrOther.value() : rangeOrOther;
}
value() {
return 'undefined' === typeof this.max ? this.min : randomNumber(this.min, this.max, false);
}
}