obsidian-dataview
obsidian-dataview copied to clipboard
Code Cleanup / function overloading
Taken from: https://github.com/blacksmithgu/obsidian-dataview/pull/1283
Also I have in issue with the code (perhaps) containsword doesn't behave like contains. containsword is case insensitive, contains is not (?) as this isn't documented, we have at least icontains and econtains . (so what is the difference between those functions?) so let's say we need icontains and econtains, do we have icontainsword and econtainsword?
without looking at the code would not function overload of .contains make more sense instead of having a lot of different function where you will need to correctly define the small difference in behaviour?
I know I can figure it out, but for a noncoding user the difference between those functions could probably be better described by having the same example with the different functions to show where the real difference is in one place. for example: contains("Hello", "Lo") = true contains("Hello", "lo") = true econtains("Hello", "Lo") = false econtains("Hello", "lo") = true icontains("Hello", "Lo") = true icontains("Hello", "lo") = true
That should probably be a contains example right before the extract part. (I'm sorry hat I can only comment atm, but I haven't had time to get my git stuff running again)
Differently named functions is the most terse way to represent the different contains variants:
containsis the standard "look for thing in array OR look for substring in string"econtainsis a niche function for working with lists of strings.containsis recursive and will search for substrings inside strings inside lists; socontains(["hello", "goodbye"], "hell") = true. If you only want exact string matches, useecontains(["hello", "goodbye"], "hell") = false.icontainsis case-insensitive contains.containswordis case-insensitive contains that additionally only matches full words (so spaces/punctuation before and after).
There could be a function overloaded variant instead, but I suspect it would be pretty verbose.
but contains is case sensitive and containsword not or? shouldn't it be then icontainsword or would case sensitive containsword only be a cornercase?
It would likely be a corner case. I honestly don't think many of these functions will be that popular but I might be wrong. Let's see.