1'use strict';
2
3function _cycler(items) {
4  var index = -1;
5  return {
6    current: null,
7    reset: function reset() {
8      index = -1;
9      this.current = null;
10    },
11    next: function next() {
12      index++;
13      if (index >= items.length) {
14        index = 0;
15      }
16      this.current = items[index];
17      return this.current;
18    }
19  };
20}
21function _joiner(sep) {
22  sep = sep || ',';
23  var first = true;
24  return function () {
25    var val = first ? '' : sep;
26    first = false;
27    return val;
28  };
29}
30
31// Making this a function instead so it returns a new object
32// each time it's called. That way, if something like an environment
33// uses it, they will each have their own copy.
34function globals() {
35  return {
36    range: function range(start, stop, step) {
37      if (typeof stop === 'undefined') {
38        stop = start;
39        start = 0;
40        step = 1;
41      } else if (!step) {
42        step = 1;
43      }
44      var arr = [];
45      if (step > 0) {
46        for (var i = start; i < stop; i += step) {
47          arr.push(i);
48        }
49      } else {
50        for (var _i = start; _i > stop; _i += step) {
51          // eslint-disable-line for-direction
52          arr.push(_i);
53        }
54      }
55      return arr;
56    },
57    cycler: function cycler() {
58      return _cycler(Array.prototype.slice.call(arguments));
59    },
60    joiner: function joiner(sep) {
61      return _joiner(sep);
62    }
63  };
64}
65module.exports = globals;