Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

util.js 733B

12345678910111213141516171819202122232425262728293031
  1. export function getQueryParams() {
  2. return parseQueryString(window.location.search);
  3. }
  4. export function parseQueryString(queryString) {
  5. if (queryString.length <= 1) {
  6. return {};
  7. }
  8. const params = [];
  9. const pairs = queryString.slice(1).split('&');
  10. let pair;
  11. for (var i = 0; i < pairs.length; i++) {
  12. pair = pairs[i].split('=');
  13. params[pair[0]] = pair[1];
  14. }
  15. return params;
  16. }
  17. /**
  18. * @param {string} prefer
  19. * @param {string} base
  20. */
  21. export function mergeQueryString(prefer, base) {
  22. const params = Object.assign({}, parseQueryString(base), parseQueryString(prefer));
  23. const result = '?' + Object.keys(params).map(key => `${key}=${params[key]}`).join('&');
  24. return result === '?' ? '' : result;
  25. }