Created
September 13, 2016 21:53
-
-
Save fonzerelly/f414bbbb9f2572a16e9886b04a815e06 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
var R = require('ramda'); | |
var | |
//[[key, value]] -> {key: [[key, value]]} | |
groupByKey = R.groupBy(R.head), | |
//{'':a, 'b':b} -> {'b':b} | |
rejectEmptyKeys = R.pickBy(function(value, key) {return key !== '';}), | |
//[[key, value]] -> [value | undefined] | |
extractValueFromPair = R.map(function(pair) {return pair[1];}), | |
//[a] -> [a] | a | |
extractValueFromSingleArray = function(a) { | |
return (a.length === 1) ? R.head(a) : a; | |
}, | |
//[[key, value]], {key: value} | |
objectizePairs = R.pipe( | |
groupByKey, | |
rejectEmptyKeys, | |
R.map(extractValueFromPair), | |
R.map(extractValueFromSingleArray) | |
), | |
//String -> {a: [a] | a} | |
objectizeUrlSearch = R.pipe( | |
R.split('&'), | |
R.map(R.split('=')), | |
objectizePairs | |
); | |
module.exports = { | |
objectizeUrlSearch : objectizeUrlSearch | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment