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-stringify-simple', function(Y) {
12 * <p>Provides Y.QueryString.stringify method for converting objects to Query Strings.
13 * This is a subset implementation of the full querystring-stringify.</p>
14 * <p>This module provides the bare minimum functionality (encoding a hash of simple values),
15 * without the additional support for nested data structures. Every key-value pair is
16 * encoded by encodeURIComponent.</p>
17 * <p>This module provides a minimalistic way for io to handle single-level objects
18 * as transaction data.</p>
21 * @submodule querystring-stringify-simple
26 var QueryString = Y.namespace("QueryString"),
27 EUC = encodeURIComponent;
30 * <p>Converts a simple object to a Query String representation.</p>
31 * <p>Nested objects, Arrays, and so on, are not supported.</p>
36 * @submodule querystring-stringify-simple
37 * @param obj {Object} A single-level object to convert to a querystring.
38 * @param cfg {Object} (optional) Configuration object. In the simple
39 * module, only the arrayKey setting is
40 * supported. When set to true, the key of an
41 * array will have the '[]' notation appended
45 QueryString.stringify = function (obj, c) {
47 // Default behavior is false; standard key notation.
48 s = c && c.arrayKey ? true : false,
52 if (obj.hasOwnProperty(key)) {
53 if (Y.Lang.isArray(obj[key])) {
54 for (i = 0, l = obj[key].length; i < l; i++) {
55 qs.push(EUC(s ? key + '[]' : key) + '=' + EUC(obj[key][i]));
59 qs.push(EUC(key) + '=' + EUC(obj[key]));