Created
April 9, 2018 22:24
-
-
Save lulalachen/aef8a0d513e9464d489c4b137c9d8396 to your computer and use it in GitHub Desktop.
This file contains 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 * as R from 'ramda' | |
// Usage: parseQueryString(location.search) -> { key1: value2, key2: value2, ... } | |
// parseQueryString => String -> { k: v } | |
const parseQueryString = R.pipe( | |
R.when( | |
R.test(/^\?/), | |
R.drop(1), | |
), | |
R.split('&'), | |
R.map(R.split('=')), | |
R.filter(R.propEq('length', 2)), | |
R.fromPairs, | |
) | |
export default parseQueryString | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment