Skip to content

Instantly share code, notes, and snippets.

@watilde
Last active December 18, 2015 04:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save watilde/5726533 to your computer and use it in GitHub Desktop.
Save watilde/5726533 to your computer and use it in GitHub Desktop.
/**
* like PHP's $_GET
* @type {Function} $_GET
* @param {String} params
* @return {Object} hash
*/
var $_GET = (function $_GET(params) {
'use strict';
// Exception
if (!params) return null;
/** @type {Object} */
var hash = {};
/** @type {Array} */
var queries = params.substring(1).split("&");
/** @type {Array} */
var query = queries.map(function(q) {return q.split("="); });
/** @type {Number} */
var i = queries.length;
// Decode & Push value of window.location.search to hash
while (i--) hash[query[i][0]] = decodeURIComponent(query[i][1]);
return hash;
}(window.location.search || null));
// $_GET['key'] => value ٩(๑❛ᴗ❛๑)۶
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment