UNPKG

450 BJavaScriptView Raw
1'use strict';
2
3var _ = require('lodash');
4
5/**
6 * Limit an array to the second argument
7 *
8 * @example
9 * {{limit array 4}}
10 */
11function helper(paper) {
12 paper.handlebars.registerHelper('limit', function (data, limit) {
13
14 if (_.isString(data)) {
15 return data.substring(0, limit);
16 }
17 if (!_.isArray(data)) {
18 return [];
19 }
20
21 return data.slice(0, limit);
22 });
23}
24
25module.exports = helper;