From 0ab9ec1ad327281f1452288a7de1c2ead21a1a8c Mon Sep 17 00:00:00 2001 From: Matt Lauber Date: Wed, 9 May 2018 13:07:08 -0400 Subject: [PATCH] Refactored the is operator for simplicity and efficiency. (#3240) * Refactored the is operator for simplicity and efficiency. * Improve `is` filter documentation. * Update is.js * extracted `subops.length` to `num_of_subops` * renamed `subop` to `operator` for clarity/differentiation from `subops` * refactored to avoid using a `Set` object. * Update is.js --- core/modules/filters/is.js | 54 +++++++++++++----------- editions/tw5.com/tiddlers/filters/is.tid | 2 +- 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/core/modules/filters/is.js b/core/modules/filters/is.js index 99d86597f..c1add6f61 100644 --- a/core/modules/filters/is.js +++ b/core/modules/filters/is.js @@ -27,40 +27,44 @@ Export our filter function */ exports.is = function(source,operator,options) { + var isFilterOperators = getIsFilterOperators(), + subops = operator.operand.split("+"), + num_of_subops = subops.length; - if( !operator.operand) { - // Return all tiddlers if the operand is missing + //Make sure all the operands are defined. + for (var t = 0; t < num_of_subops; t++){ + if( !isFilterOperators[subops[t]] ) { + return [$tw.language.getString("Error/IsFilterOperator")]; + } + } + + if(num_of_subops === 0) { // Return all tiddlers if the operand is missing var results = []; source(function(tiddler,title) { results.push(title); }); return results; - } + } else if(num_of_subops === 1) { // Shortcut the Single Operator + var operator = isFilterOperators[subops[0]]; + return operator(source,operator.prefix,options); - // Get our isfilteroperators - var isFilterOperators = getIsFilterOperators(), - subops = operator.operand.split("+"), - filteredResults = {}, - results = []; - for (var t=0; t> belong to category <<.pl The parameter <<.place C>> specifies zero or more fundamental categories using the following syntax: <$railroad text=""" -[{: ("current" | "missing" |: "orphans" | "shadows" | "tags" | "tiddlers" ) +"+" }] +[{: ("current" | "missing" |: "orphan" | "shadow" | "system" | "tag" | "tiddler" | "image") +"+" }] """/> |!Category |!Matches any tiddler that... |