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