3
Copyright 2011 Yahoo! Inc. All rights reserved.
4
Licensed under the BSD License.
5
http://yuilibrary.com/license/
7
YUI.add('querystring-parse-simple', function(Y) {
9
// @TODO this looks like we are requiring the user to extract the querystring
10
// portion of the url, which isn't good. The majority use case will be to
11
// extract querystring from the document configured for this YUI instance.
12
// This should be the default if qs is not supplied.
16
* <p>Provides Y.QueryString.stringify method for converting objects to Query Strings.
17
* This is a simpler implementation than the full querystring-stringify.</p>
18
* <p>Because some things may require basic query string escaping functionality,
19
* this module provides the bare minimum functionality (decoding a hash of simple values),
20
* without the additional support for arrays, objects, and so on.</p>
21
* <p>This provides a friendly way to deserialize basic query strings, without necessitating
22
* a lot of code for simple use-cases.</p>
25
* @submodule querystring-parse-simple
30
var QueryString = Y.namespace("QueryString");
33
* Provides Y.QueryString.parse method to accept Query Strings and return native
37
* @submodule querystring-parse
40
* @param qs {String} Querystring to be parsed into an object.
41
* @param sep {String} (optional) Character that should join param k=v pairs together. Default: "&"
42
* @param eq {String} (optional) Character that should join keys to their values. Default: "="
46
QueryString.parse = function (qs, sep, eq) {
52
pieces = qs.split(sep),
58
tuple = pieces[i].split(eq);
59
if (tuple.length > 0) {
60
obj[QueryString.unescape(tuple.shift())] = QueryString.unescape(tuple.join(eq));
67
* Provides Y.QueryString.unescape method to be able to override default decoding
68
* method. This is important in cases where non-standard delimiters are used, if
69
* the delimiters would not normally be handled properly by the builtin
70
* (en|de)codeURIComponent functions.
71
* Default: replace "+" with " ", and then decodeURIComponent behavior.
73
* @submodule querystring-parse
76
* @param s {String} String to be decoded.
80
QueryString.unescape = function (s) {
81
return decodeURIComponent(s.replace(/\+/g, ' '));
85
}, '3.4.1' ,{requires:['yui-base']});