A
arktypeā€¢4mo ago
francis

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
ssalbdivad
ssalbdivadā€¢4mo ago
You could use a regex like type(/^foo$/i)
francis
francisOPā€¢4mo ago
hm, which is uglier:
optionOne: /^success$/i,
optionTwo: type("string.lower").pipe(type("'success'")),
optionOne: /^success$/i,
optionTwo: type("string.lower").pipe(type("'success'")),
šŸ¤”
ssalbdivad
ssalbdivadā€¢4mo ago
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 šŸ˜…
francis
francisOPā€¢4mo ago
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'")
ssalbdivad
ssalbdivadā€¢4mo ago
In what way does it not do what you expect
francis
francisOPā€¢4mo ago
ah, so, it only applies the first and last operations in the pipeline
ssalbdivad
ssalbdivadā€¢4mo ago
What does?
francis
francisOPā€¢4mo ago
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't
ssalbdivad
ssalbdivadā€¢4mo ago
That does seem wrong I will look into that
francis
francisOPā€¢4mo ago
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.12
ssalbdivad
ssalbdivadā€¢4mo ago
I suppose it would be more efficient anyways to just do type("string").pipe(s => s.trim().toLowerCase()).to("'success'")
francis
francisOPā€¢4mo ago
and it's order dependent! if you put string.trim first, it inverts the success and error from the example above
ssalbdivad
ssalbdivadā€¢4mo ago
Hmm yeah it's something to do with the redundant intermediate validation. This works
const tt = type("string.lower")
.pipe(s => s.trim())
.to("'success'")
const tt = type("string.lower")
.pipe(s => s.trim())
.to("'success'")
I'm off this weekend but if you want to open an issue I will fix this in the next release
francis
francisOPā€¢4mo ago
I'll add one - thank you!
francis
francisOPā€¢4mo ago
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:...
ssalbdivad
ssalbdivadā€¢4mo ago
Thanks!
Want results from more Discord servers?
Add your server