API Docs for: 3.13.0
Show:

File: querystring/js/querystring-stringify-simple.js

  1. /*global Y */
  2. /**
  3. * <p>Provides Y.QueryString.stringify method for converting objects to Query Strings.
  4. * This is a subset implementation of the full querystring-stringify.</p>
  5. * <p>This module provides the bare minimum functionality (encoding a hash of simple values),
  6. * without the additional support for nested data structures. Every key-value pair is
  7. * encoded by encodeURIComponent.</p>
  8. * <p>This module provides a minimalistic way for io to handle single-level objects
  9. * as transaction data.</p>
  10. *
  11. * @module querystring
  12. * @submodule querystring-stringify-simple
  13. */
  14.  
  15. var QueryString = Y.namespace("QueryString"),
  16. EUC = encodeURIComponent;
  17.  
  18.  
  19. QueryString.stringify = function (obj, c) {
  20. var qs = [],
  21. // Default behavior is false; standard key notation.
  22. s = c && c.arrayKey ? true : false,
  23. key, i, l;
  24.  
  25. for (key in obj) {
  26. if (obj.hasOwnProperty(key)) {
  27. if (Y.Lang.isArray(obj[key])) {
  28. for (i = 0, l = obj[key].length; i < l; i++) {
  29. qs.push(EUC(s ? key + '[]' : key) + '=' + EUC(obj[key][i]));
  30. }
  31. }
  32. else {
  33. qs.push(EUC(key) + '=' + EUC(obj[key]));
  34. }
  35. }
  36. }
  37.  
  38. return qs.join('&');
  39. };
  40.