Last active
December 3, 2022 00:28
-
-
Save crshmk/8613a0f60662047420b1821d64fa9c31 to your computer and use it in GitHub Desktop.
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
import { fromPairs, map, path, pipe, split, tail } from 'ramda' | |
const removeEmptyQuery = filter(complement(isNil)) | |
const getQueryParams = pipe( | |
path(['location', 'search']), | |
tail, | |
split('&'), | |
map(split('=')), | |
fromPairs, | |
removeEmptyQuery, | |
map(decodeURI) | |
); | |
export default getQueryParams |
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
import getQueryParams from './getQueryParams' | |
const window = { | |
location: { | |
search: '?first=the%20first%20one&second=the%20second%20one' | |
} | |
} | |
getQueryParams(window) | |
// {"first": "the first one", "second": "the second one"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
try it out