@perceptr/web-sdk
Version:
Perceptr Web SDK for recording and monitoring user sessions
30 lines (29 loc) • 853 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.clampToRange = clampToRange;
const type_utils_1 = require("./type-utils");
/**
* Clamps a value to a range.
* @param value the value to clamp
* @param min the minimum value
* @param max the maximum value
* @param label if provided then enables logging and prefixes all logs with labels
* @param fallbackValue if provided then returns this value if the value is not a valid number
*/
function clampToRange(value, min, max, label, fallbackValue) {
if (min > max) {
min = max;
}
if (!(0, type_utils_1.isNumber)(value)) {
return clampToRange(fallbackValue || max, min, max, label);
}
else if (value > max) {
return max;
}
else if (value < min) {
return min;
}
else {
return value;
}
}