Issues (117)

lib/handlebars/repeat.js (1 issue)

Labels
Severity
1 1
var handlebars = require('handlebars');
2
3
/**
4
 * Handlebars block helper that repeats the content inside of it n number of times.
5
 * @param {integer} count - Number of times to repeat.
6
 * @param {object} options - Handlebars object.
7
 * @example
8
 * {{#repeat 5}}<li>List item!</li>{{/repeat}}
9
 * @returns The content inside of the helper, repeated n times.
10
 */
11
function repeat (count, options) {
12 1
  var str = '';
13
  var data;
14
15 2
  if (options.data) {
16 1
    data = handlebars.createFrame(options.data);
17
  }
18
19 1
  for (var i = 0; i < count; i++) {
20 5
    if (data) {
21 5
      data.index = i;
22
    }
23
24 5
    str += options.fn(this, { data: data });
0 ignored issues
show
The variable data does not seem to be initialized in case options.data on line 15 is false. Are you sure this can never be the case?
Loading history...
25
  }
26
27 1
  return str;
28
}
29
30
module.exports = repeat;
31
handlebars.registerHelper('repeat', repeat);