Last active
November 28, 2019 08:11
-
-
Save milkamil93/60473e83c14820f9cd84b1d8ed0ea54b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function locationParams(specific, value) { | |
var result = {}, | |
loc = location.search.length ? location.search.slice(1).split('&') : null; | |
if (loc) { | |
loc.forEach(function (item) { | |
item = item.split('='); | |
if (item.length > 1 && item[0] && item[1]) result[item[0]] = item[1]; | |
}); | |
result = !value && specific && specific in result ? result[specific] : result; | |
} | |
if (typeof result === 'object' && !Object.keys(result).length || typeof result === 'string' && !result.length) { | |
result = {}; | |
} | |
if (typeof value !== 'undefined') { | |
var string = '?'; | |
result[specific] = value; | |
Object.keys(result).forEach(function (key) { | |
string += key+'='+result[key]+'&'; | |
}); | |
result = string.slice(0, -1); | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment