Skip to content

Instantly share code, notes, and snippets.

var param = stream.getData() //This is bollocks
-------click-------click---------click------->
**********************************************
----------------"a=1&a=2&b=3"---------------->
**********************************************
------------"a=1&a=2&b=3"-------------------->
observablePerPair
var Rx = require('rx');
var
observablePerPair = function(string) {
return Rx.Observable.from(string.split('&'));
},
splitEqual = function(pairString) {
return pairString.split('=');
},
key = function (pair) {
{
a: [
['a', '1'],
['a', '2']
],
b: [
['b', '3']
]
}
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]
function objectizeUrlSearch (paramString) {
var
pairStrings = paramString.split('&'),
pairs = [],
result = {},
i;
for (i = 0; i < pairStrings.length; i++) {
pairs.push(pairStrings[i].split('='));
}
[['a', '1'], ['a', '2'], ['b', '3']]
['a=1','a=2', 'b=3']
var UrlSearch = require("./url-search");
describe("objectizeUrlSearch", function () {
it("should convert search string to search object", function() {
var
urlSearch = "a=1&a=2&b=3",
searchObject = {
"a": ["1","2"],
"b": "3"
};
expect(UrlSearch.objectizeUrlSearch(urlSearch))