Sha256: ff798658893a92614c3b27aa7f9adda7a03e28f65197e00e0cd553cb98beb468

Contents?: true

Size: 1.58 KB

Versions: 19

Compression:

Stored size: 1.58 KB

Contents

export class VUrls {

    paramsArrayToHash(params) {
        var results = {};
        // Map params to object/hash
        for (let param of params) {
            results[param[0]] = param[1];
        }
        return results;
    }

    buildURL(baseUrl) {
        var url = baseUrl;
        for (var i = 1; i < arguments.length; i++) {
            var args = arguments[i];
            if (Array.isArray(args)) {
                for (let arg of args) {
                    url += this.seperator(url) + this.encodeQueryParam(arg[0], arg[1]);
                }
            } else if (typeof args === 'object') {
                let q = this.serialize(arguments[i]);
                if(q && q.length>0){
                    url += this.seperator(url) + q;
                }
            } else if(args && args.length > 0){
                url += this.seperator(url) + args;
            }
        }
        return url;
    }

    seperator(url) {
        if (url.endsWith('?')) {
            return '';
        }
        return url.includes("?") ? '&' : '?';
    }

    serialize(obj, prefix) {
        var str = [],
            p;
        for (p in obj) {
            if (obj.hasOwnProperty(p)) {
                var k = prefix ? prefix + "[" + p + "]" : p,
                    v = obj[p];
                str.push((v !== null && typeof v === "object") ?
                    this.serialize(v, k) :
                    this.encodeQueryParam(k, v));
            }
        }
        return str.join("&");
    }

    encodeQueryParam(k, v) {
        return encodeURIComponent(k) + "=" + encodeURIComponent(v);
    }
}

Version data entries

19 entries across 19 versions & 2 rubygems

Version Path
coprl-3.0.0.beta.12 views/mdc/assets/js/utils/urls.js
coprl-3.0.0.beta.11 views/mdc/assets/js/utils/urls.js
coprl-3.0.0.beta.10 views/mdc/assets/js/utils/urls.js
coprl-3.0.0.beta.9 views/mdc/assets/js/utils/urls.js
coprl-3.0.0.beta.8 views/mdc/assets/js/utils/urls.js
coprl-3.0.0.beta.7 views/mdc/assets/js/utils/urls.js
coprl-3.0.0.beta.6 views/mdc/assets/js/utils/urls.js
coprl-3.0.0.beta.5 views/mdc/assets/js/utils/urls.js
voom-presenters-2.1.2 views/mdc/assets/js/utils/urls.js
coprl-3.0.0.beta.4 views/mdc/assets/js/utils/urls.js
coprl-3.0.0.beta.3 views/mdc/assets/js/utils/urls.js
coprl-3.0.0.beta.2 views/mdc/assets/js/utils/urls.js
coprl-3.0.0.beta.1 views/mdc/assets/js/utils/urls.js
voom-presenters-2.1.0 views/mdc/assets/js/utils/urls.js
voom-presenters-2.0.3 views/mdc/assets/js/utils/urls.js
voom-presenters-2.0.2 views/mdc/assets/js/utils/urls.js
voom-presenters-2.0.1 views/mdc/assets/js/utils/urls.js
voom-presenters-2.0.0 views/mdc/assets/js/utils/urls.js
voom-presenters-0.2.0 views/mdc/assets/js/utils/urls.js