MDL-32843 import YUI 3.5.1
[moodle.git] / lib / yui / 3.5.1 / build / querystring-parse-simple / querystring-parse-simple-debug.js
bloba08366d0671000e81cdf37229bc6a50c64541dea
1 /*
2 YUI 3.5.1 (build 22)
3 Copyright 2012 Yahoo! Inc. All rights reserved.
4 Licensed under the BSD License.
5 http://yuilibrary.com/license/
6 */
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.
14 /*global Y */
15 /**
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>
23  *
24  * @module querystring
25  * @submodule querystring-parse-simple
26  * @for QueryString
27  * @static
28  */
30 var QueryString = Y.namespace("QueryString");
32 /**
33  * Provides Y.QueryString.parse method to accept Query Strings and return native
34  * JavaScript objects.
35  *
36  * @module querystring
37  * @submodule querystring-parse
38  * @for QueryString
39  * @method 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: "="
43  * @public
44  * @static
45  */
46 QueryString.parse = function (qs, sep, eq) {
47     sep = sep || "&";
48     eq = eq || "=";
49     for (
50         var obj = {},
51             i = 0,
52             pieces = qs.split(sep),
53             l = pieces.length,
54             tuple;
55         i < l;
56         i ++
57     ) {
58         tuple = pieces[i].split(eq);
59         if (tuple.length > 0) {
60             obj[QueryString.unescape(tuple.shift())] = QueryString.unescape(tuple.join(eq));
61         }
62     }
63     return obj;
66 /**
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.
72  * @module querystring
73  * @submodule querystring-parse
74  * @for QueryString
75  * @method unescape
76  * @param s {String} String to be decoded.
77  * @public
78  * @static
79  **/
80 QueryString.unescape = function (s) {
81     return decodeURIComponent(s.replace(/\+/g, ' '));
85 }, '3.5.1' ,{requires:['yui-base']});