Skip to content

Instantly share code, notes, and snippets.

@crshmk
Last active December 3, 2022 00:28
Show Gist options
  • Save crshmk/8613a0f60662047420b1821d64fa9c31 to your computer and use it in GitHub Desktop.
Save crshmk/8613a0f60662047420b1821d64fa9c31 to your computer and use it in GitHub Desktop.
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
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"}
@crshmk
Copy link
Author

crshmk commented Mar 6, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment