1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-07-05 03:33:27 +00:00
TiddlyWiki5/core/modules/filterrunprefixes/reduce.js

53 lines
1.2 KiB
JavaScript
Raw Normal View History

2020-12-04 18:23:50 +00:00
/*\
title: $:/core/modules/filterrunprefixes/reduce.js
type: application/javascript
module-type: filterrunprefix
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
/*
Export our filter prefix function
*/
exports.reduce = function(operationSubFunction,options) {
2020-12-04 18:23:50 +00:00
return function(results,source,widget) {
if(results.length > 0) {
var accumulator = "";
var index = 0;
results.each(function(title) {
var list = operationSubFunction(options.wiki.makeTiddlerIterator([title]),{
getVariable: function(name) {
switch(name) {
case "currentTiddler":
return "" + title;
case "..currentTiddler":
return widget.getVariable("currentTiddler");
case "accumulator":
return "" + accumulator;
case "index":
return "" + index;
case "revIndex":
return "" + (results.length - 1 - index);
case "length":
return "" + results.length;
default:
return widget.getVariable(name);
2020-12-04 18:23:50 +00:00
}
}
});
2020-12-04 18:23:50 +00:00
if(list.length > 0) {
accumulator = "" + list[0];
}
++index;
});
results.clear();
results.push(accumulator);
2020-12-04 18:23:50 +00:00
}
}
};
})();