[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/lib/yuilib/3.17.2/querystring-parse-simple/ -> querystring-parse-simple.js (source)

   1  /*
   2  YUI 3.17.2 (build 9c3c78e)
   3  Copyright 2014 Yahoo! Inc. All rights reserved.
   4  Licensed under the BSD License.
   5  http://yuilibrary.com/license/
   6  */
   7  
   8  YUI.add('querystring-parse-simple', function (Y, NAME) {
   9  
  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.
  14  
  15  /*global Y */
  16  /**
  17   * <p>Provides Y.QueryString.parse method for converting Query Strings to an object.
  18   * This is a simpler implementation than the full querystring-parse.</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>
  24   *
  25   * @module querystring
  26   * @submodule querystring-parse-simple
  27   */
  28  
  29  var QueryString = Y.namespace("QueryString");
  30  
  31  QueryString.parse = function (qs, sep, eq) {
  32      sep = sep || "&";
  33      eq = eq || "=";
  34      for (
  35          var obj = {},
  36              i = 0,
  37              pieces = qs.split(sep),
  38              l = pieces.length,
  39              tuple;
  40          i < l;
  41          i ++
  42      ) {
  43          tuple = pieces[i].split(eq);
  44          if (tuple.length > 0) {
  45              obj[QueryString.unescape(tuple.shift())] = QueryString.unescape(tuple.join(eq));
  46          }
  47      }
  48      return obj;
  49  };
  50  
  51  QueryString.unescape = function (s) {
  52      return decodeURIComponent(s.replace(/\+/g, ' '));
  53  };
  54  
  55  
  56  }, '3.17.2', {"requires": ["yui-base"]});


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1