Skip to content

Instantly share code, notes, and snippets.

@lulalachen
Created April 9, 2018 22:24
Show Gist options
  • Save lulalachen/aef8a0d513e9464d489c4b137c9d8396 to your computer and use it in GitHub Desktop.
Save lulalachen/aef8a0d513e9464d489c4b137c9d8396 to your computer and use it in GitHub Desktop.
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