All files / src/helpers condition.ts

100% Statements 9/9
100% Branches 11/11
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 202x   2x 29x 34x     10x     16x     6x   2x        
import { HandlebarsHelper, HelperConstructorBlock } from "./helper";
 
export const conditionHelper: HelperConstructorBlock = ctx => {
    return new HandlebarsHelper("condition", (v1, operator, v2): boolean => {
        switch (operator) {
            case "!":
            case "not":
                return !v1;
            case "&&":
            case "and":
                return (v1 && v2);
            case "||":
            case "or":
                return (v1 || v2);
            default:
                throw new Error(`Invalid operator used with condition: ${operator}`);
        }
    });
};