TiddlyWiki / TiddlyWiki5

A self-contained JavaScript wiki for the browser, Node.js, AWS Lambda etc.
https://tiddlywiki.com/
Other
7.98k stars 1.18k forks source link

A match operator to support logic, string and Maths operators #4130

Closed AnthonyMuscio closed 5 years ago

AnthonyMuscio commented 5 years ago

As a result of related issues mentioned by Jeremy in Are we missing some Important Maths Operators in 5.1.20? I propose the addition of a simple string comparison operator match.

This would make a simple string comparison in a filter such that if "title" is an exact character match with the filter parameter. This would provide a lot of function and give us more time to address the possibility of an equals Operator.

The match operator would make further use of the output of the maths operators new in 5.1.20 more practical.

eg +[match[true]] meaning not false, but also not "wrong" [<variable>match[12]] 12 and only 12 [<variable>match[1.2]] 1.2 and only 1.2 not 1.20

Advantages Filters could be written in the positive rather than ONLY in the negative eg -[[false]] which can be true or "wrong"

by calling it match we imply is is a simple string comparison, that works similarly to the reveal widget. Match could not identify that the number 1.2 is equal to 1.20

Note: Currently the reveal widget can not accept a variable as the input so such a test is not available for variables, the closest is prefix[value]suffix[value] which confuses a lot of people and is not evident at first glance.

I would write it if I could, so I ask here, since I am currently dependant on the good will of others to raise a PR.

AnthonyMuscio commented 5 years ago

Relates to https://github.com/Jermolene/TiddlyWiki5/issues/3781 and https://github.com/Jermolene/TiddlyWiki5/issues/4128

AnthonyMuscio commented 5 years ago

Also https://github.com/Jermolene/TiddlyWiki5/issues/2253 and https://github.com/Jermolene/TiddlyWiki5/pull/3760

Jermolene commented 5 years ago

Hi @AnthonyMuscio I think a straightforward "match" operator is an excellent idea, and fits well with the reveal widgets use of "match" and "nomatch".

AnthonyMuscio commented 5 years ago

<$list filter="[[tiddlywiki]has[matchoperator]]"> Wow, cool, one small step for jeremy, one giant leap for ease of use and code readability. </$list>

Jermolene commented 5 years ago

Thanks @AnthonyMuscio!