Is there a way to do a case insensitive literal match?
I can pipe a
string.lower
to a lower-case literal but that seems complicated for this.16 Replies
You could use a regex like
type(/^foo$/i)
hm, which is uglier:
š¤
You could do
type("string.lower").to("'success'")
They're not equivalent though
That one will always return "success"
The regex would validate that if it were lowercase it would be success
, but it would return the original string
Also IMO neither of them are that ugly, I can't really imagine a much cleaner API for something like that š
hm... and now how about if I wanted to ignore whitespace as well? š«
this doesn't seem to do what I expect:
let temp = type('string.trim').to('string.lower').to("'success'")
In what way does it not do what you expect
ah, so, it only applies the first and last operations in the pipeline
What does?
if I have
string.trim
first and string.lower
second, success
validates but Success
does not
in the inverse case, Success
validates but success
doesn'tThat does seem wrong
I will look into that
here's a one liner to try:
type('string.lower').to('string.trim').to("'success'")('Success')
vs type('string.lower').to('string.trim').to("'success'")('success ')
those should both pass, but only one does
this is with latest RC.12I suppose it would be more efficient anyways to just do
type("string").pipe(s => s.trim().toLowerCase()).to("'success'")
and it's order dependent! if you put
string.trim
first, it inverts the success and error from the example aboveHmm yeah it's something to do with the redundant intermediate validation.
This works
I'm off this weekend but if you want to open an issue I will fix this in the next release
I'll add one - thank you!
GitHub
Pipeline of string keywords appears to skip intermediate options Ā· ...
Report a bug š Search Terms string, keywords, string.lower, string.trim, case š§© Context OS: macOS 15.0 CPU: (10) arm64 Apple M1 Pro Memory: 92.36 MB / 16.00 GB Shell: 5.9 - /bin/zsh Binaries: Node:...
Thanks!