34 lines
589 B
JavaScript
34 lines
589 B
JavaScript
import {randomNumber} from './math';
|
|
|
|
export class Range {
|
|
|
|
constructor(jsonOrValue) {
|
|
if ('undefined' === typeof jsonOrValue.min) {
|
|
this.min = jsonOrValue;
|
|
}
|
|
else {
|
|
this.min = jsonOrValue.min;
|
|
this.max = jsonOrValue.max;
|
|
}
|
|
}
|
|
|
|
static value(rangeOrOther) {
|
|
if (rangeOrOther instanceof Range) {
|
|
return rangeOrOther.value();
|
|
}
|
|
else {
|
|
return rangeOrOther;
|
|
}
|
|
}
|
|
|
|
value() {
|
|
if ('undefined' === typeof this.max) {
|
|
return this.min;
|
|
}
|
|
else {
|
|
return randomNumber(this.min, this.max, false);
|
|
}
|
|
}
|
|
|
|
}
|