JSFiddle - React, Tailwind, and code Playground

by zainshaikh

JavaScript

function b(a) {
    return encodeURIComponent(a).replace(/\+/g, "%2B")
}

function decodePart(a) {
    return decodeURIComponent(a.replace(/\+/g, " "))
}

function d(a) {
    var c = [];
    for (var d in a)
    a[d] !== null && typeof a[d] != "undefined" && c.push(b(d) + "=" + b(a[d]));
    return c.sort().join("&")
}

function e(url) {
    var dictionary = {}, items, e, f, g;
    if (url) {
        items = url.split("&");
        for (g = 0; pair = items[g]; g++)
        e = pair.split("="), (dictionary[decodePart(e.shift())] = decodePart(e.join("=")))
    }
    return dictionary
}

function prepare() {
    var url = window.location.search.substr(1);
    return e(url);
}

function replace(url, param, value) {
    if (url.indexOf('#') > -1) {
        url = url.substr(0, url.indexOf('#'));
    }
    if (url.lastIndexOf('?') <= 0) {
        url = url + "?";
    }
    var re = new RegExp("([?|&])" + param + "=.*?(&|$)", "i");
    if (url.match(re)) {
        return url.replace(re, '$1' + param + "=" + value + '$2');
    } else {
        return url.substring(url.length - 1) == '?' ? url + param + "=" + value : url + '&' + param + "=" + value;
    }
}



var d = e('https://www.google.com/search?hl=en&as_q=Investment&as_epq=&as_oq=banking&as_eq=loan&as_nlo=&as_nhi=&lr=&cr=&as_qdr=all&as_sitesearch=&as_occt=any&safe=images&tbs=&as_filetype=&as_rights=');
console.log(d);