123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- '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;
|