UNPKG

@beenotung/tslib

Version:
36 lines 1.11 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseURLSearchParams = void 0; function parseURLSearchParams(search = location.search, options) { if (search.startsWith('http://') || search.startsWith('https://')) { search = search.replace(/.*\?/, ''); } if (search.startsWith('?')) { search = search.substring(1); } if (search.includes('%')) { search = decodeURIComponent(search); } const params = {}; search.split('&').forEach(s => { let [key, value] = s.split('='); if ((options === null || options === void 0 ? void 0 : options.parse) === 'json') { try { key = JSON.parse(key); } catch (e) { // the key is not json } try { value = JSON.parse(value); } catch (e) { // the value is not json } } params[key] = value; }); return params; } exports.parseURLSearchParams = parseURLSearchParams; //# sourceMappingURL=url.js.map