Dashboard sipadu mbip
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

querystring-stringify-simple.js 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. Copyright (c) 2010, Yahoo! Inc. All rights reserved.
  3. Code licensed under the BSD License:
  4. http://developer.yahoo.com/yui/license.html
  5. version: 3.4.0
  6. build: nightly
  7. */
  8. YUI.add('querystring-stringify-simple', function(Y) {
  9. /*global Y */
  10. /**
  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>
  18. *
  19. * @module querystring
  20. * @submodule querystring-stringify-simple
  21. * @for QueryString
  22. * @static
  23. */
  24. var QueryString = Y.namespace("QueryString"),
  25. EUC = encodeURIComponent;
  26. /**
  27. * <p>Converts a simple object to a Query String representation.</p>
  28. * <p>Nested objects, Arrays, and so on, are not supported.</p>
  29. *
  30. * @method stringify
  31. * @for QueryString
  32. * @public
  33. * @submodule querystring-stringify-simple
  34. * @param obj {Object} A single-level object to convert to a querystring.
  35. * @param cfg {Object} (optional) Configuration object. In the simple
  36. * module, only the arrayKey setting is
  37. * supported. When set to true, the key of an
  38. * array will have the '[]' notation appended
  39. * to the key;.
  40. * @static
  41. */
  42. QueryString.stringify = function (obj, c) {
  43. var qs = [],
  44. // Default behavior is false; standard key notation.
  45. s = c && c.arrayKey ? true : false,
  46. key, i, l;
  47. for (key in obj) {
  48. if (obj.hasOwnProperty(key)) {
  49. if (Y.Lang.isArray(obj[key])) {
  50. for (i = 0, l = obj[key].length; i < l; i++) {
  51. qs.push(EUC(s ? key + '[]' : key) + '=' + EUC(obj[key][i]));
  52. }
  53. }
  54. else {
  55. qs.push(EUC(key) + '=' + EUC(obj[key]));
  56. }
  57. }
  58. }
  59. return qs.join('&');
  60. };
  61. }, '3.4.0' ,{requires:['yui-base']});