All files / src/helpers repeat.ts

100% Statements 12/12
100% Branches 1/1
100% Functions 2/2
100% Lines 10/10

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 182x   2x 29x 14x   14x 3x     11x 11x 23x   11x      
import { HandlebarsHelper, HelperConstructorBlock } from "./helper";
 
export const repeatHelper: HelperConstructorBlock = (ctx) => {
    return new HandlebarsHelper("repeat", function (rawNum, options) {
        const num = Number.parseInt(rawNum);
 
        if (Number.isNaN(num)) {
            throw new Error(`Can't convert "${rawNum}" to number while using repeat`);
        }
 
        let ret = "";
        for (let i = 0; i < rawNum; i++) {
            ret += options.fn({ ...this, "repeat_index": i });
        }
        return ret;
    });
};