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