mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-09-20 19:29:43 +00:00
95bd694a65
* Support case insensitive matching in prefix/suffix operators Support `caseinsensitive`/`caseinsensitive` suffixes in the following filter operators: * prefix * suffix * removeprefix * removesuffix The suffixes have the same behaviour as in the match operator. Closes: #6407 * Do not filter titles if suffix/removesuffix operand is empty Issue: #6407
59 lines
1.3 KiB
JavaScript
59 lines
1.3 KiB
JavaScript
/*\
|
|
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) {
|
|
source(function(tiddler,title) {
|
|
results.push(title);
|
|
});
|
|
} 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);
|
|
}
|
|
});
|
|
}
|
|
} 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);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
return results;
|
|
};
|
|
|
|
})();
|