mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-02-22 14:00:03 +00:00
added some more filters
This commit is contained in:
parent
b652238650
commit
103f4f6637
@ -76,4 +76,41 @@ exports.rest = function(source,operator,options) {
|
||||
return results;
|
||||
};
|
||||
|
||||
exports.butfirst = exports.rest;
|
||||
exports.bf = exports.rest;
|
||||
|
||||
exports.butlast = function(source,operator,options) {
|
||||
var results = [];
|
||||
var count = operator.operand || 1;
|
||||
// Iterate through the source tiddlers
|
||||
if($tw.utils.isArray(source)) {
|
||||
results = source.slice(0,-count);
|
||||
} else {
|
||||
for(var title in source) {
|
||||
results.push(title);
|
||||
};
|
||||
results = results.slice(0,-count);
|
||||
}
|
||||
return results;
|
||||
};
|
||||
exports.bl = exports.butlast;
|
||||
|
||||
exports.nth = function(source,operator,options) {
|
||||
var results = [];
|
||||
var count = operator.operand || 1;
|
||||
// Iterate through the source tiddlers
|
||||
if($tw.utils.isArray(source)) {
|
||||
results = source.slice(count-1,count);
|
||||
} else {
|
||||
for(var title in source) {
|
||||
--count;
|
||||
if(count > 0) continue;
|
||||
if(count < 0) break;
|
||||
results.push(title);
|
||||
break;
|
||||
};
|
||||
}
|
||||
return results;
|
||||
};
|
||||
|
||||
})();
|
||||
|
@ -61,6 +61,12 @@ A filter string consists of one or more runs of filter operators that each look
|
||||
* ''first'': selects the first tiddler of the list (or the first n if the operand is n)
|
||||
* ''last'': selects the last tiddler of the list (or the last n if the operand is n)
|
||||
* ''rest'': selects all but the first tiddler of the list (or all but the first n if the operand is n)
|
||||
* ''butfirst'': synonym for ''rest''
|
||||
* ''bf'': another synonym for ''rest''
|
||||
* ''butlast'': selects all but the last tiddler of the list (or all but the last n if the operand is n)
|
||||
* ''bl'': another synonym for ''butlast''
|
||||
* ''nth'': selects the n-th tiddler of the list. Defaults to n = 1.
|
||||
|
||||
|
||||
An operator can be negated with by preceding it with `!`, for example `[!tag[Tommy]]` selects the tiddlers that are not tagged with `Tommy`.
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user