UNPKG

nested-query-params

Version:
32 lines 899 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.splitQuery = void 0; function splitQuery(search) { // remove first '?' if (search.indexOf("?") === 0) { search = search.slice(1); } const pairs = search.split("&"); return pairs.reduce((acc, value) => { const index = value.indexOf("="); if (index > -1) { return [ ...acc, [ decode(value.slice(0, index)), decode(value.slice(index + 1)), ], ]; } return [...acc, [decode(value), ""]]; }, []); } exports.splitQuery = splitQuery; function decode(str) { return str .replace(/[ +]/g, "%20") .replace(/(%[a-f0-9]{2})+/gi, function (match) { return decodeURIComponent(match); }); } //# sourceMappingURL=util.js.map