24 lines
505 B
JavaScript
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);
|
|
}
|
|
|
|
}
|