source: trip-planner-front/node_modules/stylus/lib/functions/range.js@ eed0bf8

Last change on this file since eed0bf8 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 857 bytes
Line 
1var utils = require('../utils')
2 , nodes = require('../nodes');
3
4/**
5 * Returns a list of units from `start` to `stop`
6 * by `step`. If `step` argument is omitted,
7 * it defaults to 1.
8 *
9 * @param {Unit} start
10 * @param {Unit} stop
11 * @param {Unit} [step]
12 * @return {Expression}
13 * @api public
14 */
15
16function range(start, stop, step){
17 utils.assertType(start, 'unit', 'start');
18 utils.assertType(stop, 'unit', 'stop');
19 if (step) {
20 utils.assertType(step, 'unit', 'step');
21 if (0 == step.val) {
22 throw new Error('ArgumentError: "step" argument must not be zero');
23 }
24 } else {
25 step = new nodes.Unit(1);
26 }
27 var list = new nodes.Expression;
28 for (var i = start.val; i <= stop.val; i += step.val) {
29 list.push(new nodes.Unit(i, start.type));
30 }
31 return list;
32}
33range.params = ['start', 'stop', 'step'];
34module.exports = range;
Note: See TracBrowser for help on using the repository browser.