All files numbers.ts

100% Statements 8/8
100% Branches 4/4
100% Functions 2/2
100% Lines 8/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23          1x 15x 7x 8x 7x     1x             1x 9x    
/**
 * This method keeps a given value within the bounds of a min and max value. If the value
 * is larger than the max, the minimum value will be returned. If the value is smaller than the minimum,
 * the maximum will be returned. Otherwise, the value is returned un-changed.
 */
export function wrapInBounds(min: number, max: number, value: number): number {
    if (value < min) {
        return max;
    } else if (value > max) {
        return min;
    }
 
    return value;
}
 
/**
 * Ensures that a value is between a min and max value. If value is lower than min, min will be returned.
 * If value is greater than max, max will be retured.
 */
export function limit(min: number, max: number, value: number): number {
    return Math.min(Math.max(value, min), max);
}