All files / src/helpers compare.ts

100% Statements 14/14
100% Branches 25/25
100% Functions 2/2
100% Lines 13/13

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 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 432x   2x 29x 65x       14x       5x       7x       5x       11x       6x       9x       6x   2x        
import { HandlebarsHelper, HelperConstructorBlock } from "./helper";
 
export const compareHelper: HelperConstructorBlock = ctx => {
    return new HandlebarsHelper("compare", (v1, operator, v2): boolean => {
        switch (operator) {
            case "==":
            case "eq":
            case "equals":
                return (v1 == v2);
            case "===":
            case "seq":
            case "strictly-equals":
                return (v1 === v2);
            case "!=":
            case "ne":
            case "not-equals":
                return (v1 != v2);
            case "!==":
            case "sne":
            case "strictly-not-equals":
                return (v1 !== v2);
            case "<":
            case "lt":
            case "less-than":
                return (v1 < v2);
            case "<=":
            case "lte":
            case "less-than-equals":
                return (v1 <= v2);
            case ">":
            case "gt":
            case "greater-than":
                return (v1 > v2);
            case ">=":
            case "gte":
            case "greater-than-equals":
                return (v1 >= v2);
            default:
                throw new Error(`Invalid comparison operator used with compare: ${operator}`);
        }
    });
};