SHARE
TWEET

Untitled

a guest Apr 25th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // extracted from vue.js
  2. export default function parseQuery (query) {
  3.   var res = {};
  4.  
  5.   query = query.trim().replace(/^(\?|#|&)/, '');
  6.  
  7.   if (!query) {
  8.     return res
  9.   }
  10.  
  11.   query.split('&').forEach(function (param) {
  12.     var parts = param.replace(/\+/g, ' ').split('=');
  13.     var key = decodeURIComponent(parts.shift());
  14.     var val = parts.length > 0
  15.       ? decodeURIComponent(parts.join('='))
  16.       : null;
  17.  
  18.     if (res[key] === undefined) {
  19.       res[key] = val;
  20.     } else if (Array.isArray(res[key])) {
  21.       res[key].push(val);
  22.     } else {
  23.       res[key] = [res[key], val];
  24.     }
  25.   });
  26.  
  27.   return res
  28. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top