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