UNPKG

@beenotung/tslib

Version:
32 lines (31 loc) 932 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.urlEncode = urlEncode; const lang_1 = require("./lang"); function urlEncode(o) { function escape(x) { const type = typeof x; if (type === 'number') { return x + ''; } if (type === 'string') { let res = ''; (0, lang_1.forI)(i => { const c = x[i]; if (('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z') || ('0' <= c && c <= '9')) { res += c; } else { res += '%' + c.charCodeAt(0).toString(16); } }, x.length); return res; } return escape(JSON.stringify(x)); } return (0, lang_1.objToArray)(o) .map(vk => escape(vk[1]) + '=' + escape(vk[0])) .join('&'); }