3
Copyright 2011 Yahoo! Inc. All rights reserved.
4
Licensed under the BSD License.
5
http://yuilibrary.com/license/
7
YUI.add('querystring-stringify-simple', function(Y) {
11
* <p>Provides Y.QueryString.stringify method for converting objects to Query Strings.
12
* This is a subset implementation of the full querystring-stringify.</p>
13
* <p>This module provides the bare minimum functionality (encoding a hash of simple values),
14
* without the additional support for nested data structures. Every key-value pair is
15
* encoded by encodeURIComponent.</p>
16
* <p>This module provides a minimalistic way for io to handle single-level objects
17
* as transaction data.</p>
20
* @submodule querystring-stringify-simple
25
var QueryString = Y.namespace("QueryString"),
26
EUC = encodeURIComponent;
29
* <p>Converts a simple object to a Query String representation.</p>
30
* <p>Nested objects, Arrays, and so on, are not supported.</p>
35
* @submodule querystring-stringify-simple
36
* @param obj {Object} A single-level object to convert to a querystring.
37
* @param cfg {Object} (optional) Configuration object. In the simple
38
* module, only the arrayKey setting is
39
* supported. When set to true, the key of an
40
* array will have the '[]' notation appended
44
QueryString.stringify = function (obj, c) {
46
// Default behavior is false; standard key notation.
47
s = c && c.arrayKey ? true : false,
51
if (obj.hasOwnProperty(key)) {
52
if (Y.Lang.isArray(obj[key])) {
53
for (i = 0, l = obj[key].length; i < l; i++) {
54
qs.push(EUC(s ? key + '[]' : key) + '=' + EUC(obj[key][i]));
58
qs.push(EUC(key) + '=' + EUC(obj[key]));
67
}, '3.4.1' ,{requires:['yui-base']});