UNPKG

@react-md/utils

Version:
25 lines 901 B
/** * Gets the current percentage based on the min, max, and current value. * * @returns the percentage that the `value` is between the `min` and `max` * values. * @internal * @remarks \@since 4.0.1 uses an object for options instead of multiple * arguments. */ export function getPercentage(_a) { var min = _a.min, max = _a.max, value = _a.value, _b = _a.validate, validate = _b === void 0 ? true : _b; if (validate) { if (min >= max) { throw new RangeError("A range must have the min value less than the max value"); } if (value > max || value < min) { throw new RangeError("A value must be between the min and max values"); } } var range = max - min; var start = value - min; var percentage = start / range; return Math.max(0, Math.min(Math.abs(percentage), 1)); } //# sourceMappingURL=getPercentage.js.map