Sha256: 147e503d809a6853529c62baf80a6f91b76a34c6a75319e6784a6d7bcdb625ea
Contents?: true
Size: 1.46 KB
Versions: 14
Compression:
Stored size: 1.46 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') { url += this.seperator(url) + this.serialize(arguments[i]); } else { 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
14 entries across 14 versions & 1 rubygems