Object for working with url GET parameters: simple get, simple add
jcurl.getParams('example.com?bar=1&foo');
jcurl.addParams('example.com', { bar: 1, foo: 2 });
jcurl.getParamsExtended('example.com?bar[roo][boo]=1&foo[puu]=test');
jcurl.addParamsExtended('example.com', { bar: { foo: 'test', joo: 2 } });
jcurl
exactly, not jsurl
, this is not a mistake :)
alias get()
If you have simple parameters like
bar=1
orfoo[]=3&foo[]=5
, then usegetParams()
.
In response, you will get a simple (single-level) object whose keys will contain either simple values or simple arrays. This function is suitable in 99% of cases.
jcurl.get('example.com');
// {}
jcurl.get('example.com?bar=1&foo');
// { bar: '1', foo: '' }
jcurl.get('example.com?bar=1&bar=2');
// { bar: '2' }
jcurl.get('example.com?bar[]=1&bar[]=2');
// { bar: ['1', '2'] }
jcurl.get('example.com?bar=1&bar[]=2');
// { bar: ['2'] }
alias add()
jcurl.add('example.com', { bar: 1, foo: 2 });
// example.com?bar=1&foo=2
jcurl.add('example.com?bar=1&foo', { bar: 2, foo: 2 });
// example.com?bar=2&foo=2
jcurl.add('example.com?bar=1', { bar: [2, 3] });
// example.com?bar[]=2&bar[]=3
jcurl.add('example.com?bar=1&bar[]=2', { bar: [3, 4] });
// example.com?bar[]=2&bar[]=3&bar[]=4
alias getExt()
If you have complex parameters like:
bar[foo][too][poo]=3&bar[foo][goo]=4
, then usegetParamsExtended()
.
In response, you will get a multi-level object. Most likely you will not need this function.
jcurl.getExt('example.com?bar[t]=1&bar[j]=2');
// { bar: { t: '1', j: '2' } }
alias addExt()
jcurl.addExt('example.com', { bar: { foo: 'test', joo: 2 } });
// example.com?bar[foo]=test&bar[joo]=2
The getParamsExtended
and addParamsExtended
functions may not answer exactly. Please tell me which tests failed.