Add suffix and removesuffix filters

This commit is contained in:
Jermolene
2014-08-28 14:46:00 +01:00
parent 798ed46469
commit dcf4e93a32
6 changed files with 95 additions and 2 deletions
+28
View File
@@ -0,0 +1,28 @@
/*\
title: $:/core/modules/filters/removesuffix.js
type: application/javascript
module-type: filteroperator
Filter operator for removing a suffix from each title in the list. Titles that do not end with the suffix are removed.
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
/*
Export our filter function
*/
exports.removesuffix = function(source,operator,options) {
var results = [];
source(function(tiddler,title) {
if(title.substr(-operator.operand.length).toLowerCase() === operator.operand.toLowerCase()) {
results.push(title.substr(operator.operand.length));
}
});
return results;
};
})();
+36
View File
@@ -0,0 +1,36 @@
/*\
title: $:/core/modules/filters/suffix.js
type: application/javascript
module-type: filteroperator
Filter operator for checking if a title ends with a suffix
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
/*
Export our filter function
*/
exports.suffix = function(source,operator,options) {
var results = [];
if(operator.prefix === "!") {
source(function(tiddler,title) {
if(title.substr(-operator.operand.length).toLowerCase() !== operator.operand.toLowerCase()) {
results.push(title);
}
});
} else {
source(function(tiddler,title) {
if(title.substr(-operator.operand.length).toLowerCase() === operator.operand.toLowerCase()) {
results.push(title);
}
});
}
return results;
};
})();