]>
git.wh0rd.org - tt-rss.git/blob - lib/dojo/io-query.js.uncompressed.js
1 define("dojo/io-query", ["./_base/lang"], function(lang
){
5 // This module defines query string processing functions.
9 function objectToQuery(/*Object*/ map
){
11 // takes a name/value mapping object and returns a string representing
12 // a URL-encoded version of that object.
24 // yields the following query string:
26 // | "blah=blah&multi=thud&multi=thonk"
28 // FIXME: need to implement encodeAscii!!
29 var enc
= encodeURIComponent
, pairs
= [];
31 var value
= map
[name
];
32 if(value
!= backstop
[name
]){
33 var assign
= enc(name
) + "=";
34 if(lang
.isArray(value
)){
35 for(var i
= 0, l
= value
.length
; i
< l
; ++i
){
36 pairs
.push(assign
+ enc(value
[i
]));
39 pairs
.push(assign
+ enc(value
));
43 return pairs
.join("&"); // String
46 function queryToObject(/*String*/ str
){
48 // Create an object representing a de-serialized query section of a
49 // URL. Query keys with multiple values are returned in an array.
54 // | "foo=bar&foo=baz&thinger=%20spaces%20=blah&zonk=blarg&"
56 // results in this object structure:
59 // | foo: [ "bar", "baz" ],
60 // | thinger: " spaces =blah",
64 // Note that spaces and other urlencoded entities are correctly
67 // FIXME: should we grab the URL string if we're not passed one?
68 var dec
= decodeURIComponent
, qp
= str
.split("&"), ret
= {}, name
, val
;
69 for(var i
= 0, l
= qp
.length
, item
; i
< l
; ++i
){
72 var s
= item
.indexOf("=");
77 name
= dec(item
.slice(0, s
));
78 val
= dec(item
.slice(s
+ 1));
80 if(typeof ret
[name
] == "string"){ // inline'd type check
81 ret
[name
] = [ret
[name
]];
84 if(lang
.isArray(ret
[name
])){
95 objectToQuery
: objectToQuery
,
96 queryToObject
: queryToObject