Last active
June 12, 2020 23:20
-
-
Save crshmk/5ce55d60c646d4a60c0dd59fbe67d5e1 to your computer and use it in GitHub Desktop.
ramda pipelines to get or set query params
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // takes the window | |
| // returns params as an object | |
| export const getQueryParams = pipe( | |
| path(['location', 'search']), | |
| tail, | |
| split('&'), | |
| map(split('=')), | |
| fromPairs, | |
| map(decodeURI) | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export const getUrlParamsAsPairs = pipe( | |
| path(['location', 'search']), | |
| tail, | |
| split('&'), | |
| map(split('=')), | |
| map(([k, v]) => [k, decodeURI(v)]) | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export const makeUrlQueryString = pipe( | |
| mapObjIndexed(encodeURIComponent), | |
| toPairs, | |
| map(join('=')), | |
| join('&'), | |
| concat('?') | |
| ) |
Author
Author
let params = {
one: 'first thing',
two: 'second'
}
let queryString = makeUrlQueryString(params)"?one=first%20thing&two=second"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
www.site.com?one=first%20thing&two=second