-
-
Notifications
You must be signed in to change notification settings - Fork 443
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pick
method returns the first match from a filter
#344
Comments
After asking on StackOverflow, thanks to Adam Thomas for solving the regular expression approach.
So here is the code snippet now
pickedUrl logs like this, which I don't really understand why |
Well I partially solved it by passing the following options argument
I still have no idea why |
I am trying to clean a URL and only keep some parameters that I need in order to parse them
so I was using pick method providing it the url, and the filter which is a regex test method
here I am testing to check if the key in the query parameter matches the regular expression
for example
http://localhost:3000/tat?GRP_Bob[]=SW&GRP_sa[]=QW&GRP_sa[]=AA&projects[]=MP,PM&releases[]=2021.4,2022.1
it should return
http://localhost:3000/tat?GRP_Bob=SW&GRP_sa=QW&GRP_sa=AA
yet it only tests for the first request parameter only and logs
http://localhost:3000/tat?GRP_Bob%5B%5D=SW
I am trying to clean the url from any other parameters that doesn't match my regular expression
so I can parse the URL and extract the object
so it can be like this for example
Instead of having other parameters parsed also which are not necessary. I know I can just parse the url normally, and then loop on the returned
query
object, and remove any key that doesn't match the regex, but is there anything wrong I am doing in the above snippet?UPDATE:
I changed the filter function to be
(key,value)=>key.startsWith('GRP_'))
and the
pickedURL
logged thishttp://localhost:3000/tat?GRP_Bob%5B%5D=SW&GRP_sa%5B%5D=QW&GRP_sa%5B%5D=AA
which is likely to be correct.it came out like that
So I am confused actually what's going on with the regular expression approach, and why the keys in the second approach have
[]
in it?The text was updated successfully, but these errors were encountered: