1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-06-26 07:13:15 +00:00
TiddlyWiki5/core/modules/filters/match.js
2019-07-31 09:11:12 +01:00

54 lines
1.1 KiB
JavaScript

/*\
title: $:/core/modules/filters/match.js
type: application/javascript
module-type: filteroperator
Filter operator for checking if a title matches a string
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
/*
Export our filter function
*/
exports.match = function(source,operator,options) {
var results = [],
suffixes = (operator.suffixes || [])[0] || [];
if(suffixes.indexOf("caseinsensitive") !== -1) {
if(operator.prefix === "!") {
source(function(tiddler,title) {
if(title.toLowerCase() !== (operator.operand || "").toLowerCase()) {
results.push(title);
}
});
} else {
source(function(tiddler,title) {
if(title.toLowerCase() === (operator.operand || "").toLowerCase()) {
results.push(title);
}
});
}
} else {
if(operator.prefix === "!") {
source(function(tiddler,title) {
if(title !== operator.operand) {
results.push(title);
}
});
} else {
source(function(tiddler,title) {
if(title === operator.operand) {
results.push(title);
}
});
}
}
return results;
};
})();