2013-05-25 16:26:22 +00:00
|
|
|
/*\
|
|
|
|
title: $:/core/modules/filters/limit.js
|
|
|
|
type: application/javascript
|
|
|
|
module-type: filteroperator
|
|
|
|
|
|
|
|
Filter operator for chopping the results to a specified maximum number of entries
|
|
|
|
|
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
|
|
|
/*jslint node: true, browser: true */
|
|
|
|
/*global $tw: false */
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
/*
|
|
|
|
Export our filter function
|
|
|
|
*/
|
|
|
|
exports.limit = function(source,operator,options) {
|
|
|
|
var results = [];
|
2014-04-03 19:49:16 +00:00
|
|
|
// Convert to an array
|
|
|
|
source(function(tiddler,title) {
|
|
|
|
results.push(title);
|
|
|
|
});
|
2013-05-25 16:26:22 +00:00
|
|
|
// Slice the array if necessary
|
2014-04-03 19:49:16 +00:00
|
|
|
var limit = Math.min(results.length,parseInt(operator.operand,10));
|
2013-05-25 16:26:22 +00:00
|
|
|
if(operator.prefix === "!") {
|
2014-04-03 19:49:16 +00:00
|
|
|
results = results.slice(-limit);
|
2013-05-25 16:26:22 +00:00
|
|
|
} else {
|
2014-04-03 19:49:16 +00:00
|
|
|
results = results.slice(0,limit);
|
2013-05-25 16:26:22 +00:00
|
|
|
}
|
|
|
|
return results;
|
|
|
|
};
|
|
|
|
|
|
|
|
})();
|