silverbulletmd / silverbullet

The hackable notebook
https://silverbullet.md
MIT License
2.03k stars 140 forks source link

Propose startsWith and endsWith for queries #813

Closed fflorent closed 3 months ago

fflorent commented 3 months ago

I would find very useful to propose a startsWith(str, substr) function to, let's say, filter pages whose are contained in a certain folder.

Also I could imagine that in some cases endsWith(str, substr) could also benefit to some users, even if I don't have concrete use cases (I can understand that it will be decided to not implement it until then).

It would be a continuation of this work which introduced contains: https://github.com/silverbulletmd/silverbullet/commit/42dd7f36784f8edd7a1bd099d753413d4116a449

What do you think? I would be glad to propose a patch if you agree with that proposal.

simone-viozzi commented 3 months ago

I usually do this with regex:

page where name =~ /^notes\/Meeting\ notes\//

but having startsWith would be more intuitive

zefhemel commented 3 months ago

What I haven't really decided on is how far I want to extend the range of builtin functions now that it's possible to do this in "user land" using https://silverbullet.md/Space%20Script

I think my preference would be to develop a string manipulation library that you can import and then use rather than have a ever growing list of builtin functions PHP-style. The introduction of contains was already questionable in that sense. And in this case, indeed a regex will also do.

fflorent commented 3 months ago

Right! Closing in favor of this alternative.