1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-06-29 00:33:15 +00:00
TiddlyWiki5/core/modules/filters/suffix.js

59 lines
1.3 KiB
JavaScript
Raw Normal View History

2014-08-28 13:46:00 +00:00
/*\
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 = [],
suffixes = (operator.suffixes || [])[0] || [];
if (!operator.operand) {
2014-08-28 13:46:00 +00:00
source(function(tiddler,title) {
results.push(title);
2014-08-28 13:46:00 +00:00
});
} else if(suffixes.indexOf("caseinsensitive") !== -1) {
var operand = operator.operand.toLowerCase();
if(operator.prefix === "!") {
source(function(tiddler,title) {
if(title.toLowerCase().substr(-operand.length) !== operand) {
results.push(title);
}
});
} else {
source(function(tiddler,title) {
if(title.toLowerCase().substr(-operand.length) === operand) {
results.push(title);
}
});
}
2014-08-28 13:46:00 +00:00
} else {
if(operator.prefix === "!") {
source(function(tiddler,title) {
if(title.substr(-operator.operand.length) !== operator.operand) {
results.push(title);
}
});
} else {
source(function(tiddler,title) {
if(title.substr(-operator.operand.length) === operator.operand) {
results.push(title);
}
});
}
2014-08-28 13:46:00 +00:00
}
return results;
};
})();