summaryrefslogtreecommitdiff
path: root/node_modules/nunjucks/src/globals.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/nunjucks/src/globals.js')
-rw-r--r--node_modules/nunjucks/src/globals.js65
1 files changed, 65 insertions, 0 deletions
diff --git a/node_modules/nunjucks/src/globals.js b/node_modules/nunjucks/src/globals.js
new file mode 100644
index 0000000..e0de671
--- /dev/null
+++ b/node_modules/nunjucks/src/globals.js
@@ -0,0 +1,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; \ No newline at end of file