querystring.js revision af0614546517d2c9fdd057d4075168aadbf03b8a
/**
* <p>The QueryString module adds support for serializing JavaScript objects into
* query strings and parsing JavaScript objects from query strings format.</p>
*
* <p>The QueryString namespace is added to your YUI instance including static methods
* Y.QueryString.parse(..) and Y.QueryString.stringify(..).</p>
*
* <p>The <code>querystring</code> module is a rollup of <code>querystring-parse</code> and
* <code>querystring-stringify</code>.</p>
*
* <p>As their names suggest, <code>querystring-parse</code> adds support for parsing
* Query String data (Y.QueryString.parse) and <code>querystring-stringify</code> for serializing
* JavaScript data into Query Strings (Y.QueryString.stringify). You may choose to
* include either of the submodules individually if you don't need the
* complementary functionality, or include the rollup for both.</p>
*
* @module querystring
* @class QueryString
* @static
*/
// Parse a key=val string.
// These can get pretty hairy
// example flow:
// parse(foo[bar][][bla]=baz)
// return parse(foo[bar][][bla],"baz")
// return parse(foo[bar][], {bla : "baz"})
// return parse(foo[bar], [{bla:"baz"}])
// return parse(foo, {bar:[{bla:"baz"}]})
// return {foo:{bar:[{bla:"baz"}]}}
pieceParser = function (eq) {
return parsePiece(
);
}
// convert numerals to numbers
}
}
}
if (!sliced) {
ret = {};
if (key) {
}
return ret;
}
// ["foo[][bar][][baz]", "foo[][bar][]", "baz"]
// array: key[]=val
if (!tail) {
}
// obj: key[subkey]=val
ret = {};
};
},
// the reducer function that merges each query piece together into one set of params
return (
// if it's uncontested, then just return the addition.
// if the existing value is an array, then concat it.
// if the existing value is not an array, and either are not objects, arrayify it.
// else merge them as objects, which is a little more complex
);
},
// Merge two *objects* together. If this is called, we've already ruled
// out the simple cases, and need to do the for-in business.
for (var i in addition) {
if (i && addition.hasOwnProperty(i)) {
}
}
return params;
};
/**
* Provides Y.QueryString.parse method to accept Query Strings and return native
* JavaScript objects.
*
* @module querystring
* @submodule querystring-parse
* @for QueryString
* @method parse
* @param qs {String} Querystring to be parsed into an object.
* @param sep {String} (optional) Character that should join param k=v pairs together. Default: "&"
* @param eq {String} (optional) Character that should join keys to their values. Default: "="
* @public
* @static
*/
// wouldn't Y.Array(qs.split()).map(pieceParser(eq)).reduce(mergeParams) be prettier?
return Y.Array.reduce(
Y.Array.map(
),
{},
);
};
/**
* Provides Y.QueryString.unescape method to be able to override default decoding
* method. This is important in cases where non-standard delimiters are used, if
* the delimiters would not normally be handled properly by the builtin
* (en|de)codeURIComponent functions.
* Default: replace "+" with " ", and then decodeURIComponent behavior.
* @module querystring
* @submodule querystring-parse
* @for QueryString
* @method unescape
* @param s {String} String to be decoded.
* @public
* @static
**/
QueryString.unescape = function (s) {
};
/**
* Provides Y.QueryString.stringify method for converting objects to Query Strings.
*
* @module querystring
* @submodule querystring-stringify
* @for QueryString
* @static
*/
stack = [],
L = Y.Lang;
/**
* Provides Y.QueryString.escape method to be able to override default encoding
* method. This is important in cases where non-standard delimiters are used, if
* the delimiters would not normally be handled properly by the builtin
* (en|de)codeURIComponent functions.
* Default: encodeURIComponent
* @module querystring
* @submodule querystring-stringify
* @for QueryString
* @static
**/
/**
* <p>Converts an arbitrary value to a Query String representation.</p>
*
* <p>Objects with cyclical references will trigger an exception.</p>
*
* @method stringify
* @public
* @param obj {Variant} any arbitrary value to convert to query string
* @param cfg {Object} (optional) Configuration object. The three
* supported configurations are:
* <ul><li>sep: When defined, the value will be used as the key-value
* separator. The default value is "&".</li>
* <li>eq: When defined, the value will be used to join the key to
* the value. The default value is "=".</li>
* <li>arrayKey: When set to true, the key of an array will have the
* '[]' notation appended to the key. The default value is false.
* </li></ul>
* @param name {String} (optional) Name of the current key, for handling children recursively.
* @static
*/
}
}
}
s = [];
for (i = 0; i < l; i++) {
}
}
// now we know it's an object.
// Check for cyclical references in nested objects
throw new Error("QueryString.stringify. Cyclical reference");
}
}
s = [];
for (i in obj) {
if (obj.hasOwnProperty(i)) {
}
}
if (!s && name) {
return name + "=";
}
return s;
};
}, '@VERSION@' );
YUI.add('querystring', function(Y){}, '@VERSION@' ,{use:['querystring-parse', 'querystring-stringify']});