mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-09-19 18:59:42 +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
43 lines
1.1 KiB
JavaScript
43 lines
1.1 KiB
JavaScript
/*\
|
|
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 = [],
|
|
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();
|
|
source(function(tiddler,title) {
|
|
if(title && title.toLowerCase().substr(-operand.length) === operand) {
|
|
results.push(title.substr(0,title.length - operand.length));
|
|
}
|
|
});
|
|
} else {
|
|
source(function(tiddler,title) {
|
|
if(title && title.substr(-operator.operand.length) === operator.operand) {
|
|
results.push(title.substr(0,title.length - operator.operand.length));
|
|
}
|
|
});
|
|
}
|
|
return results;
|
|
};
|
|
|
|
})();
|